diff --git a/tdrive/backend/utils/nextcloud-migration/src/express_server.ts b/tdrive/backend/utils/nextcloud-migration/src/express_server.ts index 4c144cd2..51bda38f 100644 --- a/tdrive/backend/utils/nextcloud-migration/src/express_server.ts +++ b/tdrive/backend/utils/nextcloud-migration/src/express_server.ts @@ -60,7 +60,7 @@ app.post("/", async (req: Request, res: Response) => { res.status(400).send("Username and password for nextcloud are required"); } try { - await nextcloud.migrate(params.username, params.password); + await nextcloud.migrate(params.username, params.password, params.dir); res.status(200).send("Sync DONE ✅"); } catch (e) { console.error(e) diff --git a/tdrive/backend/utils/nextcloud-migration/src/nextcloud_migration.ts b/tdrive/backend/utils/nextcloud-migration/src/nextcloud_migration.ts index f877ad33..9fef43d9 100644 --- a/tdrive/backend/utils/nextcloud-migration/src/nextcloud_migration.ts +++ b/tdrive/backend/utils/nextcloud-migration/src/nextcloud_migration.ts @@ -42,8 +42,9 @@ export class NextcloudMigration { this.driveClient = new TwakeDriveClient(this.config.drive); } - async migrate(username: string, password: string) { - const dir = this.createTmpDir(username); + async migrate(username: string, password: string, dir?: string) { + const dirTmp = dir ? dir : this.createTmpDir(username); + if (dir) console.log(`Using dir: ${dir}`); // const dir = "/tmp/to_upload" try { const user = await this.getLDAPUser(username); @@ -51,14 +52,14 @@ export class NextcloudMigration { const driveUser = await this.driveClient.createUser(user); console.log(`Drive user ${driveUser.id} created`); //download all files from nextcloud to tmp dir - await this.download(username, password, dir); + if(!dir) await this.download(username, password, dirTmp); //upload files to the Twake Drive - await this.upload(driveUser, dir); + await this.upload(driveUser, dirTmp); } catch (e) { console.error('Error downloading files from next cloud', e); throw e; } finally { - this.deleteDir(dir); + if(!dir) this.deleteDir(dirTmp); } }