[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");
|
res.status(400).send("Username and password for nextcloud are required");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await nextcloud.migrate(params.username, params.password);
|
await nextcloud.migrate(params.username, params.password, params.dir);
|
||||||
res.status(200).send("Sync DONE ✅");
|
res.status(200).send("Sync DONE ✅");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
|||||||
@@ -42,8 +42,9 @@ export class NextcloudMigration {
|
|||||||
this.driveClient = new TwakeDriveClient(this.config.drive);
|
this.driveClient = new TwakeDriveClient(this.config.drive);
|
||||||
}
|
}
|
||||||
|
|
||||||
async migrate(username: string, password: string) {
|
async migrate(username: string, password: string, dir?: string) {
|
||||||
const dir = this.createTmpDir(username);
|
const dirTmp = dir ? dir : this.createTmpDir(username);
|
||||||
|
if (dir) console.log(`Using dir: ${dir}`);
|
||||||
// const dir = "/tmp/to_upload"
|
// const dir = "/tmp/to_upload"
|
||||||
try {
|
try {
|
||||||
const user = await this.getLDAPUser(username);
|
const user = await this.getLDAPUser(username);
|
||||||
@@ -51,14 +52,14 @@ export class NextcloudMigration {
|
|||||||
const driveUser = await this.driveClient.createUser(user);
|
const driveUser = await this.driveClient.createUser(user);
|
||||||
console.log(`Drive user ${driveUser.id} created`);
|
console.log(`Drive user ${driveUser.id} created`);
|
||||||
//download all files from nextcloud to tmp dir
|
//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
|
//upload files to the Twake Drive
|
||||||
await this.upload(driveUser, dir);
|
await this.upload(driveUser, dirTmp);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error downloading files from next cloud', e);
|
console.error('Error downloading files from next cloud', e);
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
this.deleteDir(dir);
|
if(!dir) this.deleteDir(dirTmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user