Fix overwrite of "Other" field
parent
229a7a7e78
commit
fa17008758
|
@ -58,18 +58,20 @@ export default async function fetchPlatformData(): Promise<void> {
|
||||||
// Check if the data are cached
|
// Check if the data are cached
|
||||||
if (!readCache(shared.cachePath)) {
|
if (!readCache(shared.cachePath)) {
|
||||||
// Load the HTML
|
// Load the HTML
|
||||||
const html = await fetchHTML(f95url.LATEST_UPDATES);
|
const response = await fetchHTML(f95url.LATEST_UPDATES);
|
||||||
|
|
||||||
// Parse data
|
// Parse data
|
||||||
if (html.isSuccess()) {
|
const result = response.applyOnSuccess((html) => {
|
||||||
const data = parseLatestPlatformHTML(html.value);
|
const data = parseLatestPlatformHTML(html);
|
||||||
|
|
||||||
// Assign data
|
// Assign data
|
||||||
assignLatestPlatformData(data);
|
assignLatestPlatformData(data);
|
||||||
|
|
||||||
// Cache data
|
// Cache data
|
||||||
saveCache(shared.cachePath);
|
saveCache(shared.cachePath);
|
||||||
} else throw html.value;
|
});
|
||||||
|
|
||||||
|
if (result.isFailure()) throw result.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,12 +142,19 @@ function assignLatestPlatformData(data: ILatestResource): void {
|
||||||
// Prepare the dict
|
// Prepare the dict
|
||||||
const dict: TPrefixDict = {};
|
const dict: TPrefixDict = {};
|
||||||
|
|
||||||
for (const e of res.prefixes) {
|
// Assign values
|
||||||
dict[e.id] = e.name.replace("'", "'");
|
res.prefixes.map((e) => (dict[e.id] = e.name.replace("'", "'")));
|
||||||
}
|
|
||||||
|
|
||||||
// Save the property
|
// Merge the dicts ("Other"/"Status" field)
|
||||||
scrapedData[res.name] = dict;
|
if (scrapedData[res.name]) {
|
||||||
|
const newKeys = Object.keys(dict)
|
||||||
|
.map((k) => parseInt(k, 10))
|
||||||
|
.filter((k) => !scrapedData[res.name][k]);
|
||||||
|
|
||||||
|
newKeys.map((k) => (scrapedData[res.name][k] = dict[k]));
|
||||||
|
}
|
||||||
|
// Assign the property
|
||||||
|
else scrapedData[res.name] = dict;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue