This commit is contained in:
3nprob 2021-10-07 15:15:35 +09:00
parent 193ba6691d
commit b382e8701b
4 changed files with 49 additions and 43 deletions

View File

@ -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<string> => {
export const fetchAlbum = async (albumID: string): Promise<Comment[]> => {
// 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<Comment[]> => {
/* 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<Gallery> => {

View File

@ -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) => {

View File

@ -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: {

21
src/types/index.d.ts vendored
View File

@ -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;
}