handle user cover

This commit is contained in:
3nprob 2021-10-08 16:56:54 +09:00
parent 1da6e52be6
commit 903eb2b9ba
2 changed files with 14 additions and 1 deletions

View File

@ -54,6 +54,14 @@ export const handleUser = async (request: Hapi.Request, h: Hapi.ResponseToolkit)
}); });
}; };
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;
};
export const handleTag = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => { export const handleTag = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
// https://imgur.com/t/funny // https://imgur.com/t/funny
if (!CONFIG.use_api) { if (!CONFIG.use_api) {

View File

@ -2,7 +2,7 @@ import Hapi = require('@hapi/hapi');
/* eslint-disable @typescript-eslint/no-var-requires */ /* eslint-disable @typescript-eslint/no-var-requires */
const Exiting = require('exiting'); const Exiting = require('exiting');
import Path = require('path'); import Path = require('path');
import { handleAlbum, handleGallery, handleMedia, handleTag, handleUser } from './handlers'; import { handleAlbum, handleGallery, handleMedia, handleTag, handleUser, handleUserCover } from './handlers';
import CONFIG from './config'; import CONFIG from './config';
@ -65,6 +65,11 @@ const init = async () => {
path: '/user/{userID?}', path: '/user/{userID?}',
handler: handleUser, handler: handleUser,
}); });
server.route({
method: 'GET',
path: '/user/{userID}/cover',
handler: handleUserCover,
});
server.route({ server.route({
method: 'GET', method: 'GET',
path: '/gallery/{galleryID}', path: '/gallery/{galleryID}',