You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/module/module-pastebin/handler.js

58 lines
1.6 KiB
JavaScript

5 years ago
const { Route, Handler } = global.Hydro.service.server;
const { PERM_LOGGEDIN } = global.Hydro.permission;
const { pastebin } = global.Hydro.model;
const { nav } = global.Hydro.lib;
4 years ago
class PasteMainHandler extends Handler {
async get() {
this.response.redirect = this.url('paste_create');
4 years ago
}
}
5 years ago
class PasteShowHandler extends Handler {
async get({ docId }) {
const doc = await pastebin.get(docId);
const path = [
4 years ago
['Hydro', 'homepage'],
['paste_show', null],
[doc.title, null, true],
];
this.response.body = { path, doc };
5 years ago
this.response.template = 'paste_show.html';
}
}
class PasteCreateHandler extends Handler {
async prepare() {
this.checkPerm(PERM_LOGGEDIN);
}
async get() {
const path = [
4 years ago
['Hydro', 'homepage'],
['paste_create', null],
];
this.response.body = { path };
5 years ago
this.response.template = 'paste_create.html';
}
async post({
language, expire, password, title, content,
}) {
const docId = await pastebin.add({
language, expire, password, owner: this.user._id, title, content,
});
this.response.body = { docId };
this.response.redirect = `/paste/${docId}`;
}
}
async function apply() {
4 years ago
Route('pastebin', '/paste', PasteMainHandler);
Route('paste_create', '/paste/create', PasteCreateHandler);
Route('paste_show', '/paste/:docId', PasteShowHandler);
4 years ago
nav('pastebin', null, 'pastebin', PERM_LOGGEDIN);
5 years ago
}
4 years ago
global.Hydro.handler.pastebin = module.exports = apply;