Remove unneeded sections
This commit is contained in:
parent
a425a9d5c6
commit
ee689be3a9
16
api/f.ts
16
api/f.ts
|
@ -25,19 +25,3 @@ export const fetchTagPosts = async (tagID: string, sort: Sorting = 'viral'): Pro
|
||||||
return JSON.parse(response.body).data;
|
return JSON.parse(response.body).data;
|
||||||
/* eslint-enable max-len */
|
/* eslint-enable max-len */
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchGallery = async (galleryID: string): Promise<Gallery> => {
|
|
||||||
// https://imgur.com/gallery/g1bk7CB
|
|
||||||
const response = await get(`https://imgur.com/gallery/${galleryID}`);
|
|
||||||
const $ = cheerio.load(response.body);
|
|
||||||
const postDataScript = $('head script:first-of-type').html();
|
|
||||||
if (!postDataScript) {
|
|
||||||
throw new Error('Could not find gallery data');
|
|
||||||
}
|
|
||||||
const postDataMatches = postDataScript.match(GALLERY_JSON_REGEX);
|
|
||||||
if (!postDataMatches || postDataMatches.length < 2) {
|
|
||||||
throw new Error('Could not parse gallery data');
|
|
||||||
}
|
|
||||||
const body = postDataMatches[1].replace(/\\'/g, "'");
|
|
||||||
return JSON.parse(JSON.parse(body));
|
|
||||||
};
|
|
17
pages/h.ts
17
pages/h.ts
|
@ -1,6 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const handleUser = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
|
export const handleUser = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
|
||||||
// https://imgur.com/user/MomBotNumber5
|
// https://imgur.com/user/MomBotNumber5
|
||||||
if (!CONFIG.use_api) {
|
if (!CONFIG.use_api) {
|
||||||
|
@ -39,17 +36,3 @@ export const handleTag = async (request: Hapi.Request, h: Hapi.ResponseToolkit)
|
||||||
util,
|
util,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const handleGallery = async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
|
|
||||||
const galleryID = request.params.galleryID;
|
|
||||||
const gallery = await fetchGallery(galleryID);
|
|
||||||
const comments = CONFIG.use_api
|
|
||||||
? await fetchComments(galleryID)
|
|
||||||
: null;
|
|
||||||
return h.view('gallery', {
|
|
||||||
...gallery,
|
|
||||||
comments,
|
|
||||||
pageTitle: CONFIG.page_title,
|
|
||||||
util,
|
|
||||||
});
|
|
||||||
};
|
|
Loading…
Reference in New Issue