Move file upload logic to data model

This commit is contained in:
Johannes Zellner
2023-04-11 16:29:58 +02:00
parent 6bf007f878
commit 5cde58e8b7
3 changed files with 16 additions and 2 deletions
+6
View File
@@ -26,6 +26,12 @@ export function createDirectoryModel(origin, accessToken, api) {
return result.body.entries;
},
async upload(targetDir, file, progressHandler) {
await superagent.post(`${origin}/api/v1/${api}/files/${encodeURIComponent(sanitize(targetDir + '/' + file.name))}`)
.query({ access_token: accessToken })
.attach('file', file)
.on('progress', progressHandler);
},
async remove(filePath) {
const [error] = await safe(superagent.del(`${origin}/api/v1/${api}/files/${filePath}`)
.query({ access_token: accessToken }));