Created
January 11, 2022 11:36
-
-
Save awesomephant/bae72f7a484df17e7fe6d24567b35404 to your computer and use it in GitHub Desktop.
Seafile Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "seafile-tools", | |
"description": "description", | |
"authors": "Max Kohler", | |
"version": "1.0.0", | |
"main": "pathToMain", | |
"dependencies": { | |
"axios": "*" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs") | |
const data = JSON.parse(fs.readFileSync("./output/upload-links.json")) | |
data.forEach(d => { | |
console.log(`${d.link}`) | |
// console.log(`${d.obj_name}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment