aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/local-actor.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-03 10:10:26 +0200
committerChocobozzz <me@florianbigard.com>2022-08-03 10:10:26 +0200
commit0b6f531653a7a24f82ad65564479a70a9326301a (patch)
treef65d9c80e0e8ced86a8a9f7b00952bb04413a5b7 /server/lib/local-actor.ts
parent35a0a924830d84f9ec28c129ec85cb1f45011fb8 (diff)
downloadPeerTube-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.ts18
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 @@
1import { remove } from 'fs-extra' 1import { remove } from 'fs-extra'
2import LRUCache from 'lru-cache' 2import LRUCache from 'lru-cache'
3import { join } from 'path' 3import { join } from 'path'
4import { Transaction } from 'sequelize/types'
4import { ActorModel } from '@server/models/actor/actor' 5import { ActorModel } from '@server/models/actor/actor'
5import { getLowercaseExtension } from '@shared/core-utils' 6import { getLowercaseExtension } from '@shared/core-utils'
6import { buildUUID } from '@shared/extra-utils' 7import { buildUUID } from '@shared/extra-utils'
@@ -87,6 +88,22 @@ async function deleteLocalActorImageFile (accountOrChannel: MAccountDefault | MC
87 88
88// --------------------------------------------------------------------------- 89// ---------------------------------------------------------------------------
89 90
91async 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
90function downloadActorImageFromWorker (options: { 107function 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.
109export { 126export {
110 actorImagePathUnsafeCache, 127 actorImagePathUnsafeCache,
111 updateLocalActorImageFiles, 128 updateLocalActorImageFiles,
129 findAvailableLocalActorName,
112 downloadActorImageFromWorker, 130 downloadActorImageFromWorker,
113 deleteLocalActorImageFile, 131 deleteLocalActorImageFile,
114 downloadImageFromWorker, 132 downloadImageFromWorker,