rimgo/pages/h.ts

38 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-10-07 17:29:02 +00:00
export const handleUser = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
// https://imgur.com/user/MomBotNumber5
2021-10-07 17:29:02 +00:00
if (!CONFIG.use_api) {
return 'User page disabled. Rimgu administrator needs to enable API for this to work.';
}
const userID = request.params.userID;
2021-10-08 07:38:43 +00:00
const user = await fetchUserInfo(userID);
2021-10-08 06:45:56 +00:00
const posts = await fetchUserPosts(userID);
2021-10-08 07:42:13 +00:00
return h.view('posts', {
2021-10-08 06:45:56 +00:00
posts,
2021-10-08 07:38:43 +00:00
user,
2021-10-07 17:29:02 +00:00
pageTitle: CONFIG.page_title,
util,
});
};
2021-10-08 07:56:54 +00:00
export const handleUserCover = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
const userID = request.params.userID;
const result = await fetchMedia(`/user/${userID}/cover?maxwidth=2560`);
const response = h.response(result.rawBody)
.header('Content-Type', result.headers["content-type"] || `image/jpeg`);
return response;
};
2021-10-08 06:45:56 +00:00
export const handleTag = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
// https://imgur.com/t/funny
2021-10-08 06:45:56 +00:00
if (!CONFIG.use_api) {
return 'Tag page disabled. Rimgu administrator needs to enable API for this to work.';
}
const tagID = request.params.tagID;
const result = await fetchTagPosts(tagID);
2021-10-08 07:42:13 +00:00
return h.view('posts', {
2021-10-08 06:45:56 +00:00
posts: result.items,
pageTitle: CONFIG.page_title,
tag: result,
util,
});
2022-01-17 20:23:04 +00:00
};