diff --git a/src/fetchers.ts b/src/fetchers.ts index 6ab9e3f..4a16707 100644 --- a/src/fetchers.ts +++ b/src/fetchers.ts @@ -9,25 +9,25 @@ import CONFIG from './config'; const GALLERY_JSON_REGEX = /window\.postDataJSON=(".*")$/; const agent = { - http: CONFIG.http_proxy + http: CONFIG.http_proxy ? new HttpProxyAgent({ - keepAlive: true, - keepAliveMsecs: 1000, - maxSockets: 256, - maxFreeSockets: 256, - scheduling: 'lifo', - proxy: CONFIG.http_proxy, - }) + keepAlive: true, + keepAliveMsecs: 1000, + maxSockets: 256, + maxFreeSockets: 256, + scheduling: 'lifo', + proxy: CONFIG.http_proxy, + }) : httpGlobalAgent, - https: CONFIG.https_proxy + https: CONFIG.https_proxy ? new HttpsProxyAgent({ - keepAlive: true, - keepAliveMsecs: 1000, - maxSockets: 256, - maxFreeSockets: 256, - scheduling: 'lifo', - proxy: CONFIG.https_proxy, - }) + keepAlive: true, + keepAliveMsecs: 1000, + maxSockets: 256, + maxFreeSockets: 256, + scheduling: 'lifo', + proxy: CONFIG.https_proxy, + }) : httpsGlobalAgent }; @@ -44,14 +44,22 @@ export const fetchAlbumURL = async (albumID: string): Promise => { export const fetchAlbum = async (albumID: string): Promise => { // https://api.imgur.com/post/v1/albums/zk7mdKH?client_id=${CLIENT_ID}&include=media%2Caccount - const response = await got(`https://api.imgur.com/post/v1/albums/${albumID}?client_id=${CONFIG.imgur_client_id}&include=media%2Caccount`, { agent }); + const response = await got( + `https://api.imgur.com/post/v1/albums/${albumID}?client_id=${CONFIG.imgur_client_id}&include=media%2Caccount`, + { agent } + ); return JSON.parse(response.body); } export const fetchComments = async (galleryID: string): Promise => { + /* eslint-disable max-len */ // https://api.imgur.com/comment/v1/comments?client_id=${CLIENT_ID}%5Bpost%5D=eq%3Ag1bk7CB&include=account%2Cadconfig&per_page=30&sort=best - const response = await got(`https://api.imgur.com/comment/v1/comments?client_id=${CONFIG.imgur_client_id}&filter%5Bpost%5D=eq%3A${galleryID}&include=account%2Cadconfig&per_page=30&sort=best`, { agent }); + const response = await got( + `https://api.imgur.com/comment/v1/comments?client_id=${CONFIG.imgur_client_id}&filter%5Bpost%5D=eq%3A${galleryID}&include=account%2Cadconfig&per_page=30&sort=best`, + { agent } + ); return JSON.parse(response.body).data; + /* eslint-enable max-len */ } export const fetchGallery = async (galleryID: string): Promise => { diff --git a/src/handlers.ts b/src/handlers.ts index 0b57ca0..6e8d815 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -26,14 +26,14 @@ export const handleAlbum = async (request: Hapi.Request, h: Hapi.ResponseToolkit pageTitle: CONFIG.page_title, util, }); - } else { - const url = await fetchAlbumURL(albumID); - return h.view('bare-album', { - url, - pageTitle: CONFIG.page_title, - util, - }); } + const url = await fetchAlbumURL(albumID); + return h.view('bare-album', { + url, + pageTitle: CONFIG.page_title, + util, + }); + }; export const handleUser = (request: Hapi.Request, h: Hapi.ResponseToolkit) => { diff --git a/src/index.ts b/src/index.ts index 638a530..6c52a13 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,7 @@ -'use strict'; - import Hapi = require('@hapi/hapi'); +/* eslint-disable @typescript-eslint/no-var-requires */ const Exiting = require('exiting'); -import Path = require('path'); +import Path = require('path'); import { handleAlbum, handleGallery, handleMedia, handleTag, handleUser } from './handlers'; import CONFIG from './config'; @@ -31,10 +30,10 @@ const init = async () => { method: 'GET', path: '/css/{param*}', handler: ({ - directory: { - path: Path.join(__dirname, 'static/css') - } - } as any) + directory: { + path: Path.join(__dirname, 'static/css') + } + } as any) // eslint-disable-line @typescript-eslint/no-explicit-any }); server.views({ engines: { diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 930c691..9a835cd 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -5,15 +5,6 @@ interface Account { created_at: string; } -interface Gallery { - id: string; - title: string; - account: Account; - media: Media[]; - tags: Tag[]; - cover: Media; -} - type MediaMimeType = 'image/jpeg' | 'image/png' | 'image/gif'; type MediaType = 'image'; type MediaExt = 'jpeg' | 'png' | 'gif'; @@ -64,8 +55,8 @@ interface Comment { platform_id: number; platform: MediaPlatform; created_at: string; - updated_at: "2021-10-01T00:08:51Z", - deleted_at: null, + updated_at: string; + deleted_at: null; next: null; //? comments: Comment[]; account: { @@ -75,3 +66,11 @@ interface Comment { } } +interface Gallery { + id: string; + title: string; + account: Account; + media: Media[]; + tags: Tag[]; + cover: Media; +}