Formatting
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
"use server"
|
||||
|
||||
import { revalidatePath } from "next/cache"
|
||||
import { getSession } from "../auth/session"
|
||||
import { insertUrl } from "../db/urls"
|
||||
import { advancedUrlSchema, editUrlSchema, urlFormSchema } from "../schema/url"
|
||||
import { deleteUrl as deleteUrlDb, updateUrl as updateUrlDb } from "../db/urls"
|
||||
import { revalidatePath } from "next/cache"
|
||||
import { advancedUrlSchema, editUrlSchema, urlFormSchema } from "../schema/url"
|
||||
import { getWebsiteTitle } from "../websiteTitle"
|
||||
|
||||
type Response = {
|
||||
@@ -68,7 +68,7 @@ export async function createAdvanceUrl(unsafeData: unknown): Promise<Response> {
|
||||
...data,
|
||||
slug: data.slug?.length === 0 ? undefined : data.slug,
|
||||
title: data.title?.length === 0 ? await getWebsiteTitle(data.url) : data.title,
|
||||
maxVisits: data.maxVisits > 0 ? data.maxVisits : undefined,
|
||||
maxVisits: data.maxVisits > 0 ? data.maxVisits : undefined
|
||||
})
|
||||
|
||||
return {
|
||||
@@ -120,4 +120,4 @@ export async function deleteUrl(id: string): Promise<Response> {
|
||||
error: false,
|
||||
message: "Short link deleted successfully!"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { betterAuth } from "better-auth"
|
||||
import { drizzleAdapter } from "better-auth/adapters/drizzle"
|
||||
import { nextCookies } from "better-auth/next-js"
|
||||
import { genericOAuth } from "better-auth/plugins"
|
||||
import { db } from "../drizzle/db"
|
||||
import { env } from "../env/server"
|
||||
import { nextCookies } from "better-auth/next-js"
|
||||
|
||||
export const auth = betterAuth({
|
||||
database: drizzleAdapter(db, {
|
||||
@@ -18,6 +18,6 @@ export const auth = betterAuth({
|
||||
clientSecret: env.AUTHENTIK_CLIENT_SECRET,
|
||||
discoveryUrl: env.AUTHENTIK_DISCOVERY_URL
|
||||
}]
|
||||
}),
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { headers } from "next/headers"
|
||||
import { auth } from "./auth"
|
||||
import { redirect } from "next/navigation"
|
||||
import { auth } from "./auth"
|
||||
|
||||
export async function getSession() {
|
||||
const session = await auth.api.getSession({
|
||||
@@ -11,4 +11,4 @@ export async function getSession() {
|
||||
}
|
||||
|
||||
return { session, redirect: redirectFunc }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eq, desc, count } from "drizzle-orm";
|
||||
import { db } from "../drizzle/db";
|
||||
import { urls, visits } from "../drizzle/schema";
|
||||
import { cacheTag } from "next/dist/server/use-cache/cache-tag";
|
||||
import { revalidateTag } from "next/cache";
|
||||
import { count, desc, eq } from "drizzle-orm"
|
||||
import { revalidateTag } from "next/cache"
|
||||
import { cacheTag } from "next/dist/server/use-cache/cache-tag"
|
||||
import { db } from "../drizzle/db"
|
||||
import { urls, visits } from "../drizzle/schema"
|
||||
|
||||
export async function getAllUrls() {
|
||||
"use cache"
|
||||
@@ -67,4 +67,4 @@ export async function trackVisit(data: typeof visits.$inferInsert) {
|
||||
revalidateTag("visits")
|
||||
|
||||
return await db.insert(visits).values(data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
export function generateRandomSlug(): string {
|
||||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
let result = '';
|
||||
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
let result = ""
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
||||
result += characters.charAt(Math.floor(Math.random() * characters.length))
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { z } from "zod";
|
||||
import { z } from "zod"
|
||||
|
||||
export const urlFormSchema = z.object({
|
||||
url: z.string().url("Please enter a valid URL"),
|
||||
@@ -12,7 +12,7 @@ export const advancedUrlSchema = z.object({
|
||||
maxVisits: z.number().int().positive().nullable(),
|
||||
expDate: z.date().optional(),
|
||||
forwardQueryParams: z.boolean(),
|
||||
crawlable: z.boolean(),
|
||||
crawlable: z.boolean()
|
||||
})
|
||||
|
||||
export const editUrlSchema = z.object({
|
||||
@@ -22,5 +22,5 @@ export const editUrlSchema = z.object({
|
||||
maxVisits: z.number().int().positive().nullable(),
|
||||
expDate: z.date().nullable(),
|
||||
forwardQueryParams: z.boolean(),
|
||||
crawlable: z.boolean(),
|
||||
})
|
||||
crawlable: z.boolean()
|
||||
})
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
export async function getWebsiteTitle(url: string): Promise<string | null> {
|
||||
const res = await fetch(url, { redirect: 'follow' })
|
||||
const res = await fetch(url, { redirect: "follow" })
|
||||
|
||||
if (!res.ok) {
|
||||
return null
|
||||
}
|
||||
|
||||
const contentType = res.headers.get('content-type')
|
||||
if (!contentType || !contentType.includes('text/html')) {
|
||||
const contentType = res.headers.get("content-type")
|
||||
if (!contentType || !contentType.includes("text/html")) {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -16,16 +16,16 @@ export async function getWebsiteTitle(url: string): Promise<string | null> {
|
||||
|
||||
if (titleMatch && titleMatch[1]) {
|
||||
const title = titleMatch[1]
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/&/g, "&")
|
||||
.replace(/"/g, "\"")
|
||||
.replace(/'/g, "'")
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/ /g, " ")
|
||||
.trim()
|
||||
|
||||
return title || null
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user