mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-23 04:51:49 +08:00
feat(nbstore): add upload function to blob frontend (#11247)
This commit is contained in:
@@ -23,7 +23,9 @@ export class BlobFrontend {
|
||||
}
|
||||
await lock[Symbol.asyncDispose]();
|
||||
|
||||
await this.sync.downloadBlob(blobId);
|
||||
await this.sync.downloadBlob(blobId).catch(() => {
|
||||
// ignore the error as it has already been recorded in the sync status
|
||||
});
|
||||
return await this.storage.get(blobId);
|
||||
}
|
||||
|
||||
@@ -40,14 +42,31 @@ export class BlobFrontend {
|
||||
|
||||
// We don't wait for the upload to complete,
|
||||
// as the upload process runs asynchronously in the background
|
||||
this.sync.uploadBlob(blob).catch(err => {
|
||||
// never reach here
|
||||
console.error(err);
|
||||
this.sync.uploadBlob(blob, true /* force upload */).catch(() => {
|
||||
// ignore the error as it has already been recorded in the sync status
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploads a blob to the peer. Do nothing if the blob has already been uploaded.
|
||||
*
|
||||
* @returns Always resolves to true when successful
|
||||
*
|
||||
* @throws This method will throw an error if the blob is not found locally, if the upload is aborted, or if it fails due to storage limitations.
|
||||
*/
|
||||
async upload(blobIdOrRecord: string | BlobRecord): Promise<boolean> {
|
||||
const blob =
|
||||
typeof blobIdOrRecord === 'string'
|
||||
? await this.storage.get(blobIdOrRecord)
|
||||
: blobIdOrRecord;
|
||||
if (!blob) {
|
||||
throw new Error(`Blob ${blobIdOrRecord} not found`);
|
||||
}
|
||||
return this.sync.uploadBlob(blob, false);
|
||||
}
|
||||
|
||||
fullDownload(peerId?: string, signal?: AbortSignal) {
|
||||
return this.sync.fullDownload(peerId, signal);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user