From 674b42c7afc9f08ea2f4abd82972b4760f1ffc34 Mon Sep 17 00:00:00 2001 From: Howard Date: Tue, 9 Dec 2025 10:10:34 +0800 Subject: [PATCH 1/5] Update navbar --- apps/web/src/app/dashboard/sidebar.tsx | 30 +--- apps/web/src/app/user/[userid]/page.tsx | 2 +- .../web/src/components/conditional-layout.tsx | 10 +- apps/web/src/components/footer.tsx | 18 -- apps/web/src/components/mode-toggle.tsx | 84 ++++++--- apps/web/src/components/navigation.tsx | 167 +++++++----------- apps/web/src/components/theme-provider.tsx | 6 +- packages/auth/src/index.ts | 2 + 8 files changed, 127 insertions(+), 192 deletions(-) delete mode 100644 apps/web/src/components/footer.tsx diff --git a/apps/web/src/app/dashboard/sidebar.tsx b/apps/web/src/app/dashboard/sidebar.tsx index f13de2f..cabdb81 100644 --- a/apps/web/src/app/dashboard/sidebar.tsx +++ b/apps/web/src/app/dashboard/sidebar.tsx @@ -14,6 +14,7 @@ import { } from "lucide-react"; import { Button } from "@/components/ui/button"; import Image from "next/image"; +import { ModeToggleDropdown } from "@/components/mode-toggle"; import { DropdownMenu, DropdownMenuContent, @@ -139,7 +140,7 @@ export default function DashboardSidebar({ - + @@ -211,30 +212,3 @@ export default function DashboardSidebar({ ); } - -function ModeToggle() { - const { setTheme } = useTheme(); - - return ( - - - - - - setTheme("light")}> - Light - - setTheme("dark")}> - Dark - - setTheme("system")}> - System - - - - ); -} diff --git a/apps/web/src/app/user/[userid]/page.tsx b/apps/web/src/app/user/[userid]/page.tsx index 9bffed5..6397365 100644 --- a/apps/web/src/app/user/[userid]/page.tsx +++ b/apps/web/src/app/user/[userid]/page.tsx @@ -46,7 +46,7 @@ export default async function Page(props: { alt={`The profile picture for ${content[0].name}`} width="100" height="100" - className="rounded-full border border-black dark:border-white select-none" + className="rounded-full border border-black dark:border-white select-none w-[100px] h-[100px]" draggable="false" />
diff --git a/apps/web/src/components/conditional-layout.tsx b/apps/web/src/components/conditional-layout.tsx index 4d8321a..0179ad6 100644 --- a/apps/web/src/components/conditional-layout.tsx +++ b/apps/web/src/components/conditional-layout.tsx @@ -1,7 +1,6 @@ "use client"; import { usePathname } from "next/navigation"; import Navigation from "@/components/navigation"; -import Footer from "@/components/footer"; export default function ConditionalLayout({ children, @@ -19,11 +18,10 @@ export default function ConditionalLayout({ // Regular layout with nav and footer return (
-
- -
-
{children}
-
+ +
+ {children} +
); } diff --git a/apps/web/src/components/footer.tsx b/apps/web/src/components/footer.tsx deleted file mode 100644 index 7387274..0000000 --- a/apps/web/src/components/footer.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import Link from "next/link"; -export default function Footer() { - return ( -
-
- - This project is{" "} - - open source - - . - -
- ); -} diff --git a/apps/web/src/components/mode-toggle.tsx b/apps/web/src/components/mode-toggle.tsx index 1a3c387..2acd8ef 100644 --- a/apps/web/src/components/mode-toggle.tsx +++ b/apps/web/src/components/mode-toggle.tsx @@ -1,39 +1,65 @@ "use client"; import * as React from "react"; -import { Moon, Sun } from "lucide-react"; -import { useTheme } from "next-themes"; +import { LaptopMinimalIcon, Moon, Sun } from "lucide-react"; +import { ThemeProvider, useTheme } from "next-themes"; import { Button } from "@/components/ui/button"; import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuTrigger, + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; export function ModeToggle() { - const { setTheme } = useTheme(); + const { setTheme, theme } = useTheme(); - return ( - - - - - - setTheme("light")}> - Light - - setTheme("dark")}> - Dark - - setTheme("system")}> - System - - - - ); + return ( + + ); +} + +export function ModeToggleDropdown() { + const { setTheme } = useTheme(); + + return ( + + + + + + setTheme("light")}> + Light + + setTheme("dark")}> + Dark + + setTheme("system")}> + System + + + + ); } diff --git a/apps/web/src/components/navigation.tsx b/apps/web/src/components/navigation.tsx index 53c00e5..28a682f 100644 --- a/apps/web/src/components/navigation.tsx +++ b/apps/web/src/components/navigation.tsx @@ -15,51 +15,37 @@ import { Skeleton } from "./ui/skeleton"; import { Spinner } from "./ui/spinner"; import { useRouter } from "next/navigation"; import * as React from "react"; -import { Moon, SearchIcon, Sun } from "lucide-react"; +import { ModeToggle } from "./mode-toggle"; +import { + HouseIcon, + LayoutDashboardIcon, + LogInIcon, + LogOutIcon, + Moon, + SearchIcon, + Sun, + UserIcon, +} from "lucide-react"; import { useTheme } from "next-themes"; export default function Navigation() { - const links = [] as const; - const [scrolled, setScrolled] = useState(false); - - useEffect(() => { - const handleScroll = () => { - setScrolled(window.scrollY > 10); - }; - window.addEventListener("scroll", handleScroll); - return () => window.removeEventListener("scroll", handleScroll); - }, []); - return ( -
-
-
- - logs +
+
+
+ + - -
-
-
+ © {new Date().getFullYear()}
); @@ -71,7 +57,7 @@ function UserMenu() { if (isPending) { return ( - ); @@ -79,81 +65,48 @@ function UserMenu() { if (!session) { return ( - ); } return ( - - - - - - - - - - - - - - - - - ); -} - -function ModeToggle() { - const { setTheme } = useTheme(); - - return ( - - - - - - setTheme("light")}> - Light - - setTheme("dark")}> - Dark - - setTheme("system")}> - System - - - + <> + + + + ); } diff --git a/apps/web/src/components/theme-provider.tsx b/apps/web/src/components/theme-provider.tsx index f6b22ae..189a2b1 100644 --- a/apps/web/src/components/theme-provider.tsx +++ b/apps/web/src/components/theme-provider.tsx @@ -4,8 +4,8 @@ import * as React from "react"; import { ThemeProvider as NextThemesProvider } from "next-themes"; export function ThemeProvider({ - children, - ...props + children, + ...props }: React.ComponentProps) { - return {children}; + return {children}; } diff --git a/packages/auth/src/index.ts b/packages/auth/src/index.ts index 146b7ff..2d16d7d 100644 --- a/packages/auth/src/index.ts +++ b/packages/auth/src/index.ts @@ -21,6 +21,8 @@ export const auth = betterAuth({ secure: true, httpOnly: true, }, + disableCSRFCheck: process.env.NODE_ENV === "development" ? true : false, + trustedProxyHeaders: true, }, databaseHooks: { user: { From 06721e28a22fbad5983a11e6a3a8a8c7f7225303 Mon Sep 17 00:00:00 2001 From: Howard Date: Tue, 9 Dec 2025 14:41:21 +0800 Subject: [PATCH 2/5] yeee --- apps/web/src/components/layout.tsx | 68 ------------------------------ 1 file changed, 68 deletions(-) delete mode 100644 apps/web/src/components/layout.tsx diff --git a/apps/web/src/components/layout.tsx b/apps/web/src/components/layout.tsx deleted file mode 100644 index 40f242f..0000000 --- a/apps/web/src/components/layout.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import type { Metadata } from "next"; -import { Geist, Geist_Mono } from "next/font/google"; -import "../index.css"; -import Providers from "@/components/providers"; -import Navigation from "@/components/navigation"; -import { db, main_schema, dorm } from "../../../../packages/db/src"; -import Footer from "@/components/footer"; - -const geistSans = Geist({ - variable: "--font-geist-sans", - subsets: ["latin"], -}); - -const geistMono = Geist_Mono({ - variable: "--font-geist-mono", - subsets: ["latin"], -}); - -export async function generateMetadata(): Promise { - try { - const titleResult = await db - .select() - .from(main_schema.kvData) - .where(dorm.eq(main_schema.kvData.key, "title")); - - const descResult = await db - .select() - .from(main_schema.kvData) - .where(dorm.eq(main_schema.kvData.key, "description")); - - const title = `${titleResult[0]?.value ?? ""}`; - const description = `${descResult[0]?.value ?? ""}`; - - return { - title, - description, - }; - } catch (e: any) { - console.error(e); - return { - title: `Home`, - }; - } -} - -export default function RootLayout({ - children, -}: Readonly<{ - children: React.ReactNode; -}>) { - return ( - - - -
-
- -
-
{children}
-
-
-
- - - ); -} From d146547df1a9eb97f82c341ba4c10d673c3b3666 Mon Sep 17 00:00:00 2001 From: Howard Date: Tue, 9 Dec 2025 15:34:45 +0800 Subject: [PATCH 3/5] ok --- .github/scripts/README.md | 39 +++++++ .github/scripts/increment-version.js | 105 +++++++++++++++++ .../auto-update-version.yml.disabled | 64 +++++++++++ ...ge.yml => build_docker_image.yml.disabled} | 2 + .github/workflows/version-and-build.yml | 106 ++++++++++++++++++ apps/web/projectData.ts | 2 +- apps/web/src/components/navigation.tsx | 4 +- 7 files changed, 319 insertions(+), 3 deletions(-) create mode 100644 .github/scripts/README.md create mode 100644 .github/scripts/increment-version.js create mode 100644 .github/workflows/auto-update-version.yml.disabled rename .github/workflows/{build_docker_image.yml => build_docker_image.yml.disabled} (90%) create mode 100644 .github/workflows/version-and-build.yml diff --git a/.github/scripts/README.md b/.github/scripts/README.md new file mode 100644 index 0000000..1676062 --- /dev/null +++ b/.github/scripts/README.md @@ -0,0 +1,39 @@ +# CI Scripts + +This directory contains scripts used by GitHub Actions workflows to automate various tasks. + +## increment-version.js + +Automatically increments the version number in `apps/web/projectData.ts`. + +### Usage + +```bash +node .github/scripts/increment-version.js +``` + +### Version Increment Logic + +The script handles different version formats intelligently: + +1. **Suffixed versions** (e.g., `"0.1.10-canary-1"` → `"0.1.10-canary-2"`) + - Increments the number after the final dash + +2. **Semantic versions** (e.g., `"0.1.10"` → `"0.1.11"`) + - Increments the patch version (third number) + +3. **Fallback pattern** - Increments the last number found in the version string + +### Outputs + +When run in GitHub Actions, the script sets these outputs: +- `current`: The previous version number +- `new`: The new incremented version number + +### Integration + +This script is used by the "Auto Update Version and Build" workflow (`version-and-build.yml`) to automatically increment the version on every push to the main branch, then build and tag a Docker image with the new version. + +### Prevention of Infinite Loops + +The workflow is designed to skip execution when the commit message contains "🤖 Auto-increment version" to prevent infinite loops of version updates. \ No newline at end of file diff --git a/.github/scripts/increment-version.js b/.github/scripts/increment-version.js new file mode 100644 index 0000000..9f96726 --- /dev/null +++ b/.github/scripts/increment-version.js @@ -0,0 +1,105 @@ +#!/usr/bin/env node + +import fs from "fs"; +import path from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const PROJECT_DATA_PATH = path.join(__dirname, "../../apps/web/projectData.ts"); + +function incrementVersion(version) { + // Handle different version formats: + // "0.1.10-canery-1" -> "0.1.10-canery-2" + // "0.1.10" -> "0.1.11" + // "1.2.3-alpha-5" -> "1.2.3-alpha-6" + + // Pattern 1: ends with -number (e.g., "0.1.10-canery-1") + const dashNumberPattern = /^(.+-)(\d+)$/; + const dashMatch = version.match(dashNumberPattern); + + if (dashMatch) { + const prefix = dashMatch[1]; + const number = parseInt(dashMatch[2], 10); + return `${prefix}${number + 1}`; + } + + // Pattern 2: semantic version (e.g., "0.1.10" or "1.2.3") + const semverPattern = /^(\d+)\.(\d+)\.(\d+)(.*)$/; + const semverMatch = version.match(semverPattern); + + if (semverMatch) { + const major = parseInt(semverMatch[1], 10); + const minor = parseInt(semverMatch[2], 10); + const patch = parseInt(semverMatch[3], 10); + const suffix = semverMatch[4] || ""; + return `${major}.${minor}.${patch + 1}${suffix}`; + } + + // Fallback: find the last number in the string and increment it + const lastNumberPattern = /^(.*?)(\d+)([^\d]*)$/; + const lastNumberMatch = version.match(lastNumberPattern); + + if (lastNumberMatch) { + const prefix = lastNumberMatch[1]; + const number = parseInt(lastNumberMatch[2], 10); + const suffix = lastNumberMatch[3]; + return `${prefix}${number + 1}${suffix}`; + } + + // If no number found, append .1 + return `${version}.1`; +} + +function updateProjectData() { + try { + // Read the current file + const content = fs.readFileSync(PROJECT_DATA_PATH, "utf8"); + + // Extract current version using regex + const versionPattern = /version:\s*["']([^"']+)["']/; + const match = content.match(versionPattern); + + if (!match) { + throw new Error("Could not find version property in projectData.ts"); + } + + const currentVersion = match[1]; + const newVersion = incrementVersion(currentVersion); + + // Replace the version in the content + const newContent = content.replace( + versionPattern, + `version: "${newVersion}"`, + ); + + // Write back to file + fs.writeFileSync(PROJECT_DATA_PATH, newContent, "utf8"); + + console.log(`Version updated from ${currentVersion} to ${newVersion}`); + + // Output for GitHub Actions (using modern format) + if (process.env.GITHUB_OUTPUT) { + fs.appendFileSync( + process.env.GITHUB_OUTPUT, + `current=${currentVersion}\n`, + ); + fs.appendFileSync(process.env.GITHUB_OUTPUT, `new=${newVersion}\n`); + } else { + // Fallback for local testing + console.log(`current=${currentVersion}`); + console.log(`new=${newVersion}`); + } + } catch (error) { + console.error("Error updating version:", error.message); + process.exit(1); + } +} + +// Run if this script is executed directly +if (import.meta.url === `file://${process.argv[1]}`) { + updateProjectData(); +} + +export { incrementVersion, updateProjectData }; diff --git a/.github/workflows/auto-update-version.yml.disabled b/.github/workflows/auto-update-version.yml.disabled new file mode 100644 index 0000000..0dadbc8 --- /dev/null +++ b/.github/workflows/auto-update-version.yml.disabled @@ -0,0 +1,64 @@ +name: Auto Update Version + +on: + push: + branches: + - master + - main + workflow_dispatch: + +jobs: + update-version: + runs-on: ubuntu-latest + permissions: + contents: write + # Skip if the commit message contains the auto-increment marker to prevent infinite loops + if: "!contains(github.event.head_commit.message, '🤖 Auto-increment version')" + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20" + + - name: Update version using Node.js script + id: version_update + run: | + # Make script executable + chmod +x .github/scripts/increment-version.js + + # Run the version increment script + node .github/scripts/increment-version.js + + # Display updated file + echo "Updated projectData.ts:" + cat apps/web/projectData.ts + + - name: Check for changes + id: git_status + run: | + if [ -n "$(git status --porcelain)" ]; then + echo "changes=true" >> $GITHUB_OUTPUT + else + echo "changes=false" >> $GITHUB_OUTPUT + fi + + - name: Commit and push changes + if: steps.git_status.outputs.changes == 'true' + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add apps/web/projectData.ts + git commit -m "🤖 Auto-increment version to ${{ steps.version_update.outputs.new }} [skip ci]" + git push + + - name: Output version info + run: | + echo "Previous version: ${{ steps.version_update.outputs.current }}" + echo "New version: ${{ steps.version_update.outputs.new }}" diff --git a/.github/workflows/build_docker_image.yml b/.github/workflows/build_docker_image.yml.disabled similarity index 90% rename from .github/workflows/build_docker_image.yml rename to .github/workflows/build_docker_image.yml.disabled index 086faa5..51c00a6 100644 --- a/.github/workflows/build_docker_image.yml +++ b/.github/workflows/build_docker_image.yml.disabled @@ -17,6 +17,8 @@ jobs: permissions: contents: read packages: write + # Only run if not triggered by the auto-increment commit + if: "!contains(github.event.head_commit.message, '🤖 Auto-increment version')" steps: - name: Checkout repository diff --git a/.github/workflows/version-and-build.yml b/.github/workflows/version-and-build.yml new file mode 100644 index 0000000..e09064e --- /dev/null +++ b/.github/workflows/version-and-build.yml @@ -0,0 +1,106 @@ +name: Auto Update Version and Build + +on: + push: + branches: + - master + - main + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + update-version-and-build: + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + # Skip if the commit message contains the auto-increment marker to prevent infinite loops + if: "!contains(github.event.head_commit.message, '🤖 Auto-increment version')" + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20" + + - name: Update version using Node.js script + id: version_update + run: | + # Make script executable + chmod +x .github/scripts/increment-version.js + + # Run the version increment script + node .github/scripts/increment-version.js + + # Display updated file + echo "Updated projectData.ts:" + cat apps/web/projectData.ts + + - name: Check for changes + id: git_status + run: | + if [ -n "$(git status --porcelain)" ]; then + echo "changes=true" >> $GITHUB_OUTPUT + else + echo "changes=false" >> $GITHUB_OUTPUT + fi + + - name: Commit version changes + if: steps.git_status.outputs.changes == 'true' + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add apps/web/projectData.ts + git commit -m "🤖 Auto-increment version to ${{ steps.version_update.outputs.new }}" + git push + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest + type=raw,value=${{ steps.version_update.outputs.new }} + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=sha,prefix= + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Output summary + run: | + echo "## Version Update Summary" >> $GITHUB_STEP_SUMMARY + echo "- Previous version: ${{ steps.version_update.outputs.current }}" >> $GITHUB_STEP_SUMMARY + echo "- New version: ${{ steps.version_update.outputs.new }}" >> $GITHUB_STEP_SUMMARY + echo "- Docker image built with tags:" >> $GITHUB_STEP_SUMMARY + echo " - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY + echo " - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version_update.outputs.new }}" >> $GITHUB_STEP_SUMMARY diff --git a/apps/web/projectData.ts b/apps/web/projectData.ts index cd207cd..b015ed5 100644 --- a/apps/web/projectData.ts +++ b/apps/web/projectData.ts @@ -1,5 +1,5 @@ const data = { - version: "0.1.9", + version: "0.1.10-canery-1", }; export default data; diff --git a/apps/web/src/components/navigation.tsx b/apps/web/src/components/navigation.tsx index 28a682f..db15d96 100644 --- a/apps/web/src/components/navigation.tsx +++ b/apps/web/src/components/navigation.tsx @@ -29,8 +29,8 @@ import { import { useTheme } from "next-themes"; export default function Navigation() { return ( -
-
+
+
- +
diff --git a/apps/web/src/components/mode-toggle.tsx b/apps/web/src/components/mode-toggle.tsx index 2acd8ef..3e46bfd 100644 --- a/apps/web/src/components/mode-toggle.tsx +++ b/apps/web/src/components/mode-toggle.tsx @@ -18,6 +18,7 @@ export function ModeToggle() { ); } - -export function ModeToggleDropdown() { - const { setTheme } = useTheme(); - - return ( - - - - - - setTheme("light")}> - Light - - setTheme("dark")}> - Dark - - setTheme("system")}> - System - - - - ); -} diff --git a/apps/web/src/components/navigation.tsx b/apps/web/src/components/navigation.tsx index db15d96..31b7dc5 100644 --- a/apps/web/src/components/navigation.tsx +++ b/apps/web/src/components/navigation.tsx @@ -33,12 +33,22 @@ export default function Navigation() {
- - @@ -57,7 +67,12 @@ function UserMenu() { if (isPending) { return ( - ); @@ -65,7 +80,13 @@ function UserMenu() { if (!session) { return ( -