From 903eb2b9bab1eb5d8e9da39bc999a5d6f4f49bde Mon Sep 17 00:00:00 2001 From: 3nprob <3nprob@3nprob> Date: Fri, 8 Oct 2021 16:56:54 +0900 Subject: [PATCH] handle user cover --- src/handlers.ts | 8 ++++++++ src/index.ts | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/handlers.ts b/src/handlers.ts index c28eef5..10120f4 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -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) => { // https://imgur.com/t/funny if (!CONFIG.use_api) { diff --git a/src/index.ts b/src/index.ts index 3dedc53..1ff8625 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import Hapi = require('@hapi/hapi'); /* eslint-disable @typescript-eslint/no-var-requires */ const Exiting = require('exiting'); 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'; @@ -65,6 +65,11 @@ const init = async () => { path: '/user/{userID?}', handler: handleUser, }); + server.route({ + method: 'GET', + path: '/user/{userID}/cover', + handler: handleUserCover, + }); server.route({ method: 'GET', path: '/gallery/{galleryID}',