Skip to content

Instantly share code, notes, and snippets.

@awesomephant
Created January 11, 2022 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awesomephant/bae72f7a484df17e7fe6d24567b35404 to your computer and use it in GitHub Desktop.
Save awesomephant/bae72f7a484df17e7fe6d24567b35404 to your computer and use it in GitHub Desktop.
Seafile Scripts
const axios = require("axios");
const fs = require("fs")
const baseURL = "https://seafile.rlp.net"
let allUploadLinks = [];
let config = {
headers: {
"Authorization": "Token 565d9012b6c134e37233fb64172f6223fb584197",
'Accept': 'application/json; indent=4',
'Content-Type': 'application/x-www-form-urlencoded',
},
}
const testFolders = [
"Name-A",
"Name-B"
]
const repoID = "6ba8d05a-c1f9-4fdc-8222-faa9b1d152a7"
const dir = encodeURI("Woche-5/Aufgabe-1/")
function createUploadLink(n) {
let body = `repo_id=${repoID}&path=/${dir}/${testFolders[n]}`
axios.post(baseURL + `/api/v2.1/upload-links/`, body, config)
.then(res => {
console.log(`Created upload link for /${testFolders[n]}`)
allUploadLinks.push(res.data)
if (testFolders[n + 1]) {
createUploadLink(n + 1)
} else {
console.log("Done.")
fs.writeFileSync("./output/upload-links.json", JSON.stringify(allUploadLinks, null, " "))
}
})
.catch(e => console.log(e))
}
function createFolder(n) {
axios.post(baseURL + `/api2/repos/${repoID}/dir/?p=/${dir}/${testFolders[n]}`, "operation=mkdir", config)
.then(res => {
console.log(`Created folder /${testFolders[n]}`)
if (testFolders[n + 1]) {
createFolder(n + 1)
} else {
console.log("Done.")
createUploadLink(0)
}
})
.catch(e => console.log(e))
}
createFolder(0)
{
"name": "seafile-tools",
"description": "description",
"authors": "Max Kohler",
"version": "1.0.0",
"main": "pathToMain",
"dependencies": {
"axios": "*"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment