mirror of
https://codeberg.org/video-prize-ranch/rimgo.git
synced 2025-12-14 04:05:14 +00:00
Add user profile to user page
This commit is contained in:
@@ -62,11 +62,20 @@ export const fetchComments = async (galleryID: string): Promise<Comment[]> => {
|
||||
/* eslint-enable max-len */
|
||||
}
|
||||
|
||||
export const fetchUserInfo = async (userID: string): Promise<UserResult> => {
|
||||
// https://api.imgur.com/account/v1/accounts/hughjaniss?client_id=${CLIENT_ID}
|
||||
const response = await got(
|
||||
`https://api.imgur.com/account/v1/accounts/${userID.toLowerCase()}?client_id=${CONFIG.imgur_client_id}&include=`,
|
||||
{ agent }
|
||||
);
|
||||
return JSON.parse(response.body);
|
||||
}
|
||||
|
||||
export const fetchUserPosts = async (userID: string, sort: Sorting = 'newest'): Promise<Post[]> => {
|
||||
/* 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/gallery/${userID.toLowerCase()}/submissions/0/${sort}?album_previews=1&client_id=${CONFIG.imgur_client_id}`,
|
||||
`https://api.imgur.com/3/account/${userID.toLowerCase()}/submissions/0/${sort}?album_previews=1&client_id=${CONFIG.imgur_client_id}`,
|
||||
{ agent }
|
||||
);
|
||||
return JSON.parse(response.body).data;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import Hapi = require('@hapi/hapi');
|
||||
import '@hapi/vision';
|
||||
import { fetchAlbum, fetchAlbumURL, fetchComments, fetchGallery, fetchMedia, fetchTagPosts, fetchUserPosts }
|
||||
from './fetchers';
|
||||
import
|
||||
{
|
||||
fetchAlbum, fetchAlbumURL, fetchComments, fetchGallery, fetchMedia, fetchTagPosts, fetchUserInfo, fetchUserPosts
|
||||
} from './fetchers';
|
||||
import * as util from './util';
|
||||
|
||||
import CONFIG from './config';
|
||||
@@ -42,9 +44,11 @@ export const handleUser = async (request: Hapi.Request, h: Hapi.ResponseToolkit)
|
||||
return 'User page disabled. Rimgu administrator needs to enable API for this to work.';
|
||||
}
|
||||
const userID = request.params.userID;
|
||||
const user = await fetchUserInfo(userID);
|
||||
const posts = await fetchUserPosts(userID);
|
||||
return h.view('user-posts', {
|
||||
posts,
|
||||
user,
|
||||
pageTitle: CONFIG.page_title,
|
||||
util,
|
||||
});
|
||||
|
||||
13
src/types/index.d.ts
vendored
13
src/types/index.d.ts
vendored
@@ -128,3 +128,16 @@ interface TagResult extends PostTag {
|
||||
success: boolean;
|
||||
status: number;
|
||||
}
|
||||
|
||||
interface UserResult {
|
||||
id: number;
|
||||
username: string;
|
||||
bio: string;
|
||||
reputation_count: number;
|
||||
reputation_name: string;
|
||||
avatar_id: string;
|
||||
avatar_url: string;
|
||||
cover_id: string;
|
||||
cover_url: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user