mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-08 20:57:08 +08:00
37 lines
1006 B
TypeScript
37 lines
1006 B
TypeScript
import { share } from '../../connection';
|
|
import { BlobSyncStorageBase } from '../../storage';
|
|
import { IDBConnection, type IDBConnectionOptions } from './db';
|
|
|
|
export class IndexedDBBlobSyncStorage extends BlobSyncStorageBase {
|
|
static readonly identifier = 'IndexedDBBlobSyncStorage';
|
|
|
|
readonly connection = share(new IDBConnection(this.options));
|
|
|
|
constructor(private readonly options: IDBConnectionOptions) {
|
|
super();
|
|
}
|
|
|
|
get db() {
|
|
return this.connection;
|
|
}
|
|
|
|
async setBlobUploadedAt(
|
|
peer: string,
|
|
blobId: string,
|
|
uploadedAt: Date | null
|
|
): Promise<void> {
|
|
const trx = this.db.inner.db.transaction('blobSync', 'readwrite');
|
|
await trx.store.put({
|
|
peer,
|
|
key: blobId,
|
|
uploadedAt,
|
|
});
|
|
}
|
|
|
|
async getBlobUploadedAt(peer: string, blobId: string): Promise<Date | null> {
|
|
const trx = this.db.inner.db.transaction('blobSync', 'readonly');
|
|
const record = await trx.store.get([peer, blobId]);
|
|
return record?.uploadedAt ?? null;
|
|
}
|
|
}
|