chore: format
This commit is contained in:
parent
c8338e5516
commit
527139f298
33 changed files with 848 additions and 3132 deletions
|
@ -1,16 +0,0 @@
|
||||||
# https://mcr.microsoft.com/en-us/product/devcontainers/typescript-node/about
|
|
||||||
FROM mcr.microsoft.com/devcontainers/typescript-node:20-bookworm
|
|
||||||
|
|
||||||
RUN apt-get update && \
|
|
||||||
apt-get install build-essential xz-utils
|
|
||||||
|
|
||||||
# RUN LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+') && \
|
|
||||||
# curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz" && \
|
|
||||||
# sudo tar xf lazygit.tar.gz -C /usr/local/bin lazygit && \
|
|
||||||
# rm -rf lazygit.tar.gz
|
|
||||||
|
|
||||||
# RUN BTOP_VERSION=$(curl -s "https://api.github.com/repos/aristocratos/btop/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+') && \
|
|
||||||
# wget "https://github.com/aristocratos/btop/releases/download/v${BTOP_VERSION}/btop-x86_64-linux-musl.tbz" && \
|
|
||||||
# sudo tar -xvf btop-x86_64-linux-musl.tbz && \
|
|
||||||
# cd btop && ./install.sh && cd .. && \
|
|
||||||
# rm -rf btop-x86_64-linux-musl.tbz btop
|
|
|
@ -1,60 +0,0 @@
|
||||||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
|
||||||
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
|
|
||||||
{
|
|
||||||
"name": "Node.js & TypeScript",
|
|
||||||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
|
||||||
// "image": "mcr.microsoft.com/devcontainers/typescript-node:0-20",
|
|
||||||
"build": {
|
|
||||||
// Path is relataive to the devcontainer.json file.
|
|
||||||
"dockerfile": "Dockerfile"
|
|
||||||
},
|
|
||||||
// https://github.com/microsoft/vscode-remote-release/issues/2485#issuecomment-1156342780
|
|
||||||
"runArgs": [
|
|
||||||
"--name",
|
|
||||||
"devcontainer-${containerWorkspaceFolderBasename}"
|
|
||||||
],
|
|
||||||
"initializeCommand": "docker rm -f devcontainer-${containerWorkspaceFolderBasename} || true",
|
|
||||||
// Features to add to the dev container. More info: https://containers.dev/features.
|
|
||||||
"features": {
|
|
||||||
"ghcr.io/devcontainers/features/git:1": {},
|
|
||||||
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
|
|
||||||
"ghcr.io/devcontainers/features/nix:1": {
|
|
||||||
"packages": [
|
|
||||||
"btop",
|
|
||||||
"lazygit",
|
|
||||||
"nixpkgs-fmt"
|
|
||||||
],
|
|
||||||
"extraNixConfig": "experimental-features = nix-command flakes"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
|
||||||
// "forwardPorts": [],
|
|
||||||
// Use 'postCreateCommand' to run commands after the container is created.
|
|
||||||
// "postCreateCommand": "yarn install",
|
|
||||||
"postAttachCommand": {
|
|
||||||
"AddGitSafeDir": "git config --global --add safe.directory /workspaces/${containerWorkspaceFolderBasename}"
|
|
||||||
},
|
|
||||||
"onCreateCommand": {
|
|
||||||
"nix-shell": "nix-shell --command 'echo done install packages'"
|
|
||||||
},
|
|
||||||
// Configure tool-specific properties.
|
|
||||||
// "customizations": {},
|
|
||||||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
|
||||||
"remoteUser": "root",
|
|
||||||
"customizations": {
|
|
||||||
"vscode": {
|
|
||||||
"extensions": [
|
|
||||||
"mutantdino.resourcemonitor",
|
|
||||||
"christian-kohler.path-intellisense",
|
|
||||||
"Gruntfuggly.todo-tree",
|
|
||||||
"ms-azuretools.vscode-docker",
|
|
||||||
"redhat.vscode-yaml",
|
|
||||||
"bradlc.vscode-tailwindcss",
|
|
||||||
"ms-vscode.vscode-typescript-next",
|
|
||||||
"esbenp.prettier-vscode",
|
|
||||||
"GitHub.copilot",
|
|
||||||
"GitHub.copilot-chat"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"extends": "next/core-web-vitals"
|
|
||||||
}
|
|
36
biome.json
Normal file
36
biome.json
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
|
||||||
|
"vcs": {
|
||||||
|
"enabled": false,
|
||||||
|
"clientKind": "git",
|
||||||
|
"useIgnoreFile": false
|
||||||
|
},
|
||||||
|
"files": {
|
||||||
|
"ignoreUnknown": false,
|
||||||
|
"ignore": [".next", "./src/components/ui"]
|
||||||
|
},
|
||||||
|
"formatter": {
|
||||||
|
"enabled": true,
|
||||||
|
"indentStyle": "tab"
|
||||||
|
},
|
||||||
|
"organizeImports": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"linter": {
|
||||||
|
"enabled": true,
|
||||||
|
"rules": {
|
||||||
|
"recommended": true,
|
||||||
|
"complexity": { "noForEach": "off", "noBannedTypes": "off" },
|
||||||
|
"suspicious": {
|
||||||
|
"noShadowRestrictedNames": "off",
|
||||||
|
"noExplicitAny": "off",
|
||||||
|
"noArrayIndexKey": "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"javascript": {
|
||||||
|
"formatter": {
|
||||||
|
"quoteStyle": "double"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
output: "standalone",
|
output: "standalone",
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = nextConfig
|
module.exports = nextConfig;
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
"dev": "next dev --turbo",
|
"dev": "next dev --turbo",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "next lint"
|
"fix": "biome check . --write",
|
||||||
|
"check": "biome check ."
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hookform/resolvers": "^3.10.0",
|
"@hookform/resolvers": "^3.10.0",
|
||||||
|
@ -34,16 +35,13 @@
|
||||||
"zod": "^3.24.2"
|
"zod": "^3.24.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@biomejs/biome": "1.9.4",
|
||||||
"@types/node": "^22.13.9",
|
"@types/node": "^22.13.9",
|
||||||
"@types/prop-types": "^15.7.14",
|
"@types/prop-types": "^15.7.14",
|
||||||
"@types/react": "^18.3.18",
|
"@types/react": "^18.3.18",
|
||||||
"@types/react-dom": "^18.3.5",
|
"@types/react-dom": "^18.3.5",
|
||||||
"autoprefixer": "^10.4.20",
|
"autoprefixer": "^10.4.20",
|
||||||
"eslint": "^8.57.1",
|
|
||||||
"eslint-config-next": "14.2.5",
|
|
||||||
"postcss": "^8.5.3",
|
"postcss": "^8.5.3",
|
||||||
"prettier": "^3.5.3",
|
|
||||||
"prettier-plugin-tailwindcss": "^0.6.11",
|
|
||||||
"tailwindcss": "^3.4.17",
|
"tailwindcss": "^3.4.17",
|
||||||
"typescript": "^5.8.2"
|
"typescript": "^5.8.2"
|
||||||
}
|
}
|
||||||
|
|
2401
pnpm-lock.yaml
generated
2401
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
|
@ -3,4 +3,4 @@ module.exports = {
|
||||||
tailwindcss: {},
|
tailwindcss: {},
|
||||||
autoprefixer: {},
|
autoprefixer: {},
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
{ pkgs ? import <nixpkgs> {} }:
|
|
||||||
pkgs.mkShell {
|
|
||||||
packages = with pkgs; [
|
|
||||||
git
|
|
||||||
btop
|
|
||||||
lazygit
|
|
||||||
micro
|
|
||||||
];
|
|
||||||
}
|
|
|
@ -1,21 +1,27 @@
|
||||||
"use server";
|
"use server";
|
||||||
import { initConnectionPostgres, initConnectionSurreal } from "@/components/db-utils";
|
import {
|
||||||
|
initConnectionPostgres,
|
||||||
|
initConnectionSurreal,
|
||||||
|
} from "@/components/db-utils";
|
||||||
|
|
||||||
export async function querydb(slug: string) {
|
export async function querydb(slug: string) {
|
||||||
let long_url = undefined;
|
let long_url = undefined;
|
||||||
try {
|
try {
|
||||||
if (process.env.DB_TYPE === "surrealdb") {
|
if (process.env.DB_TYPE === "surrealdb") {
|
||||||
let db = await initConnectionSurreal();
|
const db = await initConnectionSurreal();
|
||||||
long_url = await db.query(`
|
long_url = await db.query(
|
||||||
|
`
|
||||||
update url:[$id]
|
update url:[$id]
|
||||||
set clicks +=1;
|
set clicks +=1;
|
||||||
`, { id: slug });
|
`,
|
||||||
|
{ id: slug },
|
||||||
|
);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
long_url = long_url[0][0].long_url;
|
long_url = long_url[0][0].long_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.DB_TYPE === "postgres") {
|
if (process.env.DB_TYPE === "postgres") {
|
||||||
let sql = await initConnectionPostgres();
|
const sql = await initConnectionPostgres();
|
||||||
long_url = await sql`
|
long_url = await sql`
|
||||||
update url set
|
update url set
|
||||||
clicks = clicks + 1,
|
clicks = clicks + 1,
|
||||||
|
|
|
@ -3,12 +3,12 @@ import { notFound, redirect } from "next/navigation";
|
||||||
import { querydb } from "./db";
|
import { querydb } from "./db";
|
||||||
|
|
||||||
export default async function Page({ params }: { params: { slug: string } }) {
|
export default async function Page({ params }: { params: { slug: string } }) {
|
||||||
if (params.slug == "favicon.ico") {
|
if (params.slug === "favicon.ico") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let long_url = await querydb(params.slug);
|
const long_url = await querydb(params.slug);
|
||||||
if (long_url == undefined) {
|
if (long_url === undefined) {
|
||||||
return notFound();
|
return notFound();
|
||||||
}
|
}
|
||||||
redirect(`https://${long_url}`);
|
redirect(`https://${long_url}`);
|
||||||
|
|
|
@ -5,7 +5,7 @@ import {
|
||||||
CardContent,
|
CardContent,
|
||||||
CardFooter,
|
CardFooter,
|
||||||
CardHeader,
|
CardHeader,
|
||||||
CardTitle
|
CardTitle,
|
||||||
} from "@/components/ui/card";
|
} from "@/components/ui/card";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
|
@ -13,7 +13,7 @@ import {
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import {
|
import {
|
||||||
|
@ -25,17 +25,17 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { CopyIcon } from "@radix-ui/react-icons";
|
import { CopyIcon } from "@radix-ui/react-icons";
|
||||||
import { useFormState } from "react-dom";
|
import { useFormState } from "react-dom";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { z } from "zod";
|
import type { z } from "zod";
|
||||||
import { querydb } from "./db";
|
import { querydb } from "./db";
|
||||||
import { formSchema } from "./schema";
|
import { formSchema } from "./schema";
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
url: null,
|
url: null,
|
||||||
}
|
};
|
||||||
|
|
||||||
export default function CreateCard() {
|
export default function CreateCard() {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
let [state, formAction] = useFormState(querydb, initialState);
|
const [state, formAction] = useFormState(querydb, initialState);
|
||||||
|
|
||||||
const form = useForm<z.infer<typeof formSchema>>({
|
const form = useForm<z.infer<typeof formSchema>>({
|
||||||
resolver: zodResolver(formSchema),
|
resolver: zodResolver(formSchema),
|
||||||
|
@ -59,9 +59,8 @@ export default function CreateCard() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
navigator.clipboard.writeText(url)
|
navigator.clipboard.writeText(url).catch((err) => {
|
||||||
.catch(err => {
|
console.error("Failed to copy URL to clipboard:", err);
|
||||||
console.error('Failed to copy URL to clipboard:', err);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -95,7 +94,9 @@ export default function CreateCard() {
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|
||||||
<CardFooter className="flex flex-row gap-4">
|
<CardFooter className="flex flex-row gap-4">
|
||||||
<Button type="submit" form="url_form">Submit</Button>
|
<Button type="submit" form="url_form">
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
{state && state.url && (
|
{state && state.url && (
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger>
|
<PopoverTrigger>
|
||||||
|
@ -104,9 +105,7 @@ export default function CreateCard() {
|
||||||
</Button>
|
</Button>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent>
|
<PopoverContent>
|
||||||
<p className="text-lg">
|
<p className="text-lg">Url added to clipboard</p>
|
||||||
Url added to clipboard
|
|
||||||
</p>
|
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
"use server";
|
"use server";
|
||||||
import { initConnectionPostgres, initConnectionSurreal } from "@/components/db-utils";
|
import {
|
||||||
|
initConnectionPostgres,
|
||||||
|
initConnectionSurreal,
|
||||||
|
} from "@/components/db-utils";
|
||||||
import { formSchema } from "./schema";
|
import { formSchema } from "./schema";
|
||||||
|
|
||||||
function generateRandomString(length: number) {
|
function generateRandomString(length: number) {
|
||||||
const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
const charset =
|
||||||
let randomString = '';
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
let randomString = "";
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
const randomIndex = Math.floor(Math.random() * charset.length);
|
const randomIndex = Math.floor(Math.random() * charset.length);
|
||||||
randomString += charset[randomIndex];
|
randomString += charset[randomIndex];
|
||||||
|
@ -13,34 +17,37 @@ function generateRandomString(length: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function querydb(prevState: any, formData: FormData) {
|
export async function querydb(prevState: any, formData: FormData) {
|
||||||
const values = formSchema.safeParse(formData)
|
const values = formSchema.safeParse(formData);
|
||||||
if (!values.success) {
|
if (!values.success) {
|
||||||
return { error: values.error };
|
return { error: values.error };
|
||||||
}
|
}
|
||||||
let long_url = values.data.url.replace("https://", "").replace("http://", "");
|
let long_url = values.data.url.replace("https://", "").replace("http://", "");
|
||||||
long_url = long_url.endsWith('/') ? long_url.slice(0, -1) : long_url;
|
long_url = long_url.endsWith("/") ? long_url.slice(0, -1) : long_url;
|
||||||
let url = undefined;
|
let url = undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (process.env.DB_TYPE === "surrealdb") {
|
if (process.env.DB_TYPE === "surrealdb") {
|
||||||
let db = await initConnectionSurreal();
|
const db = await initConnectionSurreal();
|
||||||
url = await db.query(`
|
url = await db.query(
|
||||||
|
`
|
||||||
create url:[rand::string(8)] CONTENT {
|
create url:[rand::string(8)] CONTENT {
|
||||||
long_url: $long_url,
|
long_url: $long_url,
|
||||||
clicks: 0,
|
clicks: 0,
|
||||||
date_added: time::now(),
|
date_added: time::now(),
|
||||||
date_accessed: <future> { time::now() }
|
date_accessed: <future> { time::now() }
|
||||||
} return id[0];
|
} return id[0];
|
||||||
`, {
|
`,
|
||||||
long_url: long_url
|
{
|
||||||
});
|
long_url: long_url,
|
||||||
|
},
|
||||||
|
);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
url = url[0][0].id;
|
url = url[0][0].id;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(long_url);
|
console.log(long_url);
|
||||||
if (process.env.DB_TYPE === "postgres") {
|
if (process.env.DB_TYPE === "postgres") {
|
||||||
let sql = await initConnectionPostgres();
|
const sql = await initConnectionPostgres();
|
||||||
await sql`
|
await sql`
|
||||||
create table if not exists url (
|
create table if not exists url (
|
||||||
id text primary key,
|
id text primary key,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
export const formSchema = z.object({
|
export const formSchema = z.object({
|
||||||
url: z.string().min(4,
|
url: z
|
||||||
{ message: "The URL must be at least 4 characters long" }
|
.string()
|
||||||
).max(100
|
.min(4, { message: "The URL must be at least 4 characters long" })
|
||||||
, { message: "The URL must be at most 100 characters long" }),
|
.max(100, { message: "The URL must be at most 100 characters long" }),
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,21 +1,19 @@
|
||||||
"use client";
|
"use client";
|
||||||
import CardGrid from "@/components/card-grid";
|
import CardGrid from "@/components/card-grid";
|
||||||
import {
|
import { Card, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
Card,
|
|
||||||
CardHeader,
|
|
||||||
CardTitle
|
|
||||||
} from "@/components/ui/card";
|
|
||||||
|
|
||||||
export default function GlobalError({
|
export default function GlobalError({
|
||||||
error,
|
error,
|
||||||
}: {
|
}: {
|
||||||
error: Error & { digest?: string }
|
error: Error & { digest?: string };
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<CardGrid maxCols={1}>
|
<CardGrid maxCols={1}>
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-center text-2xl text-red-400">Error + {String(error)}</CardTitle>
|
<CardTitle className="text-center text-2xl text-red-400">
|
||||||
|
Error + {String(error)}
|
||||||
|
</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
</Card>
|
</Card>
|
||||||
</CardGrid>
|
</CardGrid>
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
"use client";
|
"use client";
|
||||||
import CardGrid from "@/components/card-grid";
|
import CardGrid from "@/components/card-grid";
|
||||||
import {
|
import { Card, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
Card,
|
|
||||||
CardHeader,
|
|
||||||
CardTitle
|
|
||||||
} from "@/components/ui/card";
|
|
||||||
|
|
||||||
export default function NotFound() {
|
export default function NotFound() {
|
||||||
return (
|
return (
|
||||||
<CardGrid maxCols={1}>
|
<CardGrid maxCols={1}>
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-center text-2xl text-red-400">404 - Not Found</CardTitle>
|
<CardTitle className="text-center text-2xl text-red-400">
|
||||||
|
404 - Not Found
|
||||||
|
</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
</Card>
|
</Card>
|
||||||
</CardGrid>
|
</CardGrid>
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
"use client";
|
"use client";
|
||||||
import CardGrid from "@/components/card-grid";
|
import CardGrid from "@/components/card-grid";
|
||||||
import {
|
import { Card, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
Card,
|
|
||||||
CardHeader,
|
|
||||||
CardTitle
|
|
||||||
} from "@/components/ui/card";
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import CreateCard from "./create/create";
|
import CreateCard from "./create/create";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"use client";
|
"use client";
|
||||||
import { ColumnDef } from "@tanstack/react-table";
|
import type { ColumnDef } from "@tanstack/react-table";
|
||||||
|
|
||||||
export type UrlTable = {
|
export type UrlTable = {
|
||||||
clicks: number;
|
clicks: number;
|
||||||
|
|
|
@ -8,10 +8,10 @@ import {
|
||||||
TableRow,
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import {
|
import {
|
||||||
ColumnDef,
|
type ColumnDef,
|
||||||
flexRender,
|
flexRender,
|
||||||
getCoreRowModel,
|
getCoreRowModel,
|
||||||
useReactTable
|
useReactTable,
|
||||||
} from "@tanstack/react-table";
|
} from "@tanstack/react-table";
|
||||||
|
|
||||||
interface DataTableProps<TData, TValue> {
|
interface DataTableProps<TData, TValue> {
|
||||||
|
@ -43,10 +43,10 @@ export function DataTable<TData, TValue>({
|
||||||
? null
|
? null
|
||||||
: flexRender(
|
: flexRender(
|
||||||
header.column.columnDef.header,
|
header.column.columnDef.header,
|
||||||
header.getContext()
|
header.getContext(),
|
||||||
)}
|
)}
|
||||||
</TableHead>
|
</TableHead>
|
||||||
)
|
);
|
||||||
})}
|
})}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
"use server";
|
"use server";
|
||||||
import { initConnectionPostgres, initConnectionSurreal } from "@/components/db-utils";
|
import {
|
||||||
|
initConnectionPostgres,
|
||||||
|
initConnectionSurreal,
|
||||||
|
} from "@/components/db-utils";
|
||||||
|
|
||||||
export async function querydb() {
|
export async function querydb() {
|
||||||
try {
|
try {
|
||||||
let stats = [];
|
let stats = [];
|
||||||
if (process.env.DB_TYPE === "surrealdb") {
|
if (process.env.DB_TYPE === "surrealdb") {
|
||||||
let db = await initConnectionSurreal();
|
const db = await initConnectionSurreal();
|
||||||
// console.log(db);
|
// console.log(db);
|
||||||
stats = await db.query(`
|
stats = await db.query(`
|
||||||
select * from url
|
select * from url
|
||||||
|
@ -18,7 +21,7 @@ export async function querydb() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.DB_TYPE === "postgres") {
|
if (process.env.DB_TYPE === "postgres") {
|
||||||
let sql = await initConnectionPostgres();
|
const sql = await initConnectionPostgres();
|
||||||
stats = await sql`
|
stats = await sql`
|
||||||
select * from url
|
select * from url
|
||||||
order by clicks desc
|
order by clicks desc
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
"use client";
|
"use client";
|
||||||
import CardGrid from "@/components/card-grid";
|
import CardGrid from "@/components/card-grid";
|
||||||
import {
|
import { Card, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
Card,
|
|
||||||
CardHeader,
|
|
||||||
CardTitle
|
|
||||||
} from "@/components/ui/card";
|
|
||||||
|
|
||||||
export default function Loading() {
|
export default function Loading() {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -22,14 +22,14 @@ export default function StatsPage() {
|
||||||
if (data.length !== 0 && data !== undefined && data !== null) {
|
if (data.length !== 0 && data !== undefined && data !== null) {
|
||||||
const formatDate = (dateString: string | number | Date) => {
|
const formatDate = (dateString: string | number | Date) => {
|
||||||
const date = new Date(dateString);
|
const date = new Date(dateString);
|
||||||
const day = String(date.getDate()).padStart(2, '0');
|
const day = String(date.getDate()).padStart(2, "0");
|
||||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
const month = String(date.getMonth() + 1).padStart(2, "0");
|
||||||
const year = String(date.getFullYear()).slice(-2);
|
const year = String(date.getFullYear()).slice(-2);
|
||||||
return `${month}/${day}/${year}`;
|
return `${month}/${day}/${year}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
data = data.map(item => ({
|
data = data.map((item) => ({
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
...item,
|
...item,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -37,7 +37,7 @@ export default function StatsPage() {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
date_added: formatDate(item.date_added),
|
date_added: formatDate(item.date_added),
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
id: item.id.replace(/^url:\['(.*)'\]$/, '$1')
|
id: item.id.replace(/^url:\['(.*)'\]$/, "$1"),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
export default function CardGrid({
|
export default function CardGrid({
|
||||||
maxCols: maxCols = 4,
|
maxCols = 4,
|
||||||
children,
|
children,
|
||||||
className,
|
className,
|
||||||
...props
|
...props
|
||||||
|
@ -10,7 +10,8 @@ export default function CardGrid({
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
className?: string;
|
className?: string;
|
||||||
}) {
|
}) {
|
||||||
let baseClassName = `items-start justify-center gap-6 rounded-lg p-8 grid grid-cols-1`;
|
let baseClassName =
|
||||||
|
"items-start justify-center gap-6 rounded-lg p-8 grid grid-cols-1";
|
||||||
|
|
||||||
if (maxCols >= 2) {
|
if (maxCols >= 2) {
|
||||||
baseClassName += " lg:grid-cols-2";
|
baseClassName += " lg:grid-cols-2";
|
||||||
|
@ -22,16 +23,13 @@ export default function CardGrid({
|
||||||
baseClassName += " 2xl:grid-cols-4";
|
baseClassName += " 2xl:grid-cols-4";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (className == undefined) {
|
if (className === undefined) {
|
||||||
className = baseClassName;
|
className = baseClassName;
|
||||||
} else {
|
} else {
|
||||||
className = baseClassName + " " + className;
|
className = `${baseClassName} ${className}`;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div
|
<div className={`${className}`} {...props}>
|
||||||
className={`${className}`}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
"use server";
|
"use server";
|
||||||
import postgres, { Sql } from 'postgres';
|
import postgres, { type Sql } from "postgres";
|
||||||
import { Surreal } from "surrealdb.js";
|
import { Surreal } from "surrealdb.js";
|
||||||
const db = new Surreal();
|
const db = new Surreal();
|
||||||
|
|
||||||
export async function initConnectionSurreal(): Promise<Surreal> {
|
export async function initConnectionSurreal(): Promise<Surreal> {
|
||||||
try {
|
try {
|
||||||
await db.connect("ws://" + process.env.DB_URL_PORT + "/rpc", {
|
await db.connect(`ws://${process.env.DB_URL_PORT}/rpc`, {
|
||||||
namespace: "url",
|
namespace: "url",
|
||||||
database: "url",
|
database: "url",
|
||||||
auth: {
|
auth: {
|
||||||
|
@ -24,12 +24,12 @@ export async function initConnectionPostgres(): Promise<Sql<{}>> {
|
||||||
const DB_URL_PORT = (process.env.DB_URL_PORT || "postgres:5432").split(":");
|
const DB_URL_PORT = (process.env.DB_URL_PORT || "postgres:5432").split(":");
|
||||||
const sql = postgres({
|
const sql = postgres({
|
||||||
host: DB_URL_PORT[0],
|
host: DB_URL_PORT[0],
|
||||||
port: parseInt(DB_URL_PORT[1]),
|
port: Number.parseInt(DB_URL_PORT[1]),
|
||||||
user: process.env.POSTGRES_USER || "root",
|
user: process.env.POSTGRES_USER || "root",
|
||||||
password: process.env.POSTGRES_PASSWORD || "root",
|
password: process.env.POSTGRES_PASSWORD || "root",
|
||||||
database: process.env.POSTGRES_DB || "url",
|
database: process.env.POSTGRES_DB || "url",
|
||||||
max: 100,
|
max: 100,
|
||||||
onnotice: () => { },
|
onnotice: () => {},
|
||||||
});
|
});
|
||||||
return sql;
|
return sql;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,11 @@ export default async function Nav() {
|
||||||
<Link href="/stats">Stats</Link>
|
<Link href="/stats">Stats</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div className="flex flex-1 items-center justify-between gap-4 md:justify-end">
|
<div className="flex flex-1 items-center justify-between gap-4 md:justify-end">
|
||||||
<div className="transition-colors text-foreground/50 hover:text-foreground/100">
|
<div className="transition-colors text-foreground/50 hover:text-foreground/100">
|
||||||
<Link href="https://github.com/NexVeridian/next-url-shortener">GitHub</Link>
|
<Link href="https://github.com/NexVeridian/next-url-shortener">
|
||||||
|
GitHub
|
||||||
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DarkModeToggle />
|
<DarkModeToggle />
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"use client";
|
"use client";
|
||||||
import { ThemeProvider as NextThemesProvider } from "next-themes";
|
import { ThemeProvider as NextThemesProvider } from "next-themes";
|
||||||
import { type ThemeProviderProps } from "next-themes/dist/types";
|
import type { ThemeProviderProps } from "next-themes/dist/types";
|
||||||
|
|
||||||
export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
|
export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
|
||||||
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
|
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { type ClassValue, clsx } from "clsx"
|
import { type ClassValue, clsx } from "clsx";
|
||||||
import { twMerge } from "tailwind-merge"
|
import { twMerge } from "tailwind-merge";
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
export function cn(...inputs: ClassValue[]) {
|
||||||
return twMerge(clsx(inputs))
|
return twMerge(clsx(inputs));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
darkMode: ["class"],
|
darkMode: ["class"],
|
||||||
content: [
|
content: [
|
||||||
'./pages/**/*.{ts,tsx}',
|
"./pages/**/*.{ts,tsx}",
|
||||||
'./components/**/*.{ts,tsx}',
|
"./components/**/*.{ts,tsx}",
|
||||||
'./app/**/*.{ts,tsx}',
|
"./app/**/*.{ts,tsx}",
|
||||||
'./src/**/*.{ts,tsx}',
|
"./src/**/*.{ts,tsx}",
|
||||||
],
|
],
|
||||||
theme: {
|
theme: {
|
||||||
container: {
|
container: {
|
||||||
|
@ -75,4 +75,4 @@ module.exports = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [require("tailwindcss-animate")],
|
plugins: [require("tailwindcss-animate")],
|
||||||
}
|
};
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"lib": [
|
"lib": ["dom", "dom.iterable", "esnext"],
|
||||||
"dom",
|
|
||||||
"dom.iterable",
|
|
||||||
"esnext"
|
|
||||||
],
|
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
|
@ -23,18 +19,9 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": [
|
"@/*": ["./src/*"]
|
||||||
"./src/*"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": [
|
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||||
"next-env.d.ts",
|
"exclude": ["node_modules"]
|
||||||
"**/*.ts",
|
|
||||||
"**/*.tsx",
|
|
||||||
".next/types/**/*.ts",
|
|
||||||
],
|
|
||||||
"exclude": [
|
|
||||||
"node_modules"
|
|
||||||
]
|
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue