2023-02-15 10:36:47 -05:00
|
|
|
import Dexie, { Table } from 'dexie'
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create a database for bucket file cache
|
|
|
|
*database name: bucketFileDb
|
|
|
|
*structure:
|
2023-03-01 22:41:06 -05:00
|
|
|
* - table: picBedName
|
|
|
|
* - key: alias-bucketName-prefix
|
|
|
|
* - value: from fullList
|
|
|
|
* - primaryKey: key
|
2023-02-15 10:36:47 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
export interface IFileCache {
|
2024-04-09 03:03:32 -04:00
|
|
|
key: string
|
2023-02-15 10:36:47 -05:00
|
|
|
value: any
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* new picbed will add a plist suffix to distinguish from picgo
|
|
|
|
*/
|
|
|
|
export class FileCacheDb extends Dexie {
|
|
|
|
aliyun: Table<IFileCache, string>
|
|
|
|
github: Table<IFileCache, string>
|
|
|
|
imgur: Table<IFileCache, string>
|
2023-08-06 05:06:37 -04:00
|
|
|
local: Table<IFileCache, string>
|
2023-08-10 03:11:57 -04:00
|
|
|
tcyun: Table<IFileCache, string>
|
|
|
|
qiniu: Table<IFileCache, string>
|
|
|
|
smms: Table<IFileCache, string>
|
|
|
|
s3plist: Table<IFileCache, string>
|
2023-08-20 00:06:28 -04:00
|
|
|
sftp: Table<IFileCache, string>
|
2023-08-10 03:11:57 -04:00
|
|
|
upyun: Table<IFileCache, string>
|
|
|
|
webdavplist: Table<IFileCache, string>
|
2023-02-15 10:36:47 -05:00
|
|
|
|
|
|
|
constructor () {
|
|
|
|
super('bucketFileDb')
|
2023-08-20 00:06:28 -04:00
|
|
|
const tableNames = ['aliyun', 'github', 'imgur', 'local', 'qiniu', 's3plist', 'sftp', 'smms', 'tcyun', 'upyun', 'webdavplist']
|
2023-08-10 03:11:57 -04:00
|
|
|
|
2023-02-15 10:36:47 -05:00
|
|
|
const tableNamesMap = tableNames.reduce((acc, cur) => {
|
|
|
|
acc[cur] = '&key, value'
|
|
|
|
return acc
|
|
|
|
}, {} as IStringKeyMap)
|
2023-08-20 00:06:28 -04:00
|
|
|
this.version(5).stores(tableNamesMap)
|
2023-02-15 10:36:47 -05:00
|
|
|
this.aliyun = this.table('aliyun')
|
|
|
|
this.github = this.table('github')
|
|
|
|
this.imgur = this.table('imgur')
|
2023-08-06 05:06:37 -04:00
|
|
|
this.local = this.table('local')
|
2023-08-10 03:11:57 -04:00
|
|
|
this.qiniu = this.table('qiniu')
|
|
|
|
this.tcyun = this.table('tcyun')
|
|
|
|
this.s3plist = this.table('s3plist')
|
2023-08-20 00:06:28 -04:00
|
|
|
this.sftp = this.table('sftp')
|
2023-08-10 03:11:57 -04:00
|
|
|
this.smms = this.table('smms')
|
|
|
|
this.upyun = this.table('upyun')
|
|
|
|
this.webdavplist = this.table('webdavplist')
|
2023-02-15 10:36:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const fileCacheDbInstance = new FileCacheDb()
|