From ed93bf95fb648a7dc8a10e6994989ecc55a08ec0 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 3 Jul 2023 13:40:43 +0200 Subject: [PATCH] don't print directory creation if it already exists --- nextcloud-upload/run.js | 8 ++++---- nextcloud-upload/test.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nextcloud-upload/run.js b/nextcloud-upload/run.js index 6975343..5d0bead 100644 --- a/nextcloud-upload/run.js +++ b/nextcloud-upload/run.js @@ -75,8 +75,6 @@ async function upload() { console.log(`No files found for pattern ${pattern}`); for (let file of files) { let dest = `${destEnv}/${file}`; - if (!quiet) - console.log(`Uploading ${file} to ${dest}`); // we have to explicitly create any directories that don't exist yet // (https://github.com/shiftpi/nextcloud-chunk-file-upload/issues/22) @@ -84,7 +82,7 @@ async function upload() { for (let dir of dest.split("/").slice(0, -1)) { currDir += `${dir}/`; try { - await axios.request({ + let response = await axios.request({ method: 'mkcol', url: `${basePath}/files/${userEnv}/${currDir}`, auth: { @@ -94,7 +92,7 @@ async function upload() { // 405 means the directory already exists validateStatus: s => s == 201 || s == 405 }); - if (!quiet) + if (response.status != 405 && !quiet) console.log(`Created directory ${currDir}`); } catch (error) { console.log(`Failed to create directory ${currDir} (${error})`); @@ -103,6 +101,8 @@ async function upload() { } // use lib to upload file + if (!quiet) + console.log(`Uploading ${file} to ${dest}`); await upload.uploadFile(`${baseDir}/${file}`, dest, parseInt(chunkSizeEnv)).then(e => { if (!quiet) console.log(`Uploaded ${file} to ${dest}`); diff --git a/nextcloud-upload/test.sh b/nextcloud-upload/test.sh index 5e7ce68..234628a 100644 --- a/nextcloud-upload/test.sh +++ b/nextcloud-upload/test.sh @@ -2,7 +2,7 @@ export PLUGIN_SERVER=https://cloud.ellpeck.de export PLUGIN_USER=EllBot export PLUGIN_FILES=Dockerfile export PLUGIN_DEST=Test/Testing -export PLUGIN_TAGS=testing,another +export PLUGIN_TAGS="Autoremove 1D" npm install node run.js