2021-10-06 09:43:59 +00:00
|
|
|
import Hapi = require('@hapi/hapi');
|
|
|
|
import '@hapi/vision';
|
2021-10-08 06:45:56 +00:00
|
|
|
import { fetchAlbum, fetchAlbumURL, fetchComments, fetchGallery, fetchMedia, fetchTagPosts, fetchUserPosts }
|
|
|
|
from './fetchers';
|
2021-10-06 09:43:59 +00:00
|
|
|
import * as util from './util';
|
|
|
|
|
2021-10-06 15:48:05 +00:00
|
|
|
import CONFIG from './config';
|
|
|
|
|
2021-10-06 09:43:59 +00:00
|
|
|
export const handleMedia = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
|
|
|
|
const {
|
|
|
|
baseName,
|
|
|
|
extension,
|
|
|
|
} = request.params;
|
|
|
|
const result = await fetchMedia(`${baseName}.${extension}`);
|
|
|
|
const response = h.response(result.rawBody)
|
|
|
|
.header('Content-Type', result.headers["content-type"] || `image/${extension}`);
|
|
|
|
return response;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const handleAlbum = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
|
|
|
|
// https://imgur.com/a/DfEsrAB
|
2021-10-06 17:47:10 +00:00
|
|
|
const albumID = request.params.albumID;
|
2021-10-07 06:00:50 +00:00
|
|
|
if (CONFIG.use_api) {
|
|
|
|
const album = await fetchAlbum(albumID);
|
|
|
|
return h.view('gallery', {
|
|
|
|
...album,
|
2021-10-06 17:47:10 +00:00
|
|
|
pageTitle: CONFIG.page_title,
|
|
|
|
util,
|
|
|
|
});
|
|
|
|
}
|
2021-10-07 06:15:35 +00:00
|
|
|
const url = await fetchAlbumURL(albumID);
|
|
|
|
return h.view('bare-album', {
|
|
|
|
url,
|
|
|
|
pageTitle: CONFIG.page_title,
|
|
|
|
util,
|
|
|
|
});
|
2021-10-06 09:43:59 +00:00
|
|
|
};
|
|
|
|
|
2021-10-07 17:29:02 +00:00
|
|
|
export const handleUser = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
|
2021-10-06 09:43:59 +00:00
|
|
|
// 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 06:45:56 +00:00
|
|
|
const posts = await fetchUserPosts(userID);
|
2021-10-07 17:29:02 +00:00
|
|
|
return h.view('user-posts', {
|
2021-10-08 06:45:56 +00:00
|
|
|
posts,
|
2021-10-07 17:29:02 +00:00
|
|
|
pageTitle: CONFIG.page_title,
|
|
|
|
util,
|
|
|
|
});
|
2021-10-06 09:43:59 +00:00
|
|
|
};
|
|
|
|
|
2021-10-08 06:45:56 +00:00
|
|
|
export const handleTag = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
|
2021-10-06 09:43:59 +00:00
|
|
|
// 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);
|
|
|
|
return h.view('user-posts', {
|
|
|
|
posts: result.items,
|
|
|
|
pageTitle: CONFIG.page_title,
|
|
|
|
tag: result,
|
|
|
|
util,
|
|
|
|
});
|
2021-10-06 09:43:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const handleGallery = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
|
|
|
|
const galleryID = request.params.galleryID;
|
|
|
|
const gallery = await fetchGallery(galleryID);
|
2021-10-07 06:00:50 +00:00
|
|
|
const comments = CONFIG.use_api
|
|
|
|
? await fetchComments(galleryID)
|
|
|
|
: null;
|
2021-10-06 09:43:59 +00:00
|
|
|
return h.view('gallery', {
|
|
|
|
...gallery,
|
|
|
|
comments,
|
2021-10-06 17:47:10 +00:00
|
|
|
pageTitle: CONFIG.page_title,
|
2021-10-06 09:43:59 +00:00
|
|
|
util,
|
|
|
|
});
|
|
|
|
};
|