Merge branch 'dev'
This commit is contained in:
commit
d7fce2eac0
7 changed files with 25 additions and 8 deletions
|
|
@ -2,6 +2,8 @@ NUXT_PUBLIC_PREVIEW_MODE=true
|
||||||
NUXT_PUBLIC_SLUG_DEFAULT_LENGTH=5
|
NUXT_PUBLIC_SLUG_DEFAULT_LENGTH=5
|
||||||
NUXT_SITE_TOKEN=SinkCool
|
NUXT_SITE_TOKEN=SinkCool
|
||||||
NUXT_REDIRECT_STATUS_CODE=308
|
NUXT_REDIRECT_STATUS_CODE=308
|
||||||
|
NUXT_LINK_CACHE_TTL=60
|
||||||
|
NUXT_REDIRECT_WITH_QUERY=false
|
||||||
NUXT_HOME_URL="https://sink.cool"
|
NUXT_HOME_URL="https://sink.cool"
|
||||||
NUXT_CF_ACCOUNT_ID=123456
|
NUXT_CF_ACCOUNT_ID=123456
|
||||||
NUXT_CF_API_TOKEN=CloudflareAPIToken
|
NUXT_CF_API_TOKEN=CloudflareAPIToken
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,14 @@ const route = useRoute()
|
||||||
@update:model-value="navigateTo"
|
@update:model-value="navigateTo"
|
||||||
>
|
>
|
||||||
<TabsList>
|
<TabsList>
|
||||||
<TabsTrigger value="/dashboard">
|
|
||||||
Analysis
|
|
||||||
</TabsTrigger>
|
|
||||||
<TabsTrigger
|
<TabsTrigger
|
||||||
value="/dashboard/links"
|
value="/dashboard/links"
|
||||||
>
|
>
|
||||||
Links
|
Links
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value="/dashboard/analysis">
|
||||||
|
Analysis
|
||||||
|
</TabsTrigger>
|
||||||
</TabsList>
|
</TabsList>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
<slot name="left" />
|
<slot name="left" />
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,14 @@ Sets the default length of the generated SLUG.
|
||||||
|
|
||||||
Redirects default to use HTTP 301 status code, you can set it to `302`/`307`/`308`.
|
Redirects default to use HTTP 301 status code, you can set it to `302`/`307`/`308`.
|
||||||
|
|
||||||
|
## `NUXT_LINK_CACHE_TTL`
|
||||||
|
|
||||||
|
Cache links can speed up access, but setting them too long may result in slow changes taking effect. The default value is 60 seconds.
|
||||||
|
|
||||||
|
## `NUXT_REDIRECT_WITH_QUERY`
|
||||||
|
|
||||||
|
URL parameters are not carried during link redirection by default and it is not recommended to enable this feature.
|
||||||
|
|
||||||
## `NUXT_HOME_URL`
|
## `NUXT_HOME_URL`
|
||||||
|
|
||||||
The default Sink homepage is the introduction page, you can replace it with your own website.
|
The default Sink homepage is the introduction page, you can replace it with your own website.
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ export default defineNuxtConfig({
|
||||||
'/dashboard/**': {
|
'/dashboard/**': {
|
||||||
ssr: false,
|
ssr: false,
|
||||||
},
|
},
|
||||||
|
'/dashboard': {
|
||||||
|
redirect: '/dashboard/links',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
hub: {
|
hub: {
|
||||||
|
|
@ -49,6 +52,8 @@ export default defineNuxtConfig({
|
||||||
runtimeConfig: {
|
runtimeConfig: {
|
||||||
siteToken: 'SinkCool',
|
siteToken: 'SinkCool',
|
||||||
redirectStatusCode: '301',
|
redirectStatusCode: '301',
|
||||||
|
linkCacheTtl: 60,
|
||||||
|
redirectWithQuery: false,
|
||||||
homeURL: '',
|
homeURL: '',
|
||||||
cfAccountId: '',
|
cfAccountId: '',
|
||||||
cfApiToken: '',
|
cfApiToken: '',
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ export default eventHandler(async (event) => {
|
||||||
statusText: 'Link already exists',
|
statusText: 'Link already exists',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
const expiration = getExpiration(event, link.expiration)
|
const expiration = getExpiration(event, link.expiration)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import type { z } from 'zod'
|
import type { z } from 'zod'
|
||||||
import { parsePath } from 'ufo'
|
import { parsePath, withQuery } from 'ufo'
|
||||||
import type { LinkSchema } from '@/schemas/link'
|
import type { LinkSchema } from '@/schemas/link'
|
||||||
|
|
||||||
export default eventHandler(async (event) => {
|
export default eventHandler(async (event) => {
|
||||||
const { pathname: slug } = parsePath(event.path.slice(1)) // remove leading slash
|
const { pathname: slug } = parsePath(event.path.slice(1)) // remove leading slash
|
||||||
const { slugRegex, reserveSlug } = useAppConfig(event)
|
const { slugRegex, reserveSlug } = useAppConfig(event)
|
||||||
const { homeURL } = useRuntimeConfig(event)
|
const { homeURL, linkCacheTtl, redirectWithQuery } = useRuntimeConfig(event)
|
||||||
const { cloudflare } = event.context
|
const { cloudflare } = event.context
|
||||||
|
|
||||||
if (event.path === '/' && homeURL)
|
if (event.path === '/' && homeURL)
|
||||||
|
|
@ -13,7 +13,7 @@ export default eventHandler(async (event) => {
|
||||||
|
|
||||||
if (slug && !reserveSlug.includes(slug) && slugRegex.test(slug) && cloudflare) {
|
if (slug && !reserveSlug.includes(slug) && slugRegex.test(slug) && cloudflare) {
|
||||||
const { KV } = cloudflare.env
|
const { KV } = cloudflare.env
|
||||||
const link: z.infer<typeof LinkSchema> | null = await KV.get(`link:${slug}`, { type: 'json' })
|
const link: z.infer<typeof LinkSchema> | null = await KV.get(`link:${slug}`, { type: 'json', cacheTtl: linkCacheTtl })
|
||||||
if (link) {
|
if (link) {
|
||||||
event.context.link = link
|
event.context.link = link
|
||||||
try {
|
try {
|
||||||
|
|
@ -22,7 +22,8 @@ export default eventHandler(async (event) => {
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error('Failed write access log:', error)
|
console.error('Failed write access log:', error)
|
||||||
}
|
}
|
||||||
return sendRedirect(event, link.url, +useRuntimeConfig(event).redirectStatusCode)
|
const target = redirectWithQuery ? withQuery(link.url, getQuery(event)) : link.url
|
||||||
|
return sendRedirect(event, target, +useRuntimeConfig(event).redirectStatusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue