diff options
author | Chocobozzz <me@florianbigard.com> | 2022-08-03 10:10:26 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-03 10:10:26 +0200 |
commit | 0b6f531653a7a24f82ad65564479a70a9326301a (patch) | |
tree | f65d9c80e0e8ced86a8a9f7b00952bb04413a5b7 /server/lib/local-actor.ts | |
parent | 35a0a924830d84f9ec28c129ec85cb1f45011fb8 (diff) | |
download | PeerTube-0b6f531653a7a24f82ad65564479a70a9326301a.tar.gz PeerTube-0b6f531653a7a24f82ad65564479a70a9326301a.tar.zst PeerTube-0b6f531653a7a24f82ad65564479a70a9326301a.zip |
Suffix external auth username on conflict
Diffstat (limited to 'server/lib/local-actor.ts')
-rw-r--r-- | server/lib/local-actor.ts | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/server/lib/local-actor.ts b/server/lib/local-actor.ts index 1d9be76e2..8c10ed700 100644 --- a/server/lib/local-actor.ts +++ b/server/lib/local-actor.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { remove } from 'fs-extra' | 1 | import { remove } from 'fs-extra' |
2 | import LRUCache from 'lru-cache' | 2 | import LRUCache from 'lru-cache' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { Transaction } from 'sequelize/types' | ||
4 | import { ActorModel } from '@server/models/actor/actor' | 5 | import { ActorModel } from '@server/models/actor/actor' |
5 | import { getLowercaseExtension } from '@shared/core-utils' | 6 | import { getLowercaseExtension } from '@shared/core-utils' |
6 | import { buildUUID } from '@shared/extra-utils' | 7 | import { buildUUID } from '@shared/extra-utils' |
@@ -87,6 +88,22 @@ async function deleteLocalActorImageFile (accountOrChannel: MAccountDefault | MC | |||
87 | 88 | ||
88 | // --------------------------------------------------------------------------- | 89 | // --------------------------------------------------------------------------- |
89 | 90 | ||
91 | async function findAvailableLocalActorName (baseActorName: string, transaction?: Transaction) { | ||
92 | let actor = await ActorModel.loadLocalByName(baseActorName, transaction) | ||
93 | if (!actor) return baseActorName | ||
94 | |||
95 | for (let i = 1; i < 30; i++) { | ||
96 | const name = `${baseActorName}-${i}` | ||
97 | |||
98 | actor = await ActorModel.loadLocalByName(name, transaction) | ||
99 | if (!actor) return name | ||
100 | } | ||
101 | |||
102 | throw new Error('Cannot find available actor local name (too much iterations).') | ||
103 | } | ||
104 | |||
105 | // --------------------------------------------------------------------------- | ||
106 | |||
90 | function downloadActorImageFromWorker (options: { | 107 | function downloadActorImageFromWorker (options: { |
91 | fileUrl: string | 108 | fileUrl: string |
92 | filename: string | 109 | filename: string |
@@ -109,6 +126,7 @@ const actorImagePathUnsafeCache = new LRUCache<string, string>({ max: LRU_CACHE. | |||
109 | export { | 126 | export { |
110 | actorImagePathUnsafeCache, | 127 | actorImagePathUnsafeCache, |
111 | updateLocalActorImageFiles, | 128 | updateLocalActorImageFiles, |
129 | findAvailableLocalActorName, | ||
112 | downloadActorImageFromWorker, | 130 | downloadActorImageFromWorker, |
113 | deleteLocalActorImageFile, | 131 | deleteLocalActorImageFile, |
114 | downloadImageFromWorker, | 132 | downloadImageFromWorker, |