mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-25 09:14:54 +10:00
fix: pcgamingwiki not parsing company websites
This commit is contained in:
-12
@@ -1,17 +1,5 @@
|
|||||||
import { prefixStorage, type StorageValue, type Storage } from "unstorage";
|
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
|
* Creates and manages the lifecycles of various caches
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
|
|||||||
year:
|
year:
|
||||||
game.Released !== null && game.Released.length > 0
|
game.Released !== null && game.Released.length > 0
|
||||||
? // sometimes will provide multiple dates
|
? // sometimes will provide multiple dates
|
||||||
DateTime.fromISO(game.Released.split(";")[0]).year
|
this.parseTS(game.Released).year
|
||||||
: 0,
|
: 0,
|
||||||
};
|
};
|
||||||
return metadata;
|
return metadata;
|
||||||
@@ -141,6 +141,22 @@ export class PCGamingWikiProvider implements MetadataProvider {
|
|||||||
return results;
|
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({
|
async fetchGame({
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
@@ -234,14 +250,14 @@ export class PCGamingWikiProvider implements MetadataProvider {
|
|||||||
const company = res.data.cargoquery[i].title;
|
const company = res.data.cargoquery[i].title;
|
||||||
|
|
||||||
const fixedCompanyName =
|
const fixedCompanyName =
|
||||||
company.PageName.split("Company:").at(1) ?? company.PageName;
|
this.parseCompanyStr(company.PageName)[0] ?? company.PageName;
|
||||||
|
|
||||||
const metadata: CompanyMetadata = {
|
const metadata: CompanyMetadata = {
|
||||||
id: company.PageID,
|
id: company.PageID,
|
||||||
name: fixedCompanyName,
|
name: fixedCompanyName,
|
||||||
shortDescription: "",
|
shortDescription: "",
|
||||||
description: "",
|
description: "",
|
||||||
website: company?.Website ?? "",
|
website: this.parseWebsitesGetFirst(company?.Website),
|
||||||
|
|
||||||
logo: icon,
|
logo: icon,
|
||||||
banner: icon,
|
banner: icon,
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ export default defineTask({
|
|||||||
);
|
);
|
||||||
console.log(objects);
|
console.log(objects);
|
||||||
const results = await findUnreferencedStrings(objects, buildRefMap());
|
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");
|
console.log("[Task cleanup:objects]: Done");
|
||||||
return { result: true };
|
return { result: true };
|
||||||
@@ -60,6 +63,8 @@ async function isReferencedInModelFields(
|
|||||||
id: string,
|
id: string,
|
||||||
fieldRefMap: FieldReferenceMap,
|
fieldRefMap: FieldReferenceMap,
|
||||||
): Promise<boolean> {
|
): 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)) {
|
for (const { model, fields, arrayFields } of Object.values(fieldRefMap)) {
|
||||||
const singleFieldOrConditions = fields
|
const singleFieldOrConditions = fields
|
||||||
? fields.map((field) => ({
|
? fields.map((field) => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user