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
|
// 405 means the directory already exists
|
||||||
validateStatus: s => s == 201 || s == 405
|
validateStatus: s => s == 201 || s == 405
|
||||||
});
|
});
|
||||||
if (response.status != 405 && !quiet)
|
if (response.status != 405) {
|
||||||
console.log(`Created directory ${currDir}`);
|
if (!quiet)
|
||||||
|
console.log(`Created directory ${dir}`);
|
||||||
|
|
||||||
|
// add tags to directory too
|
||||||
|
if (tagIds)
|
||||||
|
await addTags(basePath, tagIds, dir, currDir);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`Failed to create directory ${currDir} (${error})`);
|
console.log(`Failed to create directory ${dir} (${error})`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// use lib to upload file
|
// use lib to upload file
|
||||||
|
@ -112,12 +120,18 @@ async function upload() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// add tags
|
// add tags
|
||||||
if (tagIds.size) {
|
if (tagIds.size)
|
||||||
|
await addTags(basePath, tagIds, file, dest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addTags(basePath, tagIds, file, location) {
|
||||||
try {
|
try {
|
||||||
// get file id: https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/basic.html#requesting-properties
|
// get file id: https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/basic.html#requesting-properties
|
||||||
let response = await axios.request({
|
let response = await axios.request({
|
||||||
method: "propfind",
|
method: "propfind",
|
||||||
url: `${basePath}/files/${userEnv}/${dest}`,
|
url: `${basePath}/files/${userEnv}/${location}`,
|
||||||
auth: {
|
auth: {
|
||||||
username: userEnv,
|
username: userEnv,
|
||||||
password: tokenEnv
|
password: tokenEnv
|
||||||
|
@ -132,7 +146,7 @@ async function upload() {
|
||||||
var data = JSON.parse(xml.toJson(response.data));
|
var data = JSON.parse(xml.toJson(response.data));
|
||||||
let fileId = data["d:multistatus"]["d:response"]["d:propstat"]["d:prop"]["oc:fileid"];
|
let fileId = data["d:multistatus"]["d:response"]["d:propstat"]["d:prop"]["oc:fileid"];
|
||||||
if (!quiet)
|
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
|
// 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()) {
|
for (let [tag, tagId] of tagIds.entries()) {
|
||||||
|
@ -147,15 +161,11 @@ async function upload() {
|
||||||
validateStatus: s => s == 201 || s == 409
|
validateStatus: s => s == 201 || s == 409
|
||||||
});
|
});
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
console.log(`Added tag ${tag} to file ${file}`);
|
console.log(`Added tag ${tag} to ${file}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} 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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue