File tree 4 files changed +12
-15
lines changed
4 files changed +12
-15
lines changed Original file line number Diff line number Diff line change 106
106
* Update the {@link loaded } state when the media is loaded.
107
107
*/
108
108
const checkLoaded = async () => {
109
- if (! mediaElement) {
109
+ if (! mediaElement || ! src ) {
110
110
return ;
111
111
}
112
112
133
133
}
134
134
135
135
loaded = true ;
136
+
137
+ // Revoke the thumbnail blob URL
138
+ if (asset && isThumbnail && src? .startsWith (' blob:' )) {
139
+ URL .revokeObjectURL (src);
140
+ }
136
141
};
137
142
138
143
$: {
139
144
void mediaElement;
145
+ void src;
140
146
checkLoaded ();
141
147
}
142
148
< / script>
Original file line number Diff line number Diff line change @@ -205,11 +205,6 @@ let thumbnailDB = undefined;
205
205
* @returns {Promise<string | undefined> } Thumbnail blob URL.
206
206
*/
207
207
export const getAssetThumbnailURL = async ( asset ) => {
208
- // Use a cached image if available
209
- if ( asset . thumbnailURL ) {
210
- return asset . thumbnailURL ;
211
- }
212
-
213
208
const isPDF = asset . name . endsWith ( '.pdf' ) ;
214
209
215
210
if ( ! ( [ 'image' , 'video' ] . includes ( asset . kind ) || isPDF ) ) {
@@ -235,12 +230,7 @@ export const getAssetThumbnailURL = async (asset) => {
235
230
await thumbnailDB ?. set ( asset . sha , thumbnailBlob ) ;
236
231
}
237
232
238
- const thumbnailURL = URL . createObjectURL ( thumbnailBlob ) ;
239
-
240
- // Cache the image as blob URL for later use
241
- asset . thumbnailURL = thumbnailURL ;
242
-
243
- return thumbnailURL ;
233
+ return URL . createObjectURL ( thumbnailBlob ) ;
244
234
} ;
245
235
246
236
/**
Original file line number Diff line number Diff line change @@ -200,12 +200,13 @@ export const renderPDF = async (
200
200
}
201
201
}
202
202
203
+ const blobURL = URL . createObjectURL ( blob ) ;
203
204
const canvas = new OffscreenCanvas ( 512 , 512 ) ;
204
205
const context = /** @type {OffscreenCanvasRenderingContext2D } */ ( canvas . getContext ( '2d' ) ) ;
205
206
206
207
try {
207
208
const pdfDocument = await pdfjs . getDocument ( {
208
- url : URL . createObjectURL ( blob ) ,
209
+ url : blobURL ,
209
210
isEvalSupported : false ,
210
211
disableAutoFetch : true ,
211
212
} ) . promise ;
@@ -219,6 +220,8 @@ export const renderPDF = async (
219
220
canvasContext : context ,
220
221
viewport : scale === 1 ? viewport : pdfPage . getViewport ( { scale } ) ,
221
222
} ) . promise ;
223
+
224
+ URL . revokeObjectURL ( blobURL ) ;
222
225
} catch {
223
226
throw new Error ( 'Failed to render PDF' ) ;
224
227
}
Original file line number Diff line number Diff line change 900
900
* @property {File } [file] - File object. Local backend only.
901
901
* @property {string } [blobURL] - Blob URL for the asset. It’s a temporary URL for a remote file
902
902
* being fetched or a local file being uploaded. Or `undefined` if the URL is not generated yet.
903
- * @property {string } [thumbnailURL] - Thumbnail Blob URL for the asset. Used to cache a rendered
904
- * thumbnail of a PDF document.
905
903
* @property {string } name - File name.
906
904
* @property {string } path - File path.
907
905
* @property {string } sha - SHA-1 hash for the file.
You can’t perform that action at this time.
0 commit comments