fix: pcgamingwiki not parsing company websites

This commit is contained in:
Huskydog9988
2025-05-08 21:22:15 -04:00
committed by DecDuck
parent afaaaf2eb5
commit cbf480bef9
3 changed files with 25 additions and 16 deletions

View File

@ -1,17 +1,5 @@
import { prefixStorage, type StorageValue, type Storage } from "unstorage";
export interface CacheProviderOptions {
/**
* Max number of items in the cache
*/
max?: number;
/**
* Time to live (in ms)
*/
ttl?: number;
}
/**
* Creates and manages the lifecycles of various caches
*/

View File

@ -113,7 +113,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
year:
game.Released !== null && game.Released.length > 0
? // sometimes will provide multiple dates
DateTime.fromISO(game.Released.split(";")[0]).year
this.parseTS(game.Released).year
: 0,
};
return metadata;
@ -141,6 +141,22 @@ export class PCGamingWikiProvider implements MetadataProvider {
return results;
}
/**
* Parses the specific format that the wiki returns when specifying a iso timestamp
* @param isoStr
* @returns
*/
private parseTS(isoStr: string): DateTime {
return DateTime.fromISO(isoStr.split(";")[0]);
}
private parseWebsitesGetFirst(websiteStr?: string | null): string {
if (websiteStr === undefined || websiteStr === null) return "";
// string comes in format: "[https://www.gamesci.com.cn www.gamesci.com.cn]"
return websiteStr.replaceAll(/\[|]/g, "").split(" ")[0] ?? "";
}
async fetchGame({
id,
name,
@ -234,14 +250,14 @@ export class PCGamingWikiProvider implements MetadataProvider {
const company = res.data.cargoquery[i].title;
const fixedCompanyName =
company.PageName.split("Company:").at(1) ?? company.PageName;
this.parseCompanyStr(company.PageName)[0] ?? company.PageName;
const metadata: CompanyMetadata = {
id: company.PageID,
name: fixedCompanyName,
shortDescription: "",
description: "",
website: company?.Website ?? "",
website: this.parseWebsitesGetFirst(company?.Website),
logo: icon,
banner: icon,

View File

@ -22,7 +22,10 @@ export default defineTask({
);
console.log(objects);
const results = await findUnreferencedStrings(objects, buildRefMap());
console.log("[Task cleanup:objects]: Unreferenced objects: ", results);
console.log(
`[Task cleanup:objects]: found ${results.length} Unreferenced objects`,
);
console.log(results);
console.log("[Task cleanup:objects]: Done");
return { result: true };
@ -60,6 +63,8 @@ async function isReferencedInModelFields(
id: string,
fieldRefMap: FieldReferenceMap,
): Promise<boolean> {
// TODO: optimize the built queries
// rn it runs a query for every id over each db table
for (const { model, fields, arrayFields } of Object.values(fieldRefMap)) {
const singleFieldOrConditions = fields
? fields.map((field) => ({