added mangaupdates integration

cleanup db related code
cleanup ui
ui eye candy
This commit is contained in:
wea_ondara
2023-09-26 16:47:08 +02:00
parent 641a4425aa
commit 7f28012520
36 changed files with 1435 additions and 168 deletions

View File

@@ -0,0 +1,73 @@
import {type IDBPDatabase, openDB} from 'idb';
import type {MangaUpdatesSeries} from '@/data/models/mangaupdates/MangaUpdatesSeries';
import type {MangaUpdatesChapter} from '@/data/models/mangaupdates/MangaUpdatesChapter';
export type MuDb = IDBPDatabase<MangaUpdatesDBSchema>;
export default class MangaUpdatesDb {
private intDb: IDBPDatabase<MangaUpdatesDBSchema> | null = null;
get db(): IDBPDatabase<MangaUpdatesDBSchema> | null {
return this.intDb;
}
static async withDb<T>(fn: (db: MuDb) => Promise<T> | T): Promise<T> {
const db = new MangaUpdatesDb();
const idb = await db.open();
try {
return await fn(idb);
} finally {
db.close();
}
}
async open(): Promise<IDBPDatabase<MangaUpdatesDBSchema>> {
this.intDb = await openDB('mangaupdates', 1, {
upgrade(db, oldVersion, newVersion, transaction, event) {
switch (oldVersion) {
case 0:
const relation = db.createObjectStore('relation', {autoIncrement: true});
relation.createIndex('unique', ['aniListMediaId', 'mangaUpdatesSeriesId'], {unique: true});
const media = db.createObjectStore('series', {keyPath: 'series_id'});
media.createIndex('series_id', 'series_id', {unique: true});
const chapter = db.createObjectStore('chapter', {autoIncrement: true});
chapter.createIndex('series_id', 'series_id', {multiEntry: true});
//fall through
default:
break;
}
},
});
return this.intDb;
}
close(): void {
this.intDb?.close();
}
}
export type MangaUpdatesDBSchema = {
relation: {
key: 'id',
value: MangaUpdatesRelation,
indexes: {
unique: [number, number]
}
},
series: {
key: 'series_id';
value: MangaUpdatesSeries;
indexes: {
series_id: number
}
},
chapter: {
key: 'id';
value: MangaUpdatesChapter;
indexes: {
series_id: number
}
},
}