Skip to content

Commit

Permalink
[Nextcloud-Migration]: add "dir" param (#427)
Browse files Browse the repository at this point in the history
This permit one to use an existing directory instead of downloading from Nextcloud
  • Loading branch information
guimard authored Mar 11, 2024
1 parent bd2d5c2 commit 423e7f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,24 @@ 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);
//create user if needed Twake Drive
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);
}
}

Expand Down

0 comments on commit 423e7f2

Please sign in to comment.