Merge scripts

pull/77/head
MillenniumEarl 2021-03-08 12:36:45 +01:00
parent d16ee36fc1
commit bc3ed3c11c
2 changed files with 26 additions and 41 deletions

View File

@ -1,40 +0,0 @@
// Copyright (c) 2021 MillenniumEarl
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
"use strict";
// Modules from files
import fetchHandiworkURLs from "./fetch-handiwork";
import fetchLatestHandiworkURLs from "./fetch-latest";
import fetchThreadHandiworkURLs from "./fetch-thread";
import HandiworkSearchQuery from "../classes/query/handiwork-search-query";
import LatestSearchQuery from "../classes/query/latest-search-query";
import ThreadSearchQuery from "../classes/query/thread-search-query";
import { IQuery } from "../interfaces";
//#region Public methods
/**
* @param query Query used for the search
* @param limit Maximum number of items to get. Default: 30
* @returns URLs of the fetched games
*/
export default async function getURLsFromQuery(
query: IQuery,
limit = 30
): Promise<string[]> {
switch (query.itype) {
case "HandiworkSearchQuery":
return fetchHandiworkURLs(query as HandiworkSearchQuery, limit);
case "LatestSearchQuery":
return fetchLatestHandiworkURLs(query as LatestSearchQuery, limit);
case "ThreadSearchQuery":
return fetchThreadHandiworkURLs(query as ThreadSearchQuery, limit);
default:
throw Error(`Invalid query type: ${query.itype}`);
}
}
//#endregion

View File

@ -9,7 +9,10 @@
// Modules from file // Modules from file
import { IBasic, IQuery } from "./interfaces"; import { IBasic, IQuery } from "./interfaces";
import getHandiworkInformation from "./scrape-data/handiwork-parse"; import getHandiworkInformation from "./scrape-data/handiwork-parse";
import getURLsFromQuery from "./fetch-data/fetch-query"; import { HandiworkSearchQuery, LatestSearchQuery, ThreadSearchQuery } from "..";
import fetchHandiworkURLs from "./fetch-data/fetch-handiwork";
import fetchLatestHandiworkURLs from "./fetch-data/fetch-latest";
import fetchThreadHandiworkURLs from "./fetch-data/fetch-thread";
/** /**
* Gets the handiworks that match the passed parameters. * Gets the handiworks that match the passed parameters.
@ -29,3 +32,25 @@ export default async function search<T extends IBasic>(
return Promise.all(results); return Promise.all(results);
} }
//#region Private methods
/**
* @param query Query used for the search
* @param limit Maximum number of items to get. Default: 30
* @returns URLs of the fetched games
*/
async function getURLsFromQuery(query: IQuery, limit = 30): Promise<string[]> {
switch (query.itype) {
case "HandiworkSearchQuery":
return fetchHandiworkURLs(query as HandiworkSearchQuery, limit);
case "LatestSearchQuery":
return fetchLatestHandiworkURLs(query as LatestSearchQuery, limit);
case "ThreadSearchQuery":
return fetchThreadHandiworkURLs(query as ThreadSearchQuery, limit);
default:
throw Error(`Invalid query type: ${query.itype}`);
}
}
//#endregion Private methods