Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete implementation of open & delete buttons #196

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 31 additions & 1 deletion app/src/Admin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
th Downloaded
th Expire
th Size
th Actions
template(v-for="(bucket, sid) in db")
tbody(:class="{expanded: expand===sid}")
tr.bucket(@click="expandView(sid)")
Expand All @@ -41,6 +42,9 @@
template(v-if="typeof sum[sid].firstExpire === 'number'") {{ sum[sid].firstExpire | date }}
template(v-else) {{ sum[sid].firstExpire }}
td.text-right {{ humanFileSize(sum[sid].size) }}
td
a(:href="baseURI + sid", title='Open bucket')
icon(name="folder-open")
tbody.expanded(v-if="expand === sid")
template(v-for="file in bucket")
tr.file
Expand All @@ -53,10 +57,14 @@
template(v-if="typeof file.expireDate === 'number'") {{ file.expireDate | date }}
template(v-else) {{ file.expireDate }}
td.text-right {{ humanFileSize(file.size) }}
td
a.text-danger(@click='deleteFile(file.metadata.sid, file.metadata.key)', title='Delete file')
icon(name="trash")
tfoot
tr
td(colspan="3")
td.text-right(colspan="2") Sum: {{ humanFileSize(sizeSum) }}
td

</template>

Expand All @@ -66,13 +74,16 @@
import 'vue-awesome/icons/sync-alt';
import 'vue-awesome/icons/sign-in-alt';
import 'vue-awesome/icons/key';
import 'vue-awesome/icons/folder-open';
import 'vue-awesome/icons/trash';


export default {
name: 'app',

data () {
return {
baseURI: this.$root.baseURI,
db: {},
sum: {},
loggedIn: false,
Expand Down Expand Up @@ -160,8 +171,27 @@
return Math.max(fileSizeInBytes, 0.00).toFixed(2) + byteUnits[i];
},

},
deleteFile(sid, key) {
const xhr = new XMLHttpRequest();
xhr.open('DELETE', this.$root.baseURI + 'files');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('x-passwd', this.password);
xhr.send(JSON.stringify({'sid': sid, 'key': key}));
xhr.onload = () => {
if(xhr.status === 200) {
try {
this.login();
} catch(e) {
this.error = e.toString();
}
} else {
this.error = `${xhr.status} ${xhr.statusText}: ${xhr.responseText}`;
}
};
xhr.send();
},

},

}
</script>
Expand Down
15 changes: 12 additions & 3 deletions lib/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,8 @@ app.get(`${ config.baseUrl }files/:fid`, async (req, res, next) => {
});


// Upload file
app.use(`${ config.uploadAppPath }files`,
function(req, res, next) {
// Upload or delete file
app.use(`${ config.uploadAppPath }files`, async (req, res, next) => {
// Upload password protection
if (config.uploadPass) {
const bfTimeout = 500;
Expand Down Expand Up @@ -355,6 +354,16 @@ app.use(`${ config.uploadAppPath }files`,
}
}

if (req.method === 'DELETE') {
try {
await db.remove(req.body.sid, req.body.key);
}
catch (e) {
console.error(e);
return res.status(400).end(e.message);
}
}

next();
},

Expand Down