@abraca/dabra 2.71.0 → 2.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/abracadabra-provider.cjs +84 -4
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +84 -4
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +65 -1
- package/package.json +2 -2
- package/src/AbracadabraClient.ts +46 -0
- package/src/FileBlobStore.ts +74 -6
- package/src/types.ts +21 -0
|
@@ -11073,6 +11073,40 @@ var AbracadabraClient = class {
|
|
|
11073
11073
|
if (!res.ok) throw await this.toError(res);
|
|
11074
11074
|
return res.blob();
|
|
11075
11075
|
}
|
|
11076
|
+
/**
|
|
11077
|
+
* Build the request path (with query string) for an upload's thumbnail.
|
|
11078
|
+
* Also the canonical cache key suffix — the query string is deterministic
|
|
11079
|
+
* in insertion order, so identical options map to the same URL and the
|
|
11080
|
+
* same `FileBlobStore` cache entry.
|
|
11081
|
+
*/
|
|
11082
|
+
thumbnailPath(docId, uploadId, opts = {}) {
|
|
11083
|
+
const p = new URLSearchParams();
|
|
11084
|
+
if (opts.w != null) p.set("w", String(opts.w));
|
|
11085
|
+
if (opts.h != null) p.set("h", String(opts.h));
|
|
11086
|
+
if (opts.fit) p.set("fit", opts.fit);
|
|
11087
|
+
if (opts.format) p.set("format", opts.format);
|
|
11088
|
+
if (opts.q != null) p.set("q", String(opts.q));
|
|
11089
|
+
const qs = p.toString();
|
|
11090
|
+
return `/docs/${encodeURIComponent(docId)}/uploads/${encodeURIComponent(uploadId)}/thumbnail${qs ? `?${qs}` : ""}`;
|
|
11091
|
+
}
|
|
11092
|
+
/**
|
|
11093
|
+
* Download a generated thumbnail of an image upload as a Blob. The server
|
|
11094
|
+
* renders + caches it on first request. Because a browser `<img>` can't
|
|
11095
|
+
* send `Authorization`, callers render the returned Blob via an object URL
|
|
11096
|
+
* (see `FileBlobStore.getThumbUrl`, which also caches it locally).
|
|
11097
|
+
* Throws (with `.status = 415`) when the source isn't a thumbnailable
|
|
11098
|
+
* raster image, or `422` for an out-of-allowlist size/format.
|
|
11099
|
+
*/
|
|
11100
|
+
async getThumbnail(docId, uploadId, opts = {}) {
|
|
11101
|
+
const headers = {};
|
|
11102
|
+
if (this._token) headers["Authorization"] = `Bearer ${this._token}`;
|
|
11103
|
+
const res = await this._fetch(`${this.baseUrl}${this.thumbnailPath(docId, uploadId, opts)}`, {
|
|
11104
|
+
method: "GET",
|
|
11105
|
+
headers
|
|
11106
|
+
});
|
|
11107
|
+
if (!res.ok) throw await this.toError(res);
|
|
11108
|
+
return res.blob();
|
|
11109
|
+
}
|
|
11076
11110
|
/** Delete an upload (requires uploader or document Owner). */
|
|
11077
11111
|
async deleteUpload(docId, uploadId) {
|
|
11078
11112
|
await this.request("DELETE", `/docs/${encodeURIComponent(docId)}/uploads/${encodeURIComponent(uploadId)}`);
|
|
@@ -15589,14 +15623,48 @@ var FileBlobStore = class FileBlobStore extends EventEmitter {
|
|
|
15589
15623
|
return `${docId}/${uploadId}`;
|
|
15590
15624
|
}
|
|
15591
15625
|
/**
|
|
15626
|
+
* Cache key for a thumbnail. Lives in the SAME IDB `blobs` store as
|
|
15627
|
+
* originals (no schema bump — the frozen cross-SDK IDB contract stays
|
|
15628
|
+
* intact) under a distinct `thumb:` namespace. The spec suffix is
|
|
15629
|
+
* deterministic so identical options collapse to one entry.
|
|
15630
|
+
*/
|
|
15631
|
+
thumbKey(docId, uploadId, opts) {
|
|
15632
|
+
return `thumb:${docId}/${uploadId}/${[
|
|
15633
|
+
opts.w != null ? `w${opts.w}` : "",
|
|
15634
|
+
opts.h != null ? `h${opts.h}` : "",
|
|
15635
|
+
opts.fit ? `f${opts.fit}` : "",
|
|
15636
|
+
opts.format ? `m${opts.format}` : "",
|
|
15637
|
+
opts.q != null ? `q${opts.q}` : ""
|
|
15638
|
+
].filter(Boolean).join("-")}`;
|
|
15639
|
+
}
|
|
15640
|
+
/**
|
|
15592
15641
|
* Return a local object URL for a file.
|
|
15593
15642
|
* On first call the blob is downloaded from the server and cached in IDB.
|
|
15594
15643
|
* Returns null when offline and the blob is not yet cached, or when
|
|
15595
15644
|
* URL.createObjectURL is unavailable (e.g. Node.js / SSR).
|
|
15596
15645
|
*/
|
|
15597
15646
|
async getBlobUrl(docId, uploadId) {
|
|
15647
|
+
return this._objectUrlForKey(this.blobKey(docId, uploadId), uploadId, this.client ? () => this.client.getUpload(docId, uploadId) : null);
|
|
15648
|
+
}
|
|
15649
|
+
/**
|
|
15650
|
+
* Return a local object URL for a **thumbnail** of an image upload.
|
|
15651
|
+
* On first call the server renders + caches it and this stores the bytes
|
|
15652
|
+
* in IDB (same offline-serving model as `getBlobUrl`). Returns null when
|
|
15653
|
+
* offline + uncached, on non-image sources (server 415 → treated like a
|
|
15654
|
+
* miss), or outside the browser. Options must match the server's
|
|
15655
|
+
* `allowed_sizes` / `allowed_formats` or the fetch 422s (→ null).
|
|
15656
|
+
*/
|
|
15657
|
+
async getThumbUrl(docId, uploadId, opts = {}) {
|
|
15658
|
+
return this._objectUrlForKey(this.thumbKey(docId, uploadId, opts), uploadId, this.client ? () => this.client.getThumbnail(docId, uploadId, opts) : null);
|
|
15659
|
+
}
|
|
15660
|
+
/**
|
|
15661
|
+
* Shared read-through: in-memory object URL → IDB `blobs` cache (with a
|
|
15662
|
+
* one-shot reopen on `InvalidStateError`) → `download()` (when a client is
|
|
15663
|
+
* available), caching the result. `download === null` means "no network
|
|
15664
|
+
* source" (offline / no client) → cache-only. 404 is negative-cached.
|
|
15665
|
+
*/
|
|
15666
|
+
async _objectUrlForKey(key, filename, download) {
|
|
15598
15667
|
if (typeof window === "undefined") return null;
|
|
15599
|
-
const key = this.blobKey(docId, uploadId);
|
|
15600
15668
|
const existing = this.objectUrls.get(key);
|
|
15601
15669
|
if (existing) return existing;
|
|
15602
15670
|
let db = await this.getDb();
|
|
@@ -15622,12 +15690,12 @@ var FileBlobStore = class FileBlobStore extends EventEmitter {
|
|
|
15622
15690
|
return url;
|
|
15623
15691
|
}
|
|
15624
15692
|
}
|
|
15625
|
-
if (!
|
|
15693
|
+
if (!download) return null;
|
|
15626
15694
|
const nfTime = this._notFound.get(key);
|
|
15627
15695
|
if (nfTime && Date.now() - nfTime < FileBlobStore.NOT_FOUND_TTL) return null;
|
|
15628
15696
|
let blob;
|
|
15629
15697
|
try {
|
|
15630
|
-
blob = await
|
|
15698
|
+
blob = await download();
|
|
15631
15699
|
} catch (err) {
|
|
15632
15700
|
if (err?.status === 404) this._notFound.set(key, Date.now());
|
|
15633
15701
|
return null;
|
|
@@ -15636,7 +15704,7 @@ var FileBlobStore = class FileBlobStore extends EventEmitter {
|
|
|
15636
15704
|
const entry = {
|
|
15637
15705
|
blob,
|
|
15638
15706
|
mime_type: blob.type,
|
|
15639
|
-
filename
|
|
15707
|
+
filename,
|
|
15640
15708
|
cachedAt: Date.now()
|
|
15641
15709
|
};
|
|
15642
15710
|
db.transaction("blobs", "readwrite").objectStore("blobs").put(entry, key);
|
|
@@ -15739,6 +15807,18 @@ var FileBlobStore = class FileBlobStore extends EventEmitter {
|
|
|
15739
15807
|
}
|
|
15740
15808
|
}
|
|
15741
15809
|
/**
|
|
15810
|
+
* Thumbnail counterpart of {@link invalidateUrl}: revoke the in-memory
|
|
15811
|
+
* object URL for a specific thumbnail spec without touching its IDB cache.
|
|
15812
|
+
*/
|
|
15813
|
+
invalidateThumbUrl(docId, uploadId, opts = {}) {
|
|
15814
|
+
const key = this.thumbKey(docId, uploadId, opts);
|
|
15815
|
+
const url = this.objectUrls.get(key);
|
|
15816
|
+
if (url) {
|
|
15817
|
+
URL.revokeObjectURL(url);
|
|
15818
|
+
this.objectUrls.delete(key);
|
|
15819
|
+
}
|
|
15820
|
+
}
|
|
15821
|
+
/**
|
|
15742
15822
|
* Clear the 404 negative-cache entry for (docId, uploadId) so the next
|
|
15743
15823
|
* getBlobUrl() re-fetches from the server instead of short-circuiting.
|
|
15744
15824
|
* Use on explicit user retry or after reconnect, when the file may have
|