Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

renamed keys

Steven Tey6fd12f4a3781
diff --git a/lib/middleware/link.ts b/lib/middleware/link.ts
index 5c20edec89..e1374de1ec 100644
--- a/lib/middleware/link.ts
+++ b/lib/middleware/link.ts
@@ -14,8 +14,6 @@ export default async function LinkMiddleware(
) {
const { hostname, key } = parse(req);
- console.log("referer headers is", req.headers.get("referer"));
-
const target = await redis.hget<string>(`${hostname}:links`, key);
if (target) {
ev.waitUntil(
diff --git a/pages/api/edge/links/index.ts b/pages/api/edge/links/index.ts
index 1097d8c238..63f56585e4 100644
--- a/pages/api/edge/links/index.ts
+++ b/pages/api/edge/links/index.ts
@@ -15,7 +15,7 @@ export default async function handler(req: NextRequest) {
const { response, key } = await setRandomKey(url);
if (response === 1) {
// if key was successfully added
- await redis.zadd(`dub.sh:generic:timestamp`, {
+ await redis.zadd(`dub.sh:timestamps:generic`, {
score: Date.now(),
member: key,
});
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index a5b2be75de..978a03f817 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -7,13 +7,17 @@ export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
- // const session = await getSession(req, res);
- // if (!session?.user.id) return res.status(401).end("Unauthorized");
+ const session = await getSession(req, res);
+ if (!session?.user.id) return res.status(401).end("Unauthorized");
- // GET /api/links – get all links associated with the authenticated user
+ // GET /api/links – get all dub.sh links created by the user
if (req.method === "GET") {
- const { hostname } = req.query;
- const response = await redis.hgetall(`${hostname}:links`);
+ const response = await redis.zrange(
+ `dub.sh:timestamps:${session?.user.id}`,
+ 0,
+ -1,
+ { rev: true }
+ );
return res.status(200).json(response);
// POST /api/links – create a new link
@@ -24,7 +28,7 @@ export default async function handler(
}
const pipeline = redis.pipeline();
pipeline.hsetnx(`${hostname}:links`, key, url);
- pipeline.zadd(`${hostname}:links:timestamp`, {
+ pipeline.zadd(`dub.sh:timestamps:${session?.user.id}`, {
score: Date.now(),
member: key,
});
diff --git a/pages/api/projects/[slug]/index.ts b/pages/api/projects/[slug]/index.ts
index 260ebb31e3..251ea30b18 100644
--- a/pages/api/projects/[slug]/index.ts
+++ b/pages/api/projects/[slug]/index.ts
@@ -31,7 +31,7 @@ export default async function handler(
});
if (response) {
const keys = await redis.zrange<string[]>(
- `${slug}:links:timestamps`,
+ `${slug}:timestamps:links`,
0,
-1,
{
diff --git a/pages/api/projects/[slug]/links/index.ts b/pages/api/projects/[slug]/links/index.ts
index 6f377943c7..d5698d601a 100644
--- a/pages/api/projects/[slug]/links/index.ts
+++ b/pages/api/projects/[slug]/links/index.ts
@@ -37,7 +37,7 @@ export default async function handler(
}
const pipeline = redis.pipeline();
pipeline.hsetnx(`${hostname}:links`, key, url);
- pipeline.zadd(`${hostname}:links:timestamp`, {
+ pipeline.zadd(`${hostname}:timestamps:links`, {
score: Date.now(),
member: key,
});