@banou/ripple 0.0.1 → 0.0.4

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.
@@ -0,0 +1,116 @@
1
+ var O = "osra-message", g = (e) => !!(globalThis.SharedArrayBuffer && e instanceof globalThis.SharedArrayBuffer), l = (e) => globalThis.ArrayBuffer && e instanceof globalThis.ArrayBuffer || globalThis.MessagePort && e instanceof globalThis.MessagePort || globalThis.ReadableStream && e instanceof globalThis.ReadableStream || globalThis.WritableStream && e instanceof globalThis.WritableStream || globalThis.TransformStream && e instanceof globalThis.TransformStream ? !0 : !!(globalThis.ImageBitmap && e instanceof globalThis.ImageBitmap), h = (e) => {
2
+ const r = [], t = (s) => g(s) ? void 0 : l(s) ? r.push(s) : Array.isArray(s) ? s.map(t) : s && typeof s == "object" ? Object.values(s).map(t) : void 0;
3
+ return t(e), r;
4
+ }, p = "__proxyFunctionPort__", S = (e) => {
5
+ const { port1: r, port2: t } = new MessageChannel();
6
+ return r.addEventListener("message", async (s) => {
7
+ try {
8
+ const n = await e(...s.data), a = i(n), o = h(a);
9
+ r.postMessage({ result: a }, { transfer: o });
10
+ } catch (n) {
11
+ r.postMessage({ error: n });
12
+ }
13
+ }), r.start(), t;
14
+ }, i = (e) => g(e) || l(e) ? e : typeof e == "function" ? { [p]: S(e) } : Array.isArray(e) ? e.map(i) : e && typeof e == "object" ? Object.fromEntries(Object.entries(e).map(([r, t]) => [
15
+ r,
16
+ i(t)
17
+ ])) : e, M = (e) => (...r) => new Promise((t, s) => {
18
+ const n = i(r), a = h(n);
19
+ e.addEventListener("message", (o) => {
20
+ o.data.error ? s(o.data.error) : t(y(o.data.result));
21
+ }), e.start(), e.postMessage(n, { transfer: a });
22
+ }), y = (e) => g(e) || l(e) ? e : e && typeof e == "object" && e[p] ? M(e[p]) : Array.isArray(e) ? e.map(i) : e && typeof e == "object" ? Object.fromEntries(Object.entries(e).map(([r, t]) => [
23
+ r,
24
+ y(t)
25
+ ])) : e, T = (e, { key: r = O } = { key: O }) => (t, s) => new Promise((n, a) => {
26
+ const { port1: o, port2: d } = new MessageChannel();
27
+ o.addEventListener("message", ({ data: b }) => {
28
+ if (b.error)
29
+ a(b.error);
30
+ else {
31
+ const _ = y(b.result);
32
+ n(_);
33
+ }
34
+ o.close(), d.close();
35
+ }, { once: !0 }), o.start();
36
+ const E = i(s), x = h(E);
37
+ e.postMessage({
38
+ source: r,
39
+ type: t,
40
+ data: E,
41
+ port: d
42
+ }, {
43
+ targetOrigin: "*",
44
+ transfer: [d, ...x ?? []]
45
+ });
46
+ });
47
+ let R, f;
48
+ const k = () => (f = new Promise((e, r) => {
49
+ R = e;
50
+ }), f), C = k(), A = async (e) => {
51
+ e === C && k(), R(await e);
52
+ }, F = "https://fkn.app", I = globalThis.window === void 0, c = globalThis.document?.createElement("iframe");
53
+ c && (c.src = `${F}/sandbox-api`, c.style.display = "none", document.body.appendChild(c));
54
+ const m = c, P = m?.contentWindow, B = (e) => A(e), j = () => f, L = async () => T(await j(), { key: "fkn-sandbox-api" })("API_PORT", {});
55
+ if (I) {
56
+ let e = !1;
57
+ f.then(() => {
58
+ e = !0;
59
+ }), setTimeout(() => {
60
+ e || console.warn("@fkn/lib's api target has not resolved after 250ms while in a worker, make sure to call `setApiTarget(messagePort)`");
61
+ }, 250);
62
+ } else {
63
+ if (!m)
64
+ throw new Error("Missing appended iframe");
65
+ m.addEventListener("load", () => {
66
+ const e = setInterval(
67
+ () => T(P, { key: "fkn-sandbox" })("APP_READY", {}).then(() => {
68
+ A(P), clearInterval(e);
69
+ }),
70
+ 10
71
+ );
72
+ });
73
+ }
74
+ const w = (e, r) => j().then(
75
+ (t) => T(t, { key: "fkn-sandbox-api" })(e, r)
76
+ ), Y = async (e, r) => {
77
+ const t = e, s = r, { body: n, ...a } = await w("SERVER_PROXY_FETCH", { input: t, init: s });
78
+ return new Response(
79
+ n,
80
+ {
81
+ ...a,
82
+ headers: {
83
+ ...a.headers,
84
+ ...a.headers && {
85
+ setCookie: a.headers["set-cookie"]
86
+ }
87
+ }
88
+ }
89
+ );
90
+ }, N = async ({ magnet: e, path: r, offset: t, end: s }) => {
91
+ const { body: n, ...a } = await w("TORRENT", { magnet: e, path: r, offset: t, end: s });
92
+ return new Response(
93
+ n,
94
+ {
95
+ ...a,
96
+ headers: Object.fromEntries(a.headers)
97
+ }
98
+ );
99
+ }, u = async ({ magnet: e }) => {
100
+ const { body: r, ...t } = await w("TORRENT_FILE", { magnet: e });
101
+ return new Response(
102
+ r,
103
+ {
104
+ ...t,
105
+ headers: Object.fromEntries(t.headers)
106
+ }
107
+ );
108
+ };
109
+ export {
110
+ Y as E,
111
+ N as P,
112
+ B as b,
113
+ L as k,
114
+ u,
115
+ j as w
116
+ };
package/build/index.html CHANGED
@@ -4,6 +4,8 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Ripple Torrent</title>
7
+ <link rel="shortcut icon" type="image/png" href="/assets/logo.png"/>
8
+ <link rel="manifest" href="/app.webmanifest">
7
9
  </head>
8
10
  <body>
9
11
  <script type="module" src="/index.js"></script>