WIP: add user posts page

This commit is contained in:
3nprob
2021-10-08 02:29:02 +09:00
parent e93a7a32e9
commit 341e6e1d55
5 changed files with 172 additions and 3 deletions

View File

@@ -62,6 +62,17 @@ export const fetchComments = async (galleryID: string): Promise<Comment[]> => {
/* eslint-enable max-len */
}
export const fetchUserPosts = async (userID: string, sort: Sorting = 'newest'): Promise<Comment[]> => {
/* eslint-disable max-len */
// https://api.imgur.com/3/account/mombotnumber5/submissions/0/newest?album_previews=1&client_id=${CLIENT_ID}
const response = await got(
`https://api.imgur.com/3/account/${userID.toLowerCase()}/submissions/0/newest?album_previews=1&client_id=${CONFIG.imgur_client_id}`,
{ agent }
);
return JSON.parse(response.body).data;
/* eslint-enable max-len */
}
export const fetchGallery = async (galleryID: string): Promise<Gallery> => {
// https://imgur.com/gallery/g1bk7CB
const response = await got(`https://imgur.com/gallery/${galleryID}`, { agent });

View File

@@ -1,6 +1,6 @@
import Hapi = require('@hapi/hapi');
import '@hapi/vision';
import { fetchAlbum, fetchAlbumURL, fetchComments, fetchGallery, fetchMedia } from './fetchers';
import { fetchAlbum, fetchAlbumURL, fetchComments, fetchGallery, fetchMedia, fetchUserPosts } from './fetchers';
import * as util from './util';
import CONFIG from './config';
@@ -35,9 +35,18 @@ export const handleAlbum = async (request: Hapi.Request, h: Hapi.ResponseToolkit
});
};
export const handleUser = (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
export const handleUser = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
// https://imgur.com/user/MomBotNumber5
throw new Error('not implemented');
if (!CONFIG.use_api) {
return 'User page disabled. Rimgu administrator needs to enable API for this to work.';
}
const userID = request.params.userID;
const userPosts = await fetchUserPosts(userID);
return h.view('user-posts', {
userPosts,
pageTitle: CONFIG.page_title,
util,
});
};
export const handleTag = (request: Hapi.Request, h: Hapi.ResponseToolkit) => {

View File

@@ -8,6 +8,7 @@ interface Account {
type MediaMimeType = 'image/jpeg' | 'image/png' | 'image/gif';
type MediaType = 'image';
type MediaExt = 'jpeg' | 'png' | 'gif';
type Sorting = 'newest' | 'oldest' | 'best';
interface Tag {
tag: string;