mirror of
https://github.com/Ellpeck/WoodpeckerPlugins.git
synced 2024-11-27 12:38:34 +01:00
Compare commits
No commits in common. "b190def36fab6bf62e3e69382f8da9783b44a121" and "cce6a44078f45c16b873462b5abecf5282b287af" have entirely different histories.
b190def36f
...
cce6a44078
4 changed files with 6 additions and 53 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1 @@
|
||||||
node_modules
|
node_modules
|
||||||
.idea
|
|
||||||
|
|
|
@ -25,11 +25,7 @@ steps:
|
||||||
- "**/*.md"
|
- "**/*.md"
|
||||||
dest: Uploads/CoolMarkdownFiles # the destination directory
|
dest: Uploads/CoolMarkdownFiles # the destination directory
|
||||||
|
|
||||||
# optional retention settings, useful if old builds should be deleted automatically
|
# optional settings
|
||||||
retentionamount: 7 # amount of children that retentionbase is allowed to have before oldest ones are deleted on upload
|
|
||||||
retentionbase: Uploads # directory that the retentionamount applies to
|
|
||||||
|
|
||||||
# misc optional settings
|
|
||||||
basedir: "." # local base directory for files, defaults to .
|
basedir: "." # local base directory for files, defaults to .
|
||||||
chunksize: # chunk size in bytes, defaults to 10485760, or 10 MiB
|
chunksize: # chunk size in bytes, defaults to 10485760, or 10 MiB
|
||||||
quiet: false # whether to reduce output
|
quiet: false # whether to reduce output
|
||||||
|
|
|
@ -25,53 +25,12 @@ const chunkSizeEnv = process.env.PLUGIN_CHUNKSIZE || 10 * 1024 * 1024;
|
||||||
const quiet = process.env.PLUGIN_QUIET || false;
|
const quiet = process.env.PLUGIN_QUIET || false;
|
||||||
const tags = process.env.PLUGIN_TAGS || "";
|
const tags = process.env.PLUGIN_TAGS || "";
|
||||||
const flatten = process.env.PLUGIN_FLATTEN || false;
|
const flatten = process.env.PLUGIN_FLATTEN || false;
|
||||||
const retentionBase = process.env.PLUGIN_RETENTIONBASE || "";
|
|
||||||
const retentionAmount = process.env.PLUGIN_RETENTIONAMOUNT || 0;
|
|
||||||
|
|
||||||
upload();
|
upload();
|
||||||
|
|
||||||
async function upload() {
|
async function upload() {
|
||||||
let basePath = `${serverEnv}/remote.php/dav`;
|
let basePath = `${serverEnv}/remote.php/dav`;
|
||||||
|
|
||||||
// delete files or directories that exceed the retention amount
|
|
||||||
if (retentionBase && retentionAmount) {
|
|
||||||
try {
|
|
||||||
let retentionPath = `${basePath}/files/${userEnv}/${retentionBase}`;
|
|
||||||
let response = await axios.request({
|
|
||||||
method: "propfind",
|
|
||||||
url: retentionPath,
|
|
||||||
auth: {
|
|
||||||
username: userEnv,
|
|
||||||
password: tokenEnv
|
|
||||||
},
|
|
||||||
// 404 means the directory doesn't exist, which is fine
|
|
||||||
validateStatus: s => s == 207 || s == 404
|
|
||||||
});
|
|
||||||
if (response.status != 404) {
|
|
||||||
let data = JSON.parse(xml.toJson(response.data));
|
|
||||||
let dirs = data["d:multistatus"]["d:response"].slice(1);
|
|
||||||
// sort directories by last modified
|
|
||||||
dirs.sort((a, b) => new Date(a["d:propstat"]["d:prop"]["d:getlastmodified"]) - new Date(b["d:propstat"]["d:prop"]["d:getlastmodified"]));
|
|
||||||
while (dirs.length > parseInt(retentionAmount)) {
|
|
||||||
let dir = `${serverEnv}${dirs[0]["d:href"]}`;
|
|
||||||
await axios.request({
|
|
||||||
method: "delete",
|
|
||||||
url: dir,
|
|
||||||
auth: {
|
|
||||||
username: userEnv,
|
|
||||||
password: tokenEnv
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log(`Deleted directory ${dir.substring(retentionPath.length + 1)} because retention amount of ${retentionAmount} was reached`);
|
|
||||||
dirs.splice(0, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.log(`Failed to delete old directories (${e})`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// find ids for the tags we want to assign later
|
// find ids for the tags we want to assign later
|
||||||
let tagIds = new Map();
|
let tagIds = new Map();
|
||||||
if (tags) {
|
if (tags) {
|
||||||
|
@ -93,7 +52,7 @@ async function upload() {
|
||||||
</d:prop>
|
</d:prop>
|
||||||
</d:propfind>`
|
</d:propfind>`
|
||||||
});
|
});
|
||||||
let data = JSON.parse(xml.toJson(response.data))["d:multistatus"]["d:response"].map(e => e["d:propstat"]["d:prop"]);
|
var data = JSON.parse(xml.toJson(response.data))["d:multistatus"]["d:response"].map(e => e["d:propstat"]["d:prop"]);
|
||||||
for (let tag of tags.split(",")) {
|
for (let tag of tags.split(",")) {
|
||||||
let entry = data.find(e => e["oc:display-name"] == tag);
|
let entry = data.find(e => e["oc:display-name"] == tag);
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
|
@ -187,7 +146,7 @@ async function addTags(basePath, tagIds, fileName, location) {
|
||||||
</d:prop>
|
</d:prop>
|
||||||
</d:propfind>`
|
</d:propfind>`
|
||||||
});
|
});
|
||||||
let 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 ${fileName} is ${fileId}`);
|
console.log(`File id of ${fileName} is ${fileId}`);
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
export PLUGIN_SERVER=https://cloud.ellpeck.de
|
export PLUGIN_SERVER=https://cloud.ellpeck.de
|
||||||
export PLUGIN_USER=EllBot
|
export PLUGIN_USER=EllBot
|
||||||
export PLUGIN_FILES=**/*.md
|
export PLUGIN_FILES=Dockerfile
|
||||||
export PLUGIN_DEST=Uploads/$(date '+%M:%S')
|
export PLUGIN_DEST=Test/Testing
|
||||||
export PLUGIN_RETENTION_BASE=Uploads
|
export PLUGIN_TAGS="Autoremove 1D"
|
||||||
export PLUGIN_RETENTION_AMOUNT=3
|
|
||||||
|
|
||||||
npm install
|
npm install
|
||||||
node run.js
|
node run.js
|
||||||
|
|
Loading…
Reference in a new issue