Files
yoresee_dropbox/web/app.js
T

39 lines
1.3 KiB
JavaScript

function app() {
return {
inboxFiles: [],
outboxFiles: [],
async loadFiles() {
const [inbox, outbox] = await Promise.all([
fetch('/api/files?dir=inbox').then(r => r.json()),
fetch('/api/files?dir=outbox').then(r => r.json())
]);
this.inboxFiles = inbox.files || [];
this.outboxFiles = outbox.files || [];
},
async upload(event, dir) {
const file = event.target.files[0];
const form = new FormData();
form.append('file', file);
form.append('dir', dir);
await fetch('/api/upload', {method: 'POST', body: form});
this.loadFiles();
},
download(id) {
window.location.href = '/api/files/' + id + '/download';
},
async deleteFile(id) {
await fetch('/api/files/' + id, {method: 'DELETE'});
this.loadFiles();
},
async share(id) {
const res = await fetch('/api/files/' + id + '/share', {method: 'POST'});
const data = await res.json();
alert('Share URL: ' + data.url);
},
async logout() {
await fetch('/api/logout', {method: 'POST'});
window.location.href = '/login';
}
};
}