@hasna/shortlinks 0.1.6 → 0.1.7

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/cli/index.js CHANGED
@@ -3128,13 +3128,23 @@ function createShortlinksHandler(options = {}) {
3128
3128
  if (url.pathname === "/" || url.pathname === "") {
3129
3129
  return json({ service: "shortlinks", ok: true });
3130
3130
  }
3131
- const slug = decodeURIComponent(url.pathname.replace(/^\/+/, "").split("/")[0] || "");
3131
+ let slug = "";
3132
+ try {
3133
+ slug = decodeURIComponent(url.pathname.replace(/^\/+/, "").split("/")[0] || "");
3134
+ } catch {
3135
+ return json({ error: "Invalid slug." }, 400);
3136
+ }
3132
3137
  if (!slug)
3133
3138
  return json({ error: "Missing slug." }, 404);
3134
3139
  const host = getHost(request, options.defaultHost);
3135
3140
  if (!host)
3136
3141
  return json({ error: "Missing Host header." }, 400);
3137
- const link = store.resolve(host, slug);
3142
+ let link = null;
3143
+ try {
3144
+ link = store.resolve(host, slug);
3145
+ } catch {
3146
+ return json({ error: "Shortlink not found.", slug, host }, 404);
3147
+ }
3138
3148
  if (!link)
3139
3149
  return json({ error: "Shortlink not found.", slug, host }, 404);
3140
3150
  if (!link.active)
package/dist/index.js CHANGED
@@ -561,13 +561,23 @@ function createShortlinksHandler(options = {}) {
561
561
  if (url.pathname === "/" || url.pathname === "") {
562
562
  return json({ service: "shortlinks", ok: true });
563
563
  }
564
- const slug = decodeURIComponent(url.pathname.replace(/^\/+/, "").split("/")[0] || "");
564
+ let slug = "";
565
+ try {
566
+ slug = decodeURIComponent(url.pathname.replace(/^\/+/, "").split("/")[0] || "");
567
+ } catch {
568
+ return json({ error: "Invalid slug." }, 400);
569
+ }
565
570
  if (!slug)
566
571
  return json({ error: "Missing slug." }, 404);
567
572
  const host = getHost(request, options.defaultHost);
568
573
  if (!host)
569
574
  return json({ error: "Missing Host header." }, 400);
570
- const link = store.resolve(host, slug);
575
+ let link = null;
576
+ try {
577
+ link = store.resolve(host, slug);
578
+ } catch {
579
+ return json({ error: "Shortlink not found.", slug, host }, 404);
580
+ }
571
581
  if (!link)
572
582
  return json({ error: "Shortlink not found.", slug, host }, 404);
573
583
  if (!link.active)
package/dist/server.js CHANGED
@@ -563,13 +563,23 @@ function createShortlinksHandler(options = {}) {
563
563
  if (url.pathname === "/" || url.pathname === "") {
564
564
  return json({ service: "shortlinks", ok: true });
565
565
  }
566
- const slug = decodeURIComponent(url.pathname.replace(/^\/+/, "").split("/")[0] || "");
566
+ let slug = "";
567
+ try {
568
+ slug = decodeURIComponent(url.pathname.replace(/^\/+/, "").split("/")[0] || "");
569
+ } catch {
570
+ return json({ error: "Invalid slug." }, 400);
571
+ }
567
572
  if (!slug)
568
573
  return json({ error: "Missing slug." }, 404);
569
574
  const host = getHost(request, options.defaultHost);
570
575
  if (!host)
571
576
  return json({ error: "Missing Host header." }, 400);
572
- const link = store.resolve(host, slug);
577
+ let link = null;
578
+ try {
579
+ link = store.resolve(host, slug);
580
+ } catch {
581
+ return json({ error: "Shortlink not found.", slug, host }, 404);
582
+ }
573
583
  if (!link)
574
584
  return json({ error: "Shortlink not found.", slug, host }, 404);
575
585
  if (!link.active)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/shortlinks",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "CLI-only shortlink manager for custom domains, click tracking, Cloudflare setup, and @hasna cloud sync",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",