feat: removing publishers

This commit is contained in:
Chubby Granny Chaser 2024-12-23 01:14:50 +00:00
parent 618d6f8337
commit 3a1fa9ab00
No known key found for this signature in database
2 changed files with 47 additions and 51 deletions

View File

@ -37,8 +37,6 @@ export function App() {
const { t } = useTranslation("app"); const { t } = useTranslation("app");
const downloadSourceMigrationLock = useRef(false);
const { updateRepacks } = useRepacks(); const { updateRepacks } = useRepacks();
const { clearDownload, setLastPacket } = useDownload(); const { clearDownload, setLastPacket } = useDownload();
@ -198,10 +196,6 @@ export function App() {
}, [dispatch, draggingDisabled]); }, [dispatch, draggingDisabled]);
useEffect(() => { useEffect(() => {
if (downloadSourceMigrationLock.current) return;
downloadSourceMigrationLock.current = true;
updateRepacks(); updateRepacks();
const id = crypto.randomUUID(); const id = crypto.randomUUID();

View File

@ -155,60 +155,62 @@ self.onmessage = async (event: MessageEvent<Payload>) => {
const downloadSources = await downloadSourcesTable.toArray(); const downloadSources = await downloadSourcesTable.toArray();
const existingRepacks = await repacksTable.toArray(); const existingRepacks = await repacksTable.toArray();
for (const downloadSource of downloadSources) { if (downloadSources.some((source) => !source.fingerprint)) {
console.log(downloadSource); await Promise.all(
if (!downloadSource.fingerprint) { downloadSources.map(async (source) => {
await deleteDownloadSource(downloadSource.id); await deleteDownloadSource(source.id);
await importDownloadSource(downloadSource.url); await importDownloadSource(source.url);
continue; })
} );
} else {
for (const downloadSource of downloadSources) {
const headers = new AxiosHeaders();
const headers = new AxiosHeaders(); if (downloadSource.etag) {
headers.set("If-None-Match", downloadSource.etag);
}
if (downloadSource.etag) { try {
headers.set("If-None-Match", downloadSource.etag); const response = await axios.get(downloadSource.url, {
} headers,
});
try { const source = downloadSourceSchema.parse(response.data);
const response = await axios.get(downloadSource.url, {
headers,
});
const source = downloadSourceSchema.parse(response.data); const steamGames = await getSteamGames();
const steamGames = await getSteamGames(); await db.transaction(
"rw",
repacksTable,
downloadSourcesTable,
async () => {
await downloadSourcesTable.update(downloadSource.id, {
etag: response.headers["etag"],
downloadCount: source.downloads.length,
status: DownloadSourceStatus.UpToDate,
});
await db.transaction( const repacks = source.downloads.filter(
"rw", (download) =>
repacksTable, !existingRepacks.some(
downloadSourcesTable, (repack) => repack.title === download.title
async () => { )
await downloadSourcesTable.update(downloadSource.id, { );
etag: response.headers["etag"],
downloadCount: source.downloads.length,
status: DownloadSourceStatus.UpToDate,
});
const repacks = source.downloads.filter( await addNewDownloads(downloadSource, repacks, steamGames);
(download) =>
!existingRepacks.some(
(repack) => repack.title === download.title
)
);
await addNewDownloads(downloadSource, repacks, steamGames); newRepacksCount += repacks.length;
}
);
} catch (err: unknown) {
const isNotModified = (err as AxiosError).response?.status === 304;
newRepacksCount += repacks.length; await downloadSourcesTable.update(downloadSource.id, {
} status: isNotModified
); ? DownloadSourceStatus.UpToDate
} catch (err: unknown) { : DownloadSourceStatus.Errored,
const isNotModified = (err as AxiosError).response?.status === 304; });
}
await downloadSourcesTable.update(downloadSource.id, {
status: isNotModified
? DownloadSourceStatus.UpToDate
: DownloadSourceStatus.Errored,
});
} }
} }