diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 0000000..671a084 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,6 @@ +{ + "attribution": { + "commit": "", + "pr": "" + } +} diff --git a/.env.sample b/.env.sample index 071d49f..6207dbc 100644 --- a/.env.sample +++ b/.env.sample @@ -15,6 +15,8 @@ AI_BASE_URL="https://api.openai.com/v1" # Base URL for OpenAI-compatible API AI_MODEL="gpt-4o-mini" # Model used for parsing search queries in "Find" # Immich Share Link -IMMICH_SHARE_LINK_KEY="" # Share link key for Immich POWER_TOOLS_ENDPOINT_URL="" # URL of the Power Tools endpoint (Used for share links) JWT_SECRET="" # JWT Secret for authentication + +# App Database (SQLite) +APP_DB_PATH="" # Path to the SQLite database file (default: ./data/app.db) diff --git a/.gitignore b/.gitignore index b9f8d23..fcdd3c9 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,11 @@ yarn-error.log* # local env files .env*.local +# SQLite database files +/data/*.db +/data/*.db-shm +/data/*.db-wal + # vercel .vercel @@ -35,4 +40,7 @@ yarn-error.log* *.tsbuildinfo next-env.d.ts +# plans +/docs/plans + .env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index a6992f3..712cfed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,10 @@ # Source: https://github.com/vercel/next.js/blob/canary/examples/with-docker/README.md # Install dependencies only when needed -FROM node:22-alpine AS deps -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. - -RUN apk add --no-cache libc6-compat +FROM oven/bun:1-alpine AS deps WORKDIR /app -COPY package.json ./ -RUN npm install --frozen-lockfile +COPY package.json bun.lockb ./ +RUN bun install --frozen-lockfile # Rebuild the source code only when needed FROM node:22-alpine AS builder @@ -38,10 +35,15 @@ RUN adduser -S nextjs -u 1001 COPY --from=builder /app/public ./public COPY --from=builder /app/package.json ./package.json -# Automatically leverage output traces to reduce image size +# Automatically leverage output traces to reduce image size # https://nextjs.org/docs/advanced-features/output-file-tracing COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static +COPY --from=builder --chown=nextjs:nodejs /app/src/db/migrations ./src/db/migrations + +# Copy native libsql binaries — Next.js standalone tracing misses dynamically required native modules +COPY --from=deps --chown=nextjs:nodejs /app/node_modules/@libsql ./node_modules/@libsql +COPY --from=deps --chown=nextjs:nodejs /app/node_modules/libsql ./node_modules/libsql USER nextjs @@ -58,4 +60,4 @@ ENV HOSTNAME=0.0.0.0 CMD ["node", "server.js"] -HEALTHCHECK CMD curl --fail http://localhost:3000/api/health || exit 1 \ No newline at end of file +HEALTHCHECK CMD curl --fail http://localhost:3000/api/health || exit 1 diff --git a/bun.lockb b/bun.lockb index f6133ad..f521ce9 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/drizzle.app.config.ts b/drizzle.app.config.ts new file mode 100644 index 0000000..3e3ede5 --- /dev/null +++ b/drizzle.app.config.ts @@ -0,0 +1,12 @@ +import { defineConfig } from "drizzle-kit"; + +export default defineConfig({ + dialect: "sqlite", + schema: "./src/db/schema/index.ts", + out: "./src/db/migrations", + dbCredentials: { + url: process.env.APP_DB_PATH + ? `file:${process.env.APP_DB_PATH}` + : "file:./data/app.db", + }, +}); diff --git a/next.config.mjs b/next.config.mjs index 65ab7b9..3f1b21a 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -3,6 +3,9 @@ const nextConfig = { reactStrictMode: false, output: 'standalone', + experimental: { + instrumentationHook: true, + }, images: { unoptimized: true, }, diff --git a/package.json b/package.json index 75dd287..88b0984 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,10 @@ "dev": "next dev", "build": "next build", "start": "next start -p ${PORT:=3000} -H ${HOST:=0.0.0.0}", - "lint": "next lint" + "lint": "next lint", + "db:generate": "drizzle-kit generate --config=drizzle.app.config.ts", + "db:migrate": "drizzle-kit migrate --config=drizzle.app.config.ts", + "db:studio": "drizzle-kit studio --config=drizzle.app.config.ts" }, "author": { "name": "Varun Raj Manoharan", @@ -17,6 +20,7 @@ "@ai-sdk/openai": "^3.0.29", "@ai-sdk/openai-compatible": "^2.0.30", "@ai-sdk/react": "^3.0.88", + "@libsql/client": "^0.17.2", "@radix-ui/react-accordion": "^1.2.1", "@radix-ui/react-alert-dialog": "^1.1.4", "@radix-ui/react-avatar": "^1.1.0", @@ -54,7 +58,7 @@ "cookie": "^0.6.0", "date-fns": "^3.6.0", "date-fns-tz": "^3.2.0", - "drizzle-orm": "^0.33.0", + "drizzle-orm": "^0.45.1", "jsonwebtoken": "^9.0.2", "leaflet": "^1.9.4", "leaflet-defaulticon-compatibility": "0.1.2", @@ -92,7 +96,7 @@ "@types/react-dom": "^18", "@types/react-mentions": "^4.4.1", "autoprefixer": "^10.4.20", - "drizzle-kit": "^0.24.0", + "drizzle-kit": "^0.31.10", "eslint": "^8", "eslint-config-next": "14.2.5", "postcss": "^8.4.41", diff --git a/src/components/import/ImportJobDetailDialog.tsx b/src/components/import/ImportJobDetailDialog.tsx new file mode 100644 index 0000000..e1abd74 --- /dev/null +++ b/src/components/import/ImportJobDetailDialog.tsx @@ -0,0 +1,164 @@ +import React from "react"; +import { useQuery } from "@tanstack/react-query"; +import { ExternalLink, Loader2 } from "lucide-react"; +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { getImportJob } from "@/handlers/api/import-jobs.handler"; +import { useConfig } from "@/contexts/ConfigContext"; + +const InfoRow = ({ label, value }: { label: string; value: React.ReactNode }) => ( +
+

{label}

+

{value ?? "—"}

+
+); + +const statusBadge = (status: string) => { + const styles = + status === "uploaded" || status === "completed" + ? "bg-emerald-500/10 text-emerald-600" + : status === "skipped" + ? "bg-amber-500/10 text-amber-600" + : status === "failed" + ? "bg-destructive/10 text-destructive" + : "bg-muted text-muted-foreground"; + + return ( + + {status} + + ); +}; + +interface ImportJobDetailDialogProps { + jobId: string | null; + onClose: () => void; +} + +export default function ImportJobDetailDialog({ jobId, onClose }: ImportJobDetailDialogProps) { + const { exImmichUrl } = useConfig(); + + const { data: detailJob, isLoading } = useQuery({ + queryKey: ["import-job-detail", jobId], + queryFn: () => getImportJob(jobId!), + enabled: !!jobId, + }); + + let dImportData: Record = {}; + let dAlbumOpts: { createAlbum?: boolean; albumName?: string; addToAlbumId?: string } | undefined; + let dError: string | null = null; + let albumId: string | undefined; + + if (detailJob) { + try { + dImportData = JSON.parse(detailJob.job.importData); + } catch { /* ignore */ } + dAlbumOpts = dImportData.albumOptions as typeof dAlbumOpts; + dError = typeof dImportData.error === "string" ? dImportData.error : null; + albumId = typeof dImportData.albumId === "string" ? dImportData.albumId : undefined; + } + + return ( + { if (!open) onClose(); }}> + + {isLoading && ( +
+ +
+ )} + {detailJob && (() => { + const dJob = detailJob.job; + + return ( + <> + + {dAlbumOpts?.albumName || "Import details"} + + +
+ + + + + + + {albumId && ( + + {dAlbumOpts?.albumName || albumId} + + + } /> + )} + {!albumId && dAlbumOpts?.albumName && ( + + )} +
+ + {dError && ( +
+ {dError} +
+ )} + +
+ + + + + + + + + + {detailJob.items.map((item) => { + let itemData: Record = {}; + try { itemData = JSON.parse(item.itemData ?? "{}"); } catch { /* ignore */ } + const fileName = (itemData.originalFileName as string) || item.assetId; + + return ( + + + + + + ); + })} + +
AssetStatusDetails
+ {item.immichId ? ( + e.stopPropagation()} + > + {fileName} + + + ) : ( + fileName + )} + + {statusBadge(item.status)} + + {item.error || "—"} +
+
+ + ); + })()} +
+
+ ); +} diff --git a/src/components/shared/ShareAssetsTrigger.tsx b/src/components/shared/ShareAssetsTrigger.tsx index 7d30545..366658a 100644 --- a/src/components/shared/ShareAssetsTrigger.tsx +++ b/src/components/shared/ShareAssetsTrigger.tsx @@ -3,6 +3,7 @@ import { Dialog, DialogTitle, DialogContent, DialogHeader, DialogTrigger, Dialog import { Button, ButtonProps } from '../ui/button'; import { ShareLinkFilters } from '@/types/shareLink'; import { generateShareLink } from '@/handlers/api/shareLink.handler'; +import { createShareKey, getShareKey } from '@/handlers/api/share-key.handler'; import { Input } from '../ui/input'; import { Label } from '@radix-ui/react-label'; @@ -22,6 +23,28 @@ export default function ShareAssetsTrigger({ filters, buttonProps }: ShareAssets const [config, setConfig] = useState>({ expiresIn: "never" }); + const [endpointConfigured, setEndpointConfigured] = useState(null); + const [shareKeyExists, setShareKeyExists] = useState(null); + const [creatingKey, setCreatingKey] = useState(false); + const [keyError, setKeyError] = useState(null); + + const checkShareKey = async () => { + const data = await getShareKey(); + setEndpointConfigured(data.endpointConfigured); + setShareKeyExists(data.exists); + }; + + const handleCreateKey = async () => { + setCreatingKey(true); + setKeyError(null); + try { + await createShareKey(); + setShareKeyExists(true); + } catch (err: any) { + setKeyError(err.message ?? 'Failed to create share key'); + } + setCreatingKey(false); + }; const handleReset = () => { setConfig({ expiresIn: "never" }); @@ -66,7 +89,7 @@ export default function ShareAssetsTrigger({ filters, buttonProps }: ShareAssets return ( - + { if (open) checkShareKey(); }}> @@ -77,6 +100,24 @@ export default function ShareAssetsTrigger({ filters, buttonProps }: ShareAssets Generate a share link for the selected assets (either bunch of albums or bunch of people) and share it with your friends and family. + {endpointConfigured === false && ( +
+

+ POWER_TOOLS_ENDPOINT_URL is not set. Add it to your environment variables to enable share links. +

+
+ )} + {endpointConfigured && shareKeyExists === false && ( +
+

+ Serving thumbnails on share links requires a dedicated API key. Create one now with minimal permissions. +

+ {keyError &&

{keyError}

} + +
+ )} {errorMessage &&
{errorMessage}
} {generatedLink ?
@@ -120,7 +161,7 @@ export default function ShareAssetsTrigger({ filters, buttonProps }: ShareAssets
- + )} diff --git a/src/config/constants/sidebarNavs.tsx b/src/config/constants/sidebarNavs.tsx index f327b7e..7d84e7f 100644 --- a/src/config/constants/sidebarNavs.tsx +++ b/src/config/constants/sidebarNavs.tsx @@ -1,4 +1,4 @@ -import { Copy, GalleryHorizontal, GalleryVerticalEnd, Image as ImageIcon, MapPin, MapPinX, PackageSearch, Rewind, Search, Share2, User, Video } from "lucide-react"; +import { Copy, GalleryHorizontal, GalleryVerticalEnd, Image as ImageIcon, MapPin, MapPinX, PackageSearch, Rewind, Search, Settings, Share2, User, Video } from "lucide-react"; export const sidebarNavs = [ // { @@ -50,7 +50,7 @@ export const sidebarNavs = [ // Empty Videos { title: "Empty Videos", - link: "/assets/empty-videos", + link: "/assets/empty-videos", icon: