From 0aa7178d18803e175e9f7fa245f7b9a421410547 Mon Sep 17 00:00:00 2001 From: AlexisG Date: Sat, 2 Mar 2024 14:41:56 +0100 Subject: [PATCH] feat: Migrate generateFiles command with new client BREACKING CHANGE: The `path` argument is replaced by `dirId`, and goes to second position. Example to generate 2 files at the root of your Drive: Before ``` ACH generateFiles ``` Now ``` ACH generateFiles ``` --- cli.js | 10 +++++----- libs/ACH.js | 2 +- libs/createFiles.js | 24 +++++++++++++++++------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/cli.js b/cli.js index 16d409a..913aa44 100755 --- a/cli.js +++ b/cli.js @@ -83,12 +83,12 @@ const handleImportDirCommand = async args => { } const handleGenerateFilesCommand = async args => { - const { path = '/', filesCount = 10, url, token } = args + const { dirId = 'io.cozy.files.root-dir', filesCount = 10, url, token } = args const ach = new ACH(token || autotoken(url, ['io.cozy.files']), url, [ 'io.cozy.files' ]) await ach.connect() - await ach.createFiles(path, parseInt(filesCount)) + await ach.createFiles(parseInt(filesCount), dirId) } const handleDropCommand = async args => { @@ -321,14 +321,14 @@ program ) program - .command('generateFiles [path] [filesCount]') + .command('generateFiles [filesCount] [dirId]') .description('Generates a given number of small files.') .action( - handleErrors(async function(path, filesCount) { + handleErrors(async function(filesCount, dirId) { await handleGenerateFilesCommand({ url: program.url, token: program.token, - path, + dirId, filesCount }) }) diff --git a/libs/ACH.js b/libs/ACH.js index bf5382c..1fed1b6 100644 --- a/libs/ACH.js +++ b/libs/ACH.js @@ -121,7 +121,7 @@ const methods = { }, createFiles: { method: createFiles, - oldClient: true + oldClient: false }, export: { method: exportDocs, diff --git a/libs/createFiles.js b/libs/createFiles.js index 764f7d1..c82f224 100644 --- a/libs/createFiles.js +++ b/libs/createFiles.js @@ -1,16 +1,26 @@ const ProgressBar = require('progress') const faker = require('faker') +const { + uploadFileWithConflictStrategy +} = require('cozy-client/dist/models/file') -module.exports = async (client, path, filesCount) => { - const { forceCreateByPath } = client.files - +module.exports = async ( + client, + filesCount, + dirId = 'io.cozy.files.root-dir' +) => { const bar = new ProgressBar(':bar', { total: filesCount }) for (let i = 0; i < filesCount; i++) { - const name = faker.datatype.uuid() - await forceCreateByPath(`${path}/${name}.txt`, name, { - name: `${name}.txt`, - contentType: 'text/plain' + const name = faker.lorem.word() + const content = faker.lorem.paragraph() + const buffer = new Buffer.from(content, 'utf-8') + + await uploadFileWithConflictStrategy(client, buffer.toString(), { + name, + dirId, + contentType: 'text/plain', + conflictStrategy: 'rename' }) bar.tick() }