loophole-im 0.1.4 → 0.1.6

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.
@@ -121,19 +121,39 @@ async function downloadBinary(suffix) {
121
121
  await downloadFile(binaryUrl, dest, { ...headers, Accept: "application/octet-stream" });
122
122
  await downloadFile(shaUrl, shaDest, headers);
123
123
  } else {
124
- // public mode — R2 (releases.loophole.im) — no GH_TOKEN needed, repo can stay private
124
+ // public mode — R2 (releases.loophole.im) — no GH_TOKEN needed, repo can stay private.
125
+ // Only the last two version prefixes are kept (10 GB free tier); fall back to latest.json.
125
126
  const r2Base = "https://releases.loophole.im";
126
- const base = version && version !== "0.0.0" && version !== "0.0.0-dev"
127
- ? `${r2Base}/v${version}`
128
- : `${r2Base}/v0.1.0`;
129
- binaryUrl = `${base}/${name}`;
130
- shaUrl = `${base}/SHA256SUMS`;
127
+ const bases = [];
128
+ if (version && version !== "0.0.0" && version !== "0.0.0-dev") {
129
+ bases.push(`${r2Base}/v${version}`);
130
+ }
131
131
  try {
132
- await downloadFile(binaryUrl, dest, {});
133
- await downloadFile(shaUrl, shaDest, {});
134
- } catch (e) {
135
- console.error(`could not download ${name} from ${binaryUrl}: ${e.message}`);
136
- console.error(` check https://releases.loophole.im/v${version}/ — or set GH_TOKEN to fallback to GitHub API`);
132
+ const meta = await fetch(`${r2Base}/latest.json`).then((r) => {
133
+ if (!r.ok) throw new Error(`latest.json ${r.status}`);
134
+ return r.json();
135
+ });
136
+ if (meta?.tag) bases.push(`${r2Base}/${meta.tag}`);
137
+ } catch {
138
+ /* latest.json missing — versioned URL may still work */
139
+ }
140
+ let lastErr;
141
+ let ok = false;
142
+ for (const base of [...new Set(bases)]) {
143
+ binaryUrl = `${base}/${name}`;
144
+ shaUrl = `${base}/SHA256SUMS`;
145
+ try {
146
+ await downloadFile(binaryUrl, dest, {});
147
+ await downloadFile(shaUrl, shaDest, {});
148
+ ok = true;
149
+ break;
150
+ } catch (e) {
151
+ lastErr = e;
152
+ }
153
+ }
154
+ if (!ok) {
155
+ console.error(`could not download ${name}: ${lastErr?.message ?? "no R2 prefix resolved"}`);
156
+ console.error(` check https://releases.loophole.im/latest.json — or set GH_TOKEN to fallback to GitHub API`);
137
157
  process.exit(1);
138
158
  }
139
159
  }
package/bin/loophole.js CHANGED
@@ -121,19 +121,39 @@ async function downloadBinary(suffix) {
121
121
  await downloadFile(binaryUrl, dest, { ...headers, Accept: "application/octet-stream" });
122
122
  await downloadFile(shaUrl, shaDest, headers);
123
123
  } else {
124
- // public mode — R2 (releases.loophole.im) — no GH_TOKEN needed, repo can stay private
124
+ // public mode — R2 (releases.loophole.im) — no GH_TOKEN needed, repo can stay private.
125
+ // Only the last two version prefixes are kept (10 GB free tier); fall back to latest.json.
125
126
  const r2Base = "https://releases.loophole.im";
126
- const base = version && version !== "0.0.0" && version !== "0.0.0-dev"
127
- ? `${r2Base}/v${version}`
128
- : `${r2Base}/v0.1.0`;
129
- binaryUrl = `${base}/${name}`;
130
- shaUrl = `${base}/SHA256SUMS`;
127
+ const bases = [];
128
+ if (version && version !== "0.0.0" && version !== "0.0.0-dev") {
129
+ bases.push(`${r2Base}/v${version}`);
130
+ }
131
131
  try {
132
- await downloadFile(binaryUrl, dest, {});
133
- await downloadFile(shaUrl, shaDest, {});
134
- } catch (e) {
135
- console.error(`could not download ${name} from ${binaryUrl}: ${e.message}`);
136
- console.error(` check https://releases.loophole.im/v${version}/ — or set GH_TOKEN to fallback to GitHub API`);
132
+ const meta = await fetch(`${r2Base}/latest.json`).then((r) => {
133
+ if (!r.ok) throw new Error(`latest.json ${r.status}`);
134
+ return r.json();
135
+ });
136
+ if (meta?.tag) bases.push(`${r2Base}/${meta.tag}`);
137
+ } catch {
138
+ /* latest.json missing — versioned URL may still work */
139
+ }
140
+ let lastErr;
141
+ let ok = false;
142
+ for (const base of [...new Set(bases)]) {
143
+ binaryUrl = `${base}/${name}`;
144
+ shaUrl = `${base}/SHA256SUMS`;
145
+ try {
146
+ await downloadFile(binaryUrl, dest, {});
147
+ await downloadFile(shaUrl, shaDest, {});
148
+ ok = true;
149
+ break;
150
+ } catch (e) {
151
+ lastErr = e;
152
+ }
153
+ }
154
+ if (!ok) {
155
+ console.error(`could not download ${name}: ${lastErr?.message ?? "no R2 prefix resolved"}`);
156
+ console.error(` check https://releases.loophole.im/latest.json — or set GH_TOKEN to fallback to GitHub API`);
137
157
  process.exit(1);
138
158
  }
139
159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loophole-im",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "private": false,
5
5
  "description": "Tunnel local web apps so they're reachable from any signed-in instance — private Cloudflare Tunnels",
6
6
  "license": "MIT",