1 line
6 KiB
Text
1 line
6 KiB
Text
|
{"version":3,"file":"index.cjs.js","sources":["../../storage/index.ts"],"sourcesContent":["import { getDownloadURL as _getDownloadURL, getMetadata as _getMetadata, uploadBytesResumable as _uploadBytesResumable, uploadString as _uploadString, } from 'firebase/storage';\nimport { Observable, from } from 'rxjs';\nimport { map, shareReplay } from 'rxjs/operators';\nexport function fromTask(task) {\n return new Observable(function (subscriber) {\n var lastSnapshot = null;\n var complete = false;\n var hasError = false;\n var error = null;\n var emit = function (snapshot) {\n lastSnapshot = snapshot;\n schedule();\n };\n var id = null;\n /**\n * Schedules an async event to check and emit\n * the most recent snapshot, and complete or error\n * if necessary.\n */\n var schedule = function () {\n if (!id) {\n id = setTimeout(function () {\n id = null;\n if (lastSnapshot)\n subscriber.next(lastSnapshot);\n if (complete)\n subscriber.complete();\n if (hasError)\n subscriber.error(error);\n });\n }\n };\n subscriber.add(function () {\n // If we have any emissions checks scheduled, cancel them.\n if (id)\n clearTimeout(id);\n });\n // Emit the initial snapshot\n emit(task.snapshot);\n // Take each update and schedule them to be emitted (see `emit`)\n subscriber.add(task.on('state_changed', emit));\n // task is a promise, so we can convert that to an observable,\n // this is done for the ergonomics around making sure we don't\n // try to push errors or completions through closed subscribers\n subscriber.add(from(task).subscribe({\n next: emit,\n error: function (err) {\n hasError = true;\n error = err;\n schedule();\n },\n complete: function () {\n complete = true;\n schedule();\n },\n }));\n });\n}\nexport function getDownloadURL(ref) {\n return from(_getDownloadURL(ref));\n}\n// TODO: fix storage typing in firebase, then apply the same fix here\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function getMetadata(ref) {\n return from(_getMetadata(ref));\n}\n// MARK: Breaking change (renaming put to uploadBytesResumable)\nexport function uploadBytesResumable(ref, data, metadata) {\n return new Observable(function (subscriber) {\n var task = _uploadBytesResumable(ref, data, metadata);\n var subscription = fromTask(task).subscribe(subscriber);\n return function unsubscribe() {\n subscription.unsubscribe();\n task.cancel();\n };\n }).pipe(shareReplay({ bufferSize: 1, refCount: true }));\n}\n// MARK: Breaking change (renaming put to uploadString)\nexport function uploadString(ref, data, format, metadata) {\n return from(_uploadString(ref, data, format, metadata));\n}\nexport function percentage(task) {\n return fromTask(task).pipe(map(function (snapshot) { return ({\n progress: (snapshot.bytesTransferred / snapshot.totalBytes) * 100,\n snapshot: snapshot,\n }); }));\n}\n"],"names":["Observable","from","_getDownloadURL","_getMetadata","_uploadBytesResumable","shareReplay","_uploadString","map"],"mappings":";;;;;;;;AAGO,SAAS,QAAQ,CAAC,IAAI,EAAE;AAC/B,IAAI,OAAO,IAAIA,eAAU,CAAC,UAAU,UAAU,EAAE;AAChD,QAAQ,IAAI,YAAY,GAAG,IAAI,CAAC;AAChC,QAAQ,IAAI,QAAQ,GAAG,KAAK,CAAC;AAC7B,QAAQ,IAAI,QAAQ,GAAG,KAAK,CAAC;AAC7B,QAAQ,IAAI,KAAK,GAAG,IAAI,CAAC;AACzB,QAAQ,IAAI,IAAI,GAAG,UAAU,QAAQ,EAAE;AACvC,YAAY,YAAY,GAAG,QAAQ,CAAC;AACpC,YAAY,QAAQ,EAAE,CAAC;AACvB,SAAS,CAAC;AACV,QAAQ,IAAI,EAAE,GAAG,IAAI,CAAC;AACtB;AACA;AACA;AACA;AACA;AACA,QAAQ,IAAI,QAAQ,GAAG,YAAY;AACnC,YAAY,IAAI,CAAC,EAAE,EAAE;AACrB,gBA
|