[Nextcloud-Migration]: add "dir" param (#427)
This permit one to use an existing directory instead of downloading from Nextcloud
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user