Skip to content

Commit d7fce2e

Browse files
committed
Merge branch 'dev'
2 parents 0d10da9 + 52187d1 commit d7fce2e

File tree

7 files changed

+25
-8
lines changed

7 files changed

+25
-8
lines changed

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ NUXT_PUBLIC_PREVIEW_MODE=true
22
NUXT_PUBLIC_SLUG_DEFAULT_LENGTH=5
33
NUXT_SITE_TOKEN=SinkCool
44
NUXT_REDIRECT_STATUS_CODE=308
5+
NUXT_LINK_CACHE_TTL=60
6+
NUXT_REDIRECT_WITH_QUERY=false
57
NUXT_HOME_URL="https://sink.cool"
68
NUXT_CF_ACCOUNT_ID=123456
79
NUXT_CF_API_TOKEN=CloudflareAPIToken

components/dashboard/Nav.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ const route = useRoute()
1010
@update:model-value="navigateTo"
1111
>
1212
<TabsList>
13-
<TabsTrigger value="/dashboard">
14-
Analysis
15-
</TabsTrigger>
1613
<TabsTrigger
1714
value="/dashboard/links"
1815
>
1916
Links
2017
</TabsTrigger>
18+
<TabsTrigger value="/dashboard/analysis">
19+
Analysis
20+
</TabsTrigger>
2121
</TabsList>
2222
</Tabs>
2323
<slot name="left" />

docs/configuration.md

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ Sets the default length of the generated SLUG.
1414

1515
Redirects default to use HTTP 301 status code, you can set it to `302`/`307`/`308`.
1616

17+
## `NUXT_LINK_CACHE_TTL`
18+
19+
Cache links can speed up access, but setting them too long may result in slow changes taking effect. The default value is 60 seconds.
20+
21+
## `NUXT_REDIRECT_WITH_QUERY`
22+
23+
URL parameters are not carried during link redirection by default and it is not recommended to enable this feature.
24+
1725
## `NUXT_HOME_URL`
1826

1927
The default Sink homepage is the introduction page, you can replace it with your own website.

nuxt.config.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export default defineNuxtConfig({
2121
'/dashboard/**': {
2222
ssr: false,
2323
},
24+
'/dashboard': {
25+
redirect: '/dashboard/links',
26+
},
2427
},
2528

2629
hub: {
@@ -49,6 +52,8 @@ export default defineNuxtConfig({
4952
runtimeConfig: {
5053
siteToken: 'SinkCool',
5154
redirectStatusCode: '301',
55+
linkCacheTtl: 60,
56+
redirectWithQuery: false,
5257
homeURL: '',
5358
cfAccountId: '',
5459
cfApiToken: '',
@@ -62,4 +67,4 @@ export default defineNuxtConfig({
6267
},
6368

6469
compatibilityDate: '2024-07-08',
65-
})
70+
})
File renamed without changes.

server/api/link/create.post.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default eventHandler(async (event) => {
1212
statusText: 'Link already exists',
1313
})
1414
}
15+
1516
else {
1617
const expiration = getExpiration(event, link.expiration)
1718

server/middleware/1.redirect.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import type { z } from 'zod'
2-
import { parsePath } from 'ufo'
2+
import { parsePath, withQuery } from 'ufo'
33
import type { LinkSchema } from '@/schemas/link'
44

55
export default eventHandler(async (event) => {
66
const { pathname: slug } = parsePath(event.path.slice(1)) // remove leading slash
77
const { slugRegex, reserveSlug } = useAppConfig(event)
8-
const { homeURL } = useRuntimeConfig(event)
8+
const { homeURL, linkCacheTtl, redirectWithQuery } = useRuntimeConfig(event)
99
const { cloudflare } = event.context
1010

1111
if (event.path === '/' && homeURL)
1212
return sendRedirect(event, homeURL)
1313

1414
if (slug && !reserveSlug.includes(slug) && slugRegex.test(slug) && cloudflare) {
1515
const { KV } = cloudflare.env
16-
const link: z.infer<typeof LinkSchema> | null = await KV.get(`link:${slug}`, { type: 'json' })
16+
const link: z.infer<typeof LinkSchema> | null = await KV.get(`link:${slug}`, { type: 'json', cacheTtl: linkCacheTtl })
1717
if (link) {
1818
event.context.link = link
1919
try {
@@ -22,7 +22,8 @@ export default eventHandler(async (event) => {
2222
catch (error) {
2323
console.error('Failed write access log:', error)
2424
}
25-
return sendRedirect(event, link.url, +useRuntimeConfig(event).redirectStatusCode)
25+
const target = redirectWithQuery ? withQuery(link.url, getQuery(event)) : link.url
26+
return sendRedirect(event, target, +useRuntimeConfig(event).redirectStatusCode)
2627
}
2728
}
2829
})

0 commit comments

Comments
 (0)