don't print directory creation if it already exists

This commit is contained in:
Ell 2023-07-03 13:40:43 +02:00
parent 94ec9ef22a
commit ed93bf95fb
2 changed files with 5 additions and 5 deletions

View file

@ -75,8 +75,6 @@ async function upload() {
console.log(`No files found for pattern ${pattern}`); console.log(`No files found for pattern ${pattern}`);
for (let file of files) { for (let file of files) {
let dest = `${destEnv}/${file}`; let dest = `${destEnv}/${file}`;
if (!quiet)
console.log(`Uploading ${file} to ${dest}`);
// we have to explicitly create any directories that don't exist yet // we have to explicitly create any directories that don't exist yet
// (https://github.com/shiftpi/nextcloud-chunk-file-upload/issues/22) // (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)) { for (let dir of dest.split("/").slice(0, -1)) {
currDir += `${dir}/`; currDir += `${dir}/`;
try { try {
await axios.request({ let response = await axios.request({
method: 'mkcol', method: 'mkcol',
url: `${basePath}/files/${userEnv}/${currDir}`, url: `${basePath}/files/${userEnv}/${currDir}`,
auth: { auth: {
@ -94,7 +92,7 @@ async function upload() {
// 405 means the directory already exists // 405 means the directory already exists
validateStatus: s => s == 201 || s == 405 validateStatus: s => s == 201 || s == 405
}); });
if (!quiet) if (response.status != 405 && !quiet)
console.log(`Created directory ${currDir}`); console.log(`Created directory ${currDir}`);
} catch (error) { } catch (error) {
console.log(`Failed to create directory ${currDir} (${error})`); console.log(`Failed to create directory ${currDir} (${error})`);
@ -103,6 +101,8 @@ async function upload() {
} }
// use lib to upload file // use lib to upload file
if (!quiet)
console.log(`Uploading ${file} to ${dest}`);
await upload.uploadFile(`${baseDir}/${file}`, dest, parseInt(chunkSizeEnv)).then(e => { await upload.uploadFile(`${baseDir}/${file}`, dest, parseInt(chunkSizeEnv)).then(e => {
if (!quiet) if (!quiet)
console.log(`Uploaded ${file} to ${dest}`); console.log(`Uploaded ${file} to ${dest}`);

View file

@ -2,7 +2,7 @@ export PLUGIN_SERVER=https://cloud.ellpeck.de
export PLUGIN_USER=EllBot export PLUGIN_USER=EllBot
export PLUGIN_FILES=Dockerfile export PLUGIN_FILES=Dockerfile
export PLUGIN_DEST=Test/Testing export PLUGIN_DEST=Test/Testing
export PLUGIN_TAGS=testing,another export PLUGIN_TAGS="Autoremove 1D"
npm install npm install
node run.js node run.js