Oouhammmourachid /
Public
ouhammmourachid / link-shortener
PublicShort links with custom or random codes, click counts, visit logs, expiry dates, and redirects at /s/{code}.
- Other
- 1 deploy
- 0 forks
Link Shortener with click tracking
Short links with custom or random codes, click counts, visit logs, expiry dates, and redirects at /s/{code}.
What you get
GET /s/{code}redirects (302) and counts the click atomically- Random 7-character codes, or choose your own
- Each visit is logged with its referrer and user agent
- Links can expire (410 Gone) or be disabled
- Each user sees only their own links and stats
Collections
links
| Field | Type | Notes |
|---|---|---|
code | text | Random if empty; 3-32 chars of A-Z a-z 0-9 _ - |
url (required) | url | Where the link goes |
title | text | |
owner (required) | relation → users | Set by a hook to the signed-in user |
clicks | number | Kept by the server |
disabled | bool | Stop redirecting |
expires_at | date | Optional expiry |
| Action | Who can do it |
|---|---|
| List / view | owner = @request.auth.id |
| Create | signed-in users |
| Update | owner = @request.auth.id |
| Delete | owner = @request.auth.id |
visits
Written by the redirect route only.
| Field | Type | Notes |
|---|---|---|
link (required) | relation → links | |
referrer | text | |
user_agent | text |
| Action | Who can do it |
|---|---|
| List / view | link.owner = @request.auth.id |
| Create | superusers only |
| Update | superusers only |
| Delete | link.owner = @request.auth.id |
Hooks
All hooks are in pb_hooks/main.pb.js and commented.
Quick start
import PocketBase from "pocketbase"
const pb = new PocketBase("https://YOUR-INSTANCE.pocketshub.com")
const link = await pb.collection("links").create({ url: "https://example.com/very/long/path" })
console.log(`${pb.baseURL}/s/${link.code}`)
// Visits over the last 7 days:
const since = new Date(Date.now() - 7 * 864e5).toISOString().replace("T", " ")
const visits = await pb.collection("visits").getFullList({
filter: `link = "${link.id}" && created >= "${since}"`,
})
Notes
- Point a short custom domain at the instance (Starter or Pro plan) for links like
go.example.com/s/abc123.
License
MIT
2 collections, 1 relation. Hover a collection to trace its relations