chore: format

This commit is contained in:
Elijah McMorris 2025-03-06 01:31:59 -08:00
parent c8338e5516
commit 527139f298
Signed by: NexVeridian
SSH key fingerprint: SHA256:bsA1SKZxuEcEVHAy3gY1HUeM5ykRJl0U0kQHQn0hMg8
33 changed files with 848 additions and 3132 deletions

View file

@ -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

View file

@ -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"
]
}
}
}

View file

@ -1,3 +0,0 @@
{
"extends": "next/core-web-vitals"
}

36
biome.json Normal file
View 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"
}
}
}

View file

@ -1,6 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "standalone",
}
};
module.exports = nextConfig
module.exports = nextConfig;

View file

@ -6,7 +6,8 @@
"dev": "next dev --turbo",
"build": "next build",
"start": "next start",
"lint": "next lint"
"fix": "biome check . --write",
"check": "biome check ."
},
"dependencies": {
"@hookform/resolvers": "^3.10.0",
@ -34,16 +35,13 @@
"zod": "^3.24.2"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@types/node": "^22.13.9",
"@types/prop-types": "^15.7.14",
"@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5",
"autoprefixer": "^10.4.20",
"eslint": "^8.57.1",
"eslint-config-next": "14.2.5",
"postcss": "^8.5.3",
"prettier": "^3.5.3",
"prettier-plugin-tailwindcss": "^0.6.11",
"tailwindcss": "^3.4.17",
"typescript": "^5.8.2"
}

2401
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

View file

@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {},
autoprefixer: {},
},
}
};

View file

@ -1,9 +0,0 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
packages = with pkgs; [
git
btop
lazygit
micro
];
}

View file

@ -1,21 +1,27 @@
"use server";
import { initConnectionPostgres, initConnectionSurreal } from "@/components/db-utils";
import {
initConnectionPostgres,
initConnectionSurreal,
} from "@/components/db-utils";
export async function querydb(slug: string) {
let long_url = undefined;
try {
if (process.env.DB_TYPE === "surrealdb") {
let db = await initConnectionSurreal();
long_url = await db.query(`
const db = await initConnectionSurreal();
long_url = await db.query(
`
update url:[$id]
set clicks +=1;
`, { id: slug });
`,
{ id: slug },
);
// @ts-ignore
long_url = long_url[0][0].long_url;
}
if (process.env.DB_TYPE === "postgres") {
let sql = await initConnectionPostgres();
const sql = await initConnectionPostgres();
long_url = await sql`
update url set
clicks = clicks + 1,

View file

@ -3,12 +3,12 @@ import { notFound, redirect } from "next/navigation";
import { querydb } from "./db";
export default async function Page({ params }: { params: { slug: string } }) {
if (params.slug == "favicon.ico") {
if (params.slug === "favicon.ico") {
return;
}
let long_url = await querydb(params.slug);
if (long_url == undefined) {
const long_url = await querydb(params.slug);
if (long_url === undefined) {
return notFound();
}
redirect(`https://${long_url}`);

View file

@ -5,7 +5,7 @@ import {
CardContent,
CardFooter,
CardHeader,
CardTitle
CardTitle,
} from "@/components/ui/card";
import {
Form,
@ -13,7 +13,7 @@ import {
FormField,
FormItem,
FormLabel,
FormMessage
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import {
@ -25,17 +25,17 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { CopyIcon } from "@radix-ui/react-icons";
import { useFormState } from "react-dom";
import { useForm } from "react-hook-form";
import { z } from "zod";
import type { z } from "zod";
import { querydb } from "./db";
import { formSchema } from "./schema";
const initialState = {
url: null,
}
};
export default function CreateCard() {
// @ts-ignore
let [state, formAction] = useFormState(querydb, initialState);
const [state, formAction] = useFormState(querydb, initialState);
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
@ -59,9 +59,8 @@ export default function CreateCard() {
}
}
navigator.clipboard.writeText(url)
.catch(err => {
console.error('Failed to copy URL to clipboard:', err);
navigator.clipboard.writeText(url).catch((err) => {
console.error("Failed to copy URL to clipboard:", err);
});
}
};
@ -95,7 +94,9 @@ export default function CreateCard() {
</CardContent>
<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 && (
<Popover>
<PopoverTrigger>
@ -104,9 +105,7 @@ export default function CreateCard() {
</Button>
</PopoverTrigger>
<PopoverContent>
<p className="text-lg">
Url added to clipboard
</p>
<p className="text-lg">Url added to clipboard</p>
</PopoverContent>
</Popover>
)}

View file

@ -1,10 +1,14 @@
"use server";
import { initConnectionPostgres, initConnectionSurreal } from "@/components/db-utils";
import {
initConnectionPostgres,
initConnectionSurreal,
} from "@/components/db-utils";
import { formSchema } from "./schema";
function generateRandomString(length: number) {
const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let randomString = '';
const charset =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let randomString = "";
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charset.length);
randomString += charset[randomIndex];
@ -13,34 +17,37 @@ function generateRandomString(length: number) {
}
export async function querydb(prevState: any, formData: FormData) {
const values = formSchema.safeParse(formData)
const values = formSchema.safeParse(formData);
if (!values.success) {
return { error: values.error };
}
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;
try {
if (process.env.DB_TYPE === "surrealdb") {
let db = await initConnectionSurreal();
url = await db.query(`
const db = await initConnectionSurreal();
url = await db.query(
`
create url:[rand::string(8)] CONTENT {
long_url: $long_url,
clicks: 0,
date_added: time::now(),
date_accessed: <future> { time::now() }
} return id[0];
`, {
long_url: long_url
});
`,
{
long_url: long_url,
},
);
// @ts-ignore
url = url[0][0].id;
}
console.log(long_url);
if (process.env.DB_TYPE === "postgres") {
let sql = await initConnectionPostgres();
const sql = await initConnectionPostgres();
await sql`
create table if not exists url (
id text primary key,

View file

@ -1,8 +1,8 @@
import { z } from "zod";
export const formSchema = z.object({
url: z.string().min(4,
{ message: "The URL must be at least 4 characters long" }
).max(100
, { message: "The URL must be at most 100 characters long" }),
url: z
.string()
.min(4, { message: "The URL must be at least 4 characters long" })
.max(100, { message: "The URL must be at most 100 characters long" }),
});

View file

@ -1,21 +1,19 @@
"use client";
import CardGrid from "@/components/card-grid";
import {
Card,
CardHeader,
CardTitle
} from "@/components/ui/card";
import { Card, CardHeader, CardTitle } from "@/components/ui/card";
export default function GlobalError({
error,
}: {
error: Error & { digest?: string }
error: Error & { digest?: string };
}) {
return (
<CardGrid maxCols={1}>
<Card>
<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>
</Card>
</CardGrid>

View file

@ -1,17 +1,15 @@
"use client";
import CardGrid from "@/components/card-grid";
import {
Card,
CardHeader,
CardTitle
} from "@/components/ui/card";
import { Card, CardHeader, CardTitle } from "@/components/ui/card";
export default function NotFound() {
return (
<CardGrid maxCols={1}>
<Card>
<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>
</Card>
</CardGrid>

View file

@ -1,10 +1,6 @@
"use client";
import CardGrid from "@/components/card-grid";
import {
Card,
CardHeader,
CardTitle
} from "@/components/ui/card";
import { Card, CardHeader, CardTitle } from "@/components/ui/card";
import Link from "next/link";
import CreateCard from "./create/create";

View file

@ -1,5 +1,5 @@
"use client";
import { ColumnDef } from "@tanstack/react-table";
import type { ColumnDef } from "@tanstack/react-table";
export type UrlTable = {
clicks: number;

View file

@ -8,10 +8,10 @@ import {
TableRow,
} from "@/components/ui/table";
import {
ColumnDef,
type ColumnDef,
flexRender,
getCoreRowModel,
useReactTable
useReactTable,
} from "@tanstack/react-table";
interface DataTableProps<TData, TValue> {
@ -43,10 +43,10 @@ export function DataTable<TData, TValue>({
? null
: flexRender(
header.column.columnDef.header,
header.getContext()
header.getContext(),
)}
</TableHead>
)
);
})}
</TableRow>
))}

View file

@ -1,11 +1,14 @@
"use server";
import { initConnectionPostgres, initConnectionSurreal } from "@/components/db-utils";
import {
initConnectionPostgres,
initConnectionSurreal,
} from "@/components/db-utils";
export async function querydb() {
try {
let stats = [];
if (process.env.DB_TYPE === "surrealdb") {
let db = await initConnectionSurreal();
const db = await initConnectionSurreal();
// console.log(db);
stats = await db.query(`
select * from url
@ -18,7 +21,7 @@ export async function querydb() {
}
if (process.env.DB_TYPE === "postgres") {
let sql = await initConnectionPostgres();
const sql = await initConnectionPostgres();
stats = await sql`
select * from url
order by clicks desc

View file

@ -1,10 +1,6 @@
"use client";
import CardGrid from "@/components/card-grid";
import {
Card,
CardHeader,
CardTitle
} from "@/components/ui/card";
import { Card, CardHeader, CardTitle } from "@/components/ui/card";
export default function Loading() {
return (

View file

@ -22,14 +22,14 @@ export default function StatsPage() {
if (data.length !== 0 && data !== undefined && data !== null) {
const formatDate = (dateString: string | number | Date) => {
const date = new Date(dateString);
const day = String(date.getDate()).padStart(2, '0');
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, "0");
const month = String(date.getMonth() + 1).padStart(2, "0");
const year = String(date.getFullYear()).slice(-2);
return `${month}/${day}/${year}`;
};
// @ts-ignore
data = data.map(item => ({
data = data.map((item) => ({
// @ts-ignore
...item,
// @ts-ignore
@ -37,7 +37,7 @@ export default function StatsPage() {
// @ts-ignore
date_added: formatDate(item.date_added),
// @ts-ignore
id: item.id.replace(/^url:\['(.*)'\]$/, '$1')
id: item.id.replace(/^url:\['(.*)'\]$/, "$1"),
}));
}

View file

@ -1,7 +1,7 @@
"use client";
export default function CardGrid({
maxCols: maxCols = 4,
maxCols = 4,
children,
className,
...props
@ -10,7 +10,8 @@ export default function CardGrid({
children?: React.ReactNode;
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) {
baseClassName += " lg:grid-cols-2";
@ -22,16 +23,13 @@ export default function CardGrid({
baseClassName += " 2xl:grid-cols-4";
}
if (className == undefined) {
if (className === undefined) {
className = baseClassName;
} else {
className = baseClassName + " " + className;
className = `${baseClassName} ${className}`;
}
return (
<div
className={`${className}`}
{...props}
>
<div className={`${className}`} {...props}>
{children}
</div>
);

View file

@ -1,11 +1,11 @@
"use server";
import postgres, { Sql } from 'postgres';
import postgres, { type Sql } from "postgres";
import { Surreal } from "surrealdb.js";
const db = new Surreal();
export async function initConnectionSurreal(): Promise<Surreal> {
try {
await db.connect("ws://" + process.env.DB_URL_PORT + "/rpc", {
await db.connect(`ws://${process.env.DB_URL_PORT}/rpc`, {
namespace: "url",
database: "url",
auth: {
@ -24,7 +24,7 @@ export async function initConnectionPostgres(): Promise<Sql<{}>> {
const DB_URL_PORT = (process.env.DB_URL_PORT || "postgres:5432").split(":");
const sql = postgres({
host: DB_URL_PORT[0],
port: parseInt(DB_URL_PORT[1]),
port: Number.parseInt(DB_URL_PORT[1]),
user: process.env.POSTGRES_USER || "root",
password: process.env.POSTGRES_PASSWORD || "root",
database: process.env.POSTGRES_DB || "url",

View file

@ -17,10 +17,11 @@ export default async function Nav() {
<Link href="/stats">Stats</Link>
</div>
<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">
<Link href="https://github.com/NexVeridian/next-url-shortener">GitHub</Link>
<Link href="https://github.com/NexVeridian/next-url-shortener">
GitHub
</Link>
</div>
<DarkModeToggle />

View file

@ -1,6 +1,6 @@
"use client";
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) {
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;

View file

@ -1,6 +1,6 @@
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
return twMerge(clsx(inputs));
}

View file

@ -2,10 +2,10 @@
module.exports = {
darkMode: ["class"],
content: [
'./pages/**/*.{ts,tsx}',
'./components/**/*.{ts,tsx}',
'./app/**/*.{ts,tsx}',
'./src/**/*.{ts,tsx}',
"./pages/**/*.{ts,tsx}",
"./components/**/*.{ts,tsx}",
"./app/**/*.{ts,tsx}",
"./src/**/*.{ts,tsx}",
],
theme: {
container: {
@ -75,4 +75,4 @@ module.exports = {
},
},
plugins: [require("tailwindcss-animate")],
}
};

View file

@ -1,11 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
@ -23,18 +19,9 @@
}
],
"paths": {
"@/*": [
"./src/*"
]
"@/*": ["./src/*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
],
"exclude": [
"node_modules"
]
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}