mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-09 05:05:52 +08:00
feat(nbstore): add blob sync storage (#10752)
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user