From 4f97b56c1179b878272a6c5736ed791bd8ef614b Mon Sep 17 00:00:00 2001 From: Khaled FERJANI Date: Wed, 15 Oct 2025 13:48:37 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=8E=A8=20chore:=20sanitize=20slugs=20?= =?UTF-8?q?to=20handle=20not=20compatible=20usernames?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/cli/cmds/migration_cmds/migrate-files.ts | 5 +++-- .../src/cli/cmds/migration_cmds/migrate-users.ts | 5 ++++- .../node/src/cli/cmds/migration_cmds/utils/index.ts | 12 ++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-files.ts b/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-files.ts index ab36a9c8..c29b46ce 100644 --- a/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-files.ts +++ b/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-files.ts @@ -12,6 +12,7 @@ import { DEFAULT_COMPANY, getDriveToken, nodeReadableToWebReadable, + sanitizeSlug, } from "./utils"; const purgeIndexesCommand: yargs.CommandModule = { @@ -99,7 +100,7 @@ const purgeIndexesCommand: yargs.CommandModule = { userFilesObjects.push(fileObject); if (!dryRun) { - const cozyUrl = `${userId}.${COZY_DOMAIN}`; + const cozyUrl = `${sanitizeSlug(userId)}.${COZY_DOMAIN}`; const userToken = await getDriveToken(cozyUrl); const client = new CozyClient({ uri: `https://${cozyUrl}`, @@ -161,7 +162,7 @@ const purgeIndexesCommand: yargs.CommandModule = { console.log(`\n✅ File migrated successfully: ${fileObject.name}`); } else { console.log( - `[DRY-RUN] Would create Cozy instance for user ${user.email_canonical}`, + `[DRY-RUN] Would migrate ${user.email_canonical} file: ${fileObject.name}`, ); } } catch (error) { diff --git a/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-users.ts b/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-users.ts index 14fb5aee..e1267ced 100644 --- a/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-users.ts +++ b/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-users.ts @@ -78,7 +78,10 @@ const migrateUsersCommand: yargs.CommandModule = { // Even if error, continue to next user } } else { - console.log(`[DRY-RUN] Would create Cozy instance for user ${user.email_canonical}`); + console.log( + `[DRY-RUN] Would create Cozy instance for user ${user.email_canonical} with the following params`, + userObject + ); } } }); diff --git a/tdrive/backend/node/src/cli/cmds/migration_cmds/utils/index.ts b/tdrive/backend/node/src/cli/cmds/migration_cmds/utils/index.ts index c4e075ae..faed8b62 100644 --- a/tdrive/backend/node/src/cli/cmds/migration_cmds/utils/index.ts +++ b/tdrive/backend/node/src/cli/cmds/migration_cmds/utils/index.ts @@ -49,7 +49,7 @@ export async function createCozyInstance(user: { `${COZY_MANAGER_URL}/instances`, { offer: COZY_OFFER, - slug: user.id, + slug: sanitizeSlug(user.id), domain: COZY_DOMAIN, email: user.email, public_name: user.name, @@ -149,7 +149,7 @@ export async function uploadFile( userToken: string, fileReadable: ReadableStream, ) { - const baseUrl = `https://${userId}.${COZY_DOMAIN}/files/${fileDirPath}`; + const baseUrl = `https://${sanitizeSlug(userId)}.${COZY_DOMAIN}/files/${fileDirPath}`; const params = { Name: fileName, Type: "file", @@ -169,3 +169,11 @@ export async function uploadFile( } as RequestInit); return resp; } + +/** + * Remove dots from userId to match the slug format + * + * @param {string} userId - the username to clean + * @returns {string} - the sanitized slug + */ +export const sanitizeSlug = (userId: string): string => userId.replaceAll(/\./g, ""); From e60af9caf3d76c343813d36c7e58667acd2123d8 Mon Sep 17 00:00:00 2001 From: Khaled Ferjani Date: Wed, 15 Oct 2025 13:51:08 +0200 Subject: [PATCH 2/3] Update tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-files.ts Co-authored-by: Quentin Valmori --- .../backend/node/src/cli/cmds/migration_cmds/migrate-files.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-files.ts b/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-files.ts index c29b46ce..38e9acf2 100644 --- a/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-files.ts +++ b/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-files.ts @@ -162,7 +162,7 @@ const purgeIndexesCommand: yargs.CommandModule = { console.log(`\n✅ File migrated successfully: ${fileObject.name}`); } else { console.log( - `[DRY-RUN] Would migrate ${user.email_canonical} file: ${fileObject.name}`, + `[DRY-RUN] Would migrate ${user.email_canonical} for slug ${sanitizeSlug(userId)} file: ${fileObject.name}`, ); } } catch (error) { From 680870e4160615bdfb1c3c1ca7e48ab1f1bb9bde Mon Sep 17 00:00:00 2001 From: Khaled Ferjani Date: Wed, 15 Oct 2025 13:52:25 +0200 Subject: [PATCH 3/3] Apply suggestion from @Crash-- Co-authored-by: Quentin Valmori --- .../backend/node/src/cli/cmds/migration_cmds/migrate-users.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-users.ts b/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-users.ts index e1267ced..1eb456bf 100644 --- a/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-users.ts +++ b/tdrive/backend/node/src/cli/cmds/migration_cmds/migrate-users.ts @@ -79,7 +79,7 @@ const migrateUsersCommand: yargs.CommandModule = { } } else { console.log( - `[DRY-RUN] Would create Cozy instance for user ${user.email_canonical} with the following params`, + `[DRY-RUN] Would create Cozy instance for user ${user.email_canonical} and slug ${sanitizeSlug(userId)} with the following params`, userObject ); }