@nodaro/sdk 1.5.0 → 1.7.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/index.cjs +57 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -2
- package/dist/index.d.ts +33 -2
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -1
- package/dist/supabase-browser.cjs +71 -0
- package/dist/supabase-browser.cjs.map +1 -0
- package/dist/supabase-browser.d.cts +24 -0
- package/dist/supabase-browser.d.ts +24 -0
- package/dist/supabase-browser.js +69 -0
- package/dist/supabase-browser.js.map +1 -0
- package/package.json +20 -3
package/dist/index.cjs
CHANGED
|
@@ -1645,6 +1645,63 @@ var MediaResource = class {
|
|
|
1645
1645
|
downloadVideo(input) {
|
|
1646
1646
|
return this.client.request("POST", "/v1/download-video", { body: input });
|
|
1647
1647
|
}
|
|
1648
|
+
/**
|
|
1649
|
+
* Stream the live progress of a {@link MediaResource.downloadVideo} import
|
|
1650
|
+
* (`GET /v1/download-video/progress/:downloadId`, server-sent events) as an
|
|
1651
|
+
* async iterable. Yields a {@link DownloadVideoProgress} roughly every 500ms
|
|
1652
|
+
* until the download reaches `completed` (its event carries the stored
|
|
1653
|
+
* `videoUrl`) or `failed` (its event carries `error`), then ends. The progress
|
|
1654
|
+
* state expires server-side shortly after the download starts existing, so
|
|
1655
|
+
* start iterating promptly after `downloadVideo` returns.
|
|
1656
|
+
*
|
|
1657
|
+
* No request timeout is applied (a large import legitimately takes minutes) —
|
|
1658
|
+
* pass an `AbortSignal` to cancel from the caller.
|
|
1659
|
+
*/
|
|
1660
|
+
async *downloadVideoProgress(downloadId, opts = {}) {
|
|
1661
|
+
const url = `${this.client.baseUrl}/v1/download-video/progress/${encodeURIComponent(downloadId)}`;
|
|
1662
|
+
const token = await this.client.auth.getToken();
|
|
1663
|
+
const res = await this.client.fetch(url, {
|
|
1664
|
+
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
|
1665
|
+
signal: opts.signal
|
|
1666
|
+
});
|
|
1667
|
+
if (!res.ok) {
|
|
1668
|
+
let errBody = {};
|
|
1669
|
+
try {
|
|
1670
|
+
errBody = await res.json();
|
|
1671
|
+
} catch {
|
|
1672
|
+
}
|
|
1673
|
+
throwFromResponse(res.status, errBody);
|
|
1674
|
+
}
|
|
1675
|
+
if (!res.body) {
|
|
1676
|
+
throw new NodaroError("progress stream has no response body", "empty_stream", res.status);
|
|
1677
|
+
}
|
|
1678
|
+
const reader = res.body.getReader();
|
|
1679
|
+
const decoder = new TextDecoder();
|
|
1680
|
+
let buffer = "";
|
|
1681
|
+
try {
|
|
1682
|
+
for (; ; ) {
|
|
1683
|
+
const { done, value } = await reader.read();
|
|
1684
|
+
if (done) break;
|
|
1685
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1686
|
+
let sep;
|
|
1687
|
+
while ((sep = buffer.indexOf("\n\n")) >= 0) {
|
|
1688
|
+
const frame = buffer.slice(0, sep);
|
|
1689
|
+
buffer = buffer.slice(sep + 2);
|
|
1690
|
+
for (const line of frame.split("\n")) {
|
|
1691
|
+
if (!line.startsWith("data:")) continue;
|
|
1692
|
+
try {
|
|
1693
|
+
yield JSON.parse(line.slice(5).trim());
|
|
1694
|
+
} catch {
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
} finally {
|
|
1700
|
+
reader.releaseLock();
|
|
1701
|
+
await res.body.cancel().catch(() => {
|
|
1702
|
+
});
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1648
1705
|
/**
|
|
1649
1706
|
* Copy an external media URL into your Nodaro storage (`POST /v1/save-to-storage`)
|
|
1650
1707
|
* — a server-side fetch, so nothing round-trips through the client. Poll
|