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/hydro/handler/wiki.ts

32 lines
1.1 KiB
TypeScript

import { NotFoundError } from '../error';
import {
Route, Handler, Types, param,
} from '../service/server';
5 years ago
5 years ago
class WikiHandler extends Handler {
@param('category', Types.String, true)
@param('page', Types.String)
async get(domainId: string, category = 'wiki', page: string) {
4 years ago
if (!global.Hydro.wiki[category]) throw new NotFoundError(category);
if (!global.Hydro.wiki[category][page]) throw new NotFoundError(category, page);
const contents = global.Hydro.wiki[category][page];
const pages = Object.keys(global.Hydro.wiki[category]);
5 years ago
const path = [
4 years ago
['Hydro', 'homepage'],
4 years ago
[`wiki_${category}`, null],
[`wiki_${category}_${page}`, null],
5 years ago
];
5 years ago
this.response.body = {
path, contents, pages, page_name: `wiki_${category}_${page}`,
5 years ago
};
this.response.template = 'wiki.html';
5 years ago
}
}
export async function apply() {
Route('wiki', '/wiki/:page', WikiHandler);
4 years ago
Route('wiki_with_category', '/wiki/:category/:page', WikiHandler);
5 years ago
}
global.Hydro.handler.wiki = apply;