Renamed imports
							parent
							
								
									c31c54aa94
								
							
						
					
					
						commit
						d38cb29de6
					
				| 
						 | 
					@ -18,9 +18,9 @@ export interface ILink extends IPostElement {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//#region Public methods
 | 
					//#region Public methods
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Given the main post of the page (#1) it extracts the information contained.
 | 
					 * Given a post of a thread page it extracts the information contained in the body.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
export function parseCheerioMainPost($: cheerio.Root, post: cheerio.Cheerio): IPostElement[] {
 | 
					export function parseF95ThreadPost($: cheerio.Root, post: cheerio.Cheerio): IPostElement[] {
 | 
				
			||||||
    // The data is divided between "tag" and "text" elements. 
 | 
					    // The data is divided between "tag" and "text" elements. 
 | 
				
			||||||
    // Simple data is composed of a "tag" element followed 
 | 
					    // Simple data is composed of a "tag" element followed 
 | 
				
			||||||
    // by a "text" element, while more complex data (contained 
 | 
					    // by a "text" element, while more complex data (contained 
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,11 +7,11 @@ import luxon from "luxon";
 | 
				
			||||||
// Modules from file
 | 
					// Modules from file
 | 
				
			||||||
import shared from "../shared.js";
 | 
					import shared from "../shared.js";
 | 
				
			||||||
import { fetchHTML } from "../network-helper.js";
 | 
					import { fetchHTML } from "../network-helper.js";
 | 
				
			||||||
import { getJSONLD, TJsonLD } from "../json-ld.js";
 | 
					import { getJSONLD, TJsonLD } from "./json-ld.js";
 | 
				
			||||||
import { selectors as f95Selector } from "../constants/css-selector.js";
 | 
					import { selectors as f95Selector } from "../constants/css-selector.js";
 | 
				
			||||||
import HandiWork from "../classes/handiwork/handiwork.js";
 | 
					import HandiWork from "../classes/handiwork/handiwork.js";
 | 
				
			||||||
import { TRating, IBasic, TAuthor, TExternalPlatform, TEngine, TStatus, TCategory } from "../interfaces.js";
 | 
					import { TRating, IBasic, TAuthor, TExternalPlatform, TEngine, TStatus, TCategory } from "../interfaces.js";
 | 
				
			||||||
import { ILink, IPostElement, parseCheerioMainPost } from "./post-parse.js";
 | 
					import { ILink, IPostElement, parseF95ThreadPost } from "./post-parse.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//#region Public methods
 | 
					//#region Public methods
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,7 @@ import { ILink, IPostElement, parseCheerioMainPost } from "./post-parse.js";
 | 
				
			||||||
 * If you don't want to specify the object type, use `HandiWork`.
 | 
					 * If you don't want to specify the object type, use `HandiWork`.
 | 
				
			||||||
 * @todo It does not currently support assets.
 | 
					 * @todo It does not currently support assets.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
export async function getPostInformation<T extends IBasic>(url: string): Promise<T | null> {
 | 
					export async function getHandiworkInformation<T extends IBasic>(url: string): Promise<T> {
 | 
				
			||||||
    shared.logger.info(`Obtaining post info from ${url}`);
 | 
					    shared.logger.info(`Obtaining post info from ${url}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Fetch HTML and prepare Cheerio
 | 
					    // Fetch HTML and prepare Cheerio
 | 
				
			||||||
| 
						 | 
					@ -31,7 +31,7 @@ export async function getPostInformation<T extends IBasic>(url: string): Promise
 | 
				
			||||||
        const mainPost = $(f95Selector.GS_POSTS).first();
 | 
					        const mainPost = $(f95Selector.GS_POSTS).first();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Extract data
 | 
					        // Extract data
 | 
				
			||||||
        const postData = parseCheerioMainPost($, mainPost);
 | 
					        const postData = parseF95ThreadPost($, mainPost);
 | 
				
			||||||
        const TJsonLD = getJSONLD(body);
 | 
					        const TJsonLD = getJSONLD(body);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Fill in the HandiWork element with the information obtained
 | 
					        // Fill in the HandiWork element with the information obtained
 | 
				
			||||||
| 
						 | 
					@ -170,7 +170,6 @@ function isMod(prefix: string): boolean {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
//#endregion Prefix Utility
 | 
					//#endregion Prefix Utility
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Compiles a HandiWork object with the data extracted 
 | 
					 * Compiles a HandiWork object with the data extracted 
 | 
				
			||||||
 * from the JSON+LD tags related to the object itself.
 | 
					 * from the JSON+LD tags related to the object itself.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@ import { IBasic } from "./interfaces.js";
 | 
				
			||||||
import HandiworkSearchQuery from "./classes/query/handiwork-search-query.js";
 | 
					import HandiworkSearchQuery from "./classes/query/handiwork-search-query.js";
 | 
				
			||||||
import LatestSearchQuery from "./classes/query/latest-search-query.js";
 | 
					import LatestSearchQuery from "./classes/query/latest-search-query.js";
 | 
				
			||||||
import ThreadSearchQuery from "./classes/query/thread-search-query.js";
 | 
					import ThreadSearchQuery from "./classes/query/thread-search-query.js";
 | 
				
			||||||
import { getPostInformation } from "./scrape-data/scrape-thread.js";
 | 
					import { getHandiworkInformation } from "./scrape-data/scrape-thread.js";
 | 
				
			||||||
import executeQuery from "./fetch-data/fetch-query.js";
 | 
					import executeQuery from "./fetch-data/fetch-query.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export async function search<T extends IBasic>(query: LatestSearchQuery, limit: number): Promise<T[]>
 | 
					export async function search<T extends IBasic>(query: LatestSearchQuery, limit: number): Promise<T[]>
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,7 @@ export default async function search<T extends IBasic>(query: any, limit: number
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Fetch the data
 | 
					    // Fetch the data
 | 
				
			||||||
    const results = urls.map((url, idx) => {
 | 
					    const results = urls.map((url, idx) => {
 | 
				
			||||||
        return getPostInformation<T>(url);
 | 
					        return getHandiworkInformation<T>(url);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return Promise.all(results);
 | 
					    return Promise.all(results);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue