mirror of
https://github.com/Ellpeck/WoodpeckerPlugins.git
synced 2024-11-24 03:18:33 +01:00
also add tags to created directories
This commit is contained in:
parent
262ef59cc1
commit
71ea8ddf31
1 changed files with 57 additions and 47 deletions
|
@ -92,12 +92,20 @@ async function upload() {
|
|||
// 405 means the directory already exists
|
||||
validateStatus: s => s == 201 || s == 405
|
||||
});
|
||||
if (response.status != 405 && !quiet)
|
||||
console.log(`Created directory ${currDir}`);
|
||||
if (response.status != 405) {
|
||||
if (!quiet)
|
||||
console.log(`Created directory ${dir}`);
|
||||
|
||||
// add tags to directory too
|
||||
if (tagIds)
|
||||
await addTags(basePath, tagIds, dir, currDir);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.log(`Failed to create directory ${currDir} (${error})`);
|
||||
console.log(`Failed to create directory ${dir} (${error})`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// use lib to upload file
|
||||
|
@ -112,12 +120,18 @@ async function upload() {
|
|||
});
|
||||
|
||||
// add tags
|
||||
if (tagIds.size) {
|
||||
if (tagIds.size)
|
||||
await addTags(basePath, tagIds, file, dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function addTags(basePath, tagIds, file, location) {
|
||||
try {
|
||||
// get file id: https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/basic.html#requesting-properties
|
||||
let response = await axios.request({
|
||||
method: "propfind",
|
||||
url: `${basePath}/files/${userEnv}/${dest}`,
|
||||
url: `${basePath}/files/${userEnv}/${location}`,
|
||||
auth: {
|
||||
username: userEnv,
|
||||
password: tokenEnv
|
||||
|
@ -132,7 +146,7 @@ async function upload() {
|
|||
var data = JSON.parse(xml.toJson(response.data));
|
||||
let fileId = data["d:multistatus"]["d:response"]["d:propstat"]["d:prop"]["oc:fileid"];
|
||||
if (!quiet)
|
||||
console.log(`File id of file ${file} is ${fileId}`);
|
||||
console.log(`File id of ${file} is ${fileId}`);
|
||||
|
||||
// add tags: https://doc.owncloud.com/server/next/developer_manual/webdav_api/tags.html#assign-a-tag-to-a-file
|
||||
for (let [tag, tagId] of tagIds.entries()) {
|
||||
|
@ -147,15 +161,11 @@ async function upload() {
|
|||
validateStatus: s => s == 201 || s == 409
|
||||
});
|
||||
if (!quiet)
|
||||
console.log(`Added tag ${tag} to file ${file}`);
|
||||
console.log(`Added tag ${tag} to ${file}`);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.log(`Failed to assign tags ${tags} to file ${file} (${error})`);
|
||||
console.log(`Failed to assign tags ${tags} to ${file} (${error})`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue