fix: sidebar redesign and api key validation
Signed-off-by: Varun <varun@skcript.com>
This commit is contained in:
1 parent
15f90121a1
commit
937f64a57e
6 files changed
+527
-217
No files matched your search
@@ -1,70 +1,114 @@
|
||||
import React from "react";
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Button } from "@/components/ui/button";
|
||||
import Link from "next/link";
|
||||
import { useConfig } from "@/contexts/ConfigContext";
|
||||
import { logoutUser } from "@/handlers/api/user.handler"
|
||||
import { logoutUser } from "@/handlers/api/user.handler";
|
||||
import { useCurrentUser } from "@/contexts/CurrentUserContext";
|
||||
import { useToast } from "../ui/use-toast";
|
||||
import { HandshakeIcon } from "lucide-react";
|
||||
import { useTheme } from "next-themes";
|
||||
import { Tooltip } from "@/components/ui/tooltip";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { HandshakeIcon, Server, Globe, LogOut, Moon, Sun, User, Settings } from "lucide-react";
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
export default function ProfileInfo() {
|
||||
const { updateContext, ...user } = useCurrentUser()
|
||||
const { updateContext, ...user } = useCurrentUser();
|
||||
const { immichURL, exImmichUrl, version } = useConfig();
|
||||
const { theme, setTheme } = useTheme();
|
||||
const toast = useToast();
|
||||
const router = useRouter();
|
||||
|
||||
const handleLogout = () => logoutUser()
|
||||
.then(() => {
|
||||
updateContext(null)
|
||||
}).catch((error) => {
|
||||
toast.toast({
|
||||
title: "Error",
|
||||
description: error.message,
|
||||
})
|
||||
})
|
||||
|
||||
const handleLogout = () =>
|
||||
logoutUser()
|
||||
.then(() => updateContext(null))
|
||||
.catch((error) => {
|
||||
toast.toast({ title: "Error", description: error.message });
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col gap-2 text-xs text-center py-2">
|
||||
<p className="text-muted-foreground font-mono">Connected to (External)</p>
|
||||
<Link href={exImmichUrl} target="_blank" className="font-mono">
|
||||
{exImmichUrl}
|
||||
</Link>
|
||||
<p className="text-muted-foreground font-mono">Connected to (Internal)</p>
|
||||
<Link href={immichURL} target="_blank" className="font-mono">
|
||||
{immichURL}
|
||||
</Link>
|
||||
{user && (
|
||||
<>
|
||||
<p className="text-sm">{user?.name}</p>
|
||||
<div className="flex items-center justify-between gap-2 px-2">
|
||||
{!user.isUsingAPIKey && (
|
||||
<Button variant="destructive" className="h-6 flex-1 text-xs" onClick={handleLogout}>
|
||||
Log Out
|
||||
</Button>
|
||||
)}
|
||||
<Button asChild variant="secondary" className="h-6 flex-1 text-xs flex items-center justify-center gap-2" onClick={handleLogout}>
|
||||
<Link href="https://buymeacoffee.com/varunraj" target="_blank">
|
||||
<HandshakeIcon className="w-4 h-4" />
|
||||
{/* Connection info */}
|
||||
<div className="border-t px-3 py-2 space-y-1">
|
||||
<Tooltip content={`External: ${exImmichUrl}`}>
|
||||
<div className="flex items-center gap-1.5 text-[10px] text-muted-foreground">
|
||||
<Globe className="h-3 w-3 shrink-0" />
|
||||
<Link href={exImmichUrl} target="_blank" className="font-mono truncate hover:text-foreground transition-colors">
|
||||
{exImmichUrl}
|
||||
</Link>
|
||||
</div>
|
||||
</Tooltip>
|
||||
<Tooltip content={`Internal: ${immichURL}`}>
|
||||
<div className="flex items-center gap-1.5 text-[10px] text-muted-foreground">
|
||||
<Server className="h-3 w-3 shrink-0" />
|
||||
<Link href={immichURL} target="_blank" className="font-mono truncate hover:text-foreground transition-colors">
|
||||
{immichURL}
|
||||
</Link>
|
||||
</div>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
{/* User dropdown */}
|
||||
{user && (
|
||||
<div className="border-t px-2 py-2">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="flex items-center gap-2 w-full px-2 py-1.5 rounded-lg hover:bg-muted transition-colors text-left">
|
||||
<div className="h-7 w-7 rounded-full bg-primary/10 flex items-center justify-center shrink-0">
|
||||
<User className="h-3.5 w-3.5 text-primary" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm font-medium truncate">{user.name}</p>
|
||||
<p className="text-[10px] text-muted-foreground truncate">{user.email}</p>
|
||||
</div>
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="top" align="start" className="w-52">
|
||||
<DropdownMenuLabel className="text-xs font-normal text-muted-foreground">{user.email}</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onClick={() => setTheme(theme === "light" ? "dark" : "light")} className="cursor-pointer">
|
||||
{theme === "light" ? <Moon className="h-4 w-4 mr-2" /> : <Sun className="h-4 w-4 mr-2" />}
|
||||
{theme === "light" ? "Dark Mode" : "Light Mode"}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => router.push("/settings")} className="cursor-pointer">
|
||||
<Settings className="h-4 w-4 mr-2" />
|
||||
Settings
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem asChild className="cursor-pointer">
|
||||
<Link href="https://buymeacoffee.com/varunraj" target="_blank">
|
||||
<HandshakeIcon className="h-4 w-4 mr-2" />
|
||||
Support
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="border-t text-muted-foreground text-xs py-2 flex justify-between items-center px-2">
|
||||
</DropdownMenuItem>
|
||||
{!user.isUsingAPIKey && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onClick={handleLogout} className="cursor-pointer text-destructive focus:text-destructive">
|
||||
<LogOut className="h-4 w-4 mr-2" />
|
||||
Log Out
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Footer */}
|
||||
<div className="border-t text-muted-foreground text-[10px] py-1.5 flex justify-between items-center px-3">
|
||||
<p>
|
||||
Made with <span className="text-red-500">♥</span> by{" "}
|
||||
<Link
|
||||
target="_blank"
|
||||
href="https://x.com/zathvarun"
|
||||
className="text-primary"
|
||||
>
|
||||
<Link target="_blank" href="https://x.com/zathvarun" className="text-primary">
|
||||
@zathvarun
|
||||
</Link>
|
||||
</p>
|
||||
<Link target="_blank" href={`https://github.com/varun-raj/immich-power-tools/releases/tag/v${version}`}>
|
||||
<Link target="_blank" href={`https://github.com/varun-raj/immich-power-tools/releases/tag/v${version}`} className="font-mono">
|
||||
v{version}
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import Link from "next/link";
|
||||
|
||||
import { sidebarNavs } from "@/config/constants/sidebarNavs";
|
||||
import { sidebarGroups } from "@/config/constants/sidebarNavs";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
import dynamic from "next/dynamic";
|
||||
import ProfileInfo from "./ProfileInfo";
|
||||
|
||||
const ThemeSwitcher = dynamic(() => import("@/components/shared/ThemeSwitcher"), {
|
||||
ssr: false,
|
||||
});
|
||||
const ProfileInfo = dynamic(() => import("./ProfileInfo"), { ssr: false });
|
||||
|
||||
export default function Sidebar() {
|
||||
const router = useRouter();
|
||||
@@ -29,24 +26,32 @@ export default function Sidebar() {
|
||||
/>
|
||||
<span className="">Immich Power Tools</span>
|
||||
</Link>
|
||||
<ThemeSwitcher />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<nav className="grid items-start px-2 text-sm font-medium lg:px-4">
|
||||
{sidebarNavs.map((nav) => (
|
||||
<Link
|
||||
key={nav.title}
|
||||
href={nav.link}
|
||||
className={cn(
|
||||
"flex items-center gap-3 rounded-lg py-2 text-muted-foreground transition-all hover:text-primary",
|
||||
{
|
||||
"text-primary": pathname === nav.link,
|
||||
}
|
||||
)}
|
||||
>
|
||||
{nav.icon}
|
||||
{nav.title}
|
||||
</Link>
|
||||
<div className="flex-1 overflow-y-auto">
|
||||
<nav className="px-2 lg:px-4 space-y-4 py-2">
|
||||
{sidebarGroups.map((group) => (
|
||||
<div key={group.label}>
|
||||
<p className="text-[10px] font-semibold uppercase tracking-wider text-muted-foreground/60 px-3 mb-1">
|
||||
{group.label}
|
||||
</p>
|
||||
<div className="space-y-0.5">
|
||||
{group.items.map((nav) => (
|
||||
<Link
|
||||
key={nav.title}
|
||||
href={nav.link}
|
||||
className={cn(
|
||||
"flex items-center gap-3 rounded-lg py-1.5 px-3 text-sm text-muted-foreground transition-all hover:text-primary",
|
||||
{
|
||||
"text-primary bg-primary/5 font-medium": pathname === nav.link,
|
||||
}
|
||||
)}
|
||||
>
|
||||
{nav.icon}
|
||||
{nav.title}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
@@ -1,77 +1,51 @@
|
||||
import { Copy, GalleryHorizontal, GalleryVerticalEnd, Image as ImageIcon, MapPin, MapPinX, PackageSearch, Rewind, Search, Settings, Share2, User, Video, Workflow } from "lucide-react";
|
||||
|
||||
export const sidebarNavs = [
|
||||
// {
|
||||
// title: "Rewind 2024",
|
||||
// link: "/rewind",
|
||||
// icon: <Rewind className="h-4 w-4" />,
|
||||
// },
|
||||
{
|
||||
title: "Find Assets",
|
||||
link: "/find",
|
||||
icon: <Search className="h-4 w-4" />,
|
||||
},
|
||||
{
|
||||
title: "Manage People",
|
||||
link: "/",
|
||||
icon: <User className="h-4 w-4" />,
|
||||
},
|
||||
{
|
||||
title: "Analytics",
|
||||
link: "/analytics/exif",
|
||||
icon: <ImageIcon className="h-4 w-4" />,
|
||||
},
|
||||
{
|
||||
title: "Potential Albums",
|
||||
link: "/albums/potential-albums",
|
||||
icon: <GalleryVerticalEnd className="h-4 w-4" />,
|
||||
},
|
||||
{
|
||||
title: "Missing Locations",
|
||||
link: "/assets/missing-locations",
|
||||
icon: <MapPinX className="h-4 w-4" />,
|
||||
},
|
||||
{
|
||||
title: "Manage Albums",
|
||||
link: "/albums",
|
||||
icon: <GalleryHorizontal className="h-4 w-4" />,
|
||||
},
|
||||
{
|
||||
title: "Import shared",
|
||||
link: "/assets/import-shared",
|
||||
icon: <Share2 className="h-4 w-4" />,
|
||||
},
|
||||
interface SidebarNav {
|
||||
title: string;
|
||||
link: string;
|
||||
icon: React.ReactNode;
|
||||
}
|
||||
|
||||
interface SidebarGroup {
|
||||
label: string;
|
||||
items: SidebarNav[];
|
||||
}
|
||||
|
||||
export const sidebarGroups: SidebarGroup[] = [
|
||||
{
|
||||
title: "Geo Heatmap",
|
||||
link: "/assets/geo-heatmap",
|
||||
icon: <MapPin className="h-4 w-4" />,
|
||||
},
|
||||
// Empty Videos
|
||||
{
|
||||
title: "Empty Videos",
|
||||
link: "/assets/empty-videos",
|
||||
icon: <Video className="h-4 w-4" />,
|
||||
},
|
||||
// Bulk Duplicate
|
||||
{
|
||||
title: "Bulk Duplicate Finder",
|
||||
link: "/assets/bulk-duplicate-finder",
|
||||
icon: <Copy className="h-4 w-4" />,
|
||||
label: "Library",
|
||||
items: [
|
||||
{ title: "Find Assets", link: "/find", icon: <Search className="h-4 w-4" /> },
|
||||
{ title: "Manage People", link: "/", icon: <User className="h-4 w-4" /> },
|
||||
{ title: "Manage Albums", link: "/albums", icon: <GalleryHorizontal className="h-4 w-4" /> },
|
||||
{ title: "Analytics", link: "/analytics/exif", icon: <ImageIcon className="h-4 w-4" /> },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Workflows",
|
||||
link: "/workflows",
|
||||
icon: <Workflow className="h-4 w-4" />,
|
||||
label: "Tools",
|
||||
items: [
|
||||
{ title: "Potential Albums", link: "/albums/potential-albums", icon: <GalleryVerticalEnd className="h-4 w-4" /> },
|
||||
{ title: "Missing Locations", link: "/assets/missing-locations", icon: <MapPinX className="h-4 w-4" /> },
|
||||
{ title: "Empty Videos", link: "/assets/empty-videos", icon: <Video className="h-4 w-4" /> },
|
||||
{ title: "Bulk Duplicate Finder", link: "/assets/bulk-duplicate-finder", icon: <Copy className="h-4 w-4" /> },
|
||||
{ title: "Orphan Finder", link: "/assets/orphan-finder", icon: <PackageSearch className="h-4 w-4" /> },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Orphan Finder",
|
||||
link: "/assets/orphan-finder",
|
||||
icon: <PackageSearch className="h-4 w-4" />,
|
||||
label: "Automation",
|
||||
items: [
|
||||
{ title: "Workflows", link: "/workflows", icon: <Workflow className="h-4 w-4" /> },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Settings",
|
||||
link: "/settings",
|
||||
icon: <Settings className="h-4 w-4" />,
|
||||
label: "Other",
|
||||
items: [
|
||||
{ title: "Geo Heatmap", link: "/assets/geo-heatmap", icon: <MapPin className="h-4 w-4" /> },
|
||||
{ title: "Import Shared", link: "/assets/import-shared", icon: <Share2 className="h-4 w-4" /> },
|
||||
{ title: "Settings", link: "/settings", icon: <Settings className="h-4 w-4" /> },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
// Flat list for backward compat (mobile menu)
|
||||
export const sidebarNavs = sidebarGroups.flatMap((g) => g.items);
|
||||
@@ -0,0 +1,103 @@
|
||||
import { ENV } from "@/config/environment";
|
||||
import { getCurrentUser } from "@/handlers/serverUtils/user.utils";
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
const REQUIRED_PERMISSIONS = [
|
||||
"asset.read",
|
||||
"asset.update",
|
||||
"album.create",
|
||||
"album.update",
|
||||
"tag.create",
|
||||
];
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (req.method !== "POST") return res.status(405).json({ message: "Method not allowed" });
|
||||
|
||||
const currentUser = await getCurrentUser(req);
|
||||
if (!currentUser) return res.status(401).json({ message: "Unauthorized" });
|
||||
|
||||
const { apiKey } = req.body;
|
||||
if (!apiKey) return res.status(400).json({ message: "apiKey is required" });
|
||||
|
||||
try {
|
||||
// Validate by calling Immich's auth endpoint with the key
|
||||
const authRes = await fetch(`${ENV.IMMICH_URL}/api/users/me`, {
|
||||
headers: { "x-api-key": apiKey },
|
||||
});
|
||||
|
||||
if (!authRes.ok) {
|
||||
return res.status(200).json({
|
||||
valid: false,
|
||||
error: "Invalid API key — could not authenticate with Immich",
|
||||
permissions: [],
|
||||
missing: REQUIRED_PERMISSIONS,
|
||||
});
|
||||
}
|
||||
|
||||
// Get the API key details to check permissions
|
||||
const keysRes = await fetch(`${ENV.IMMICH_URL}/api/api-keys`, {
|
||||
headers: { "x-api-key": apiKey },
|
||||
});
|
||||
|
||||
if (!keysRes.ok) {
|
||||
// Can authenticate but can't list keys — might be a full-access key
|
||||
return res.status(200).json({
|
||||
valid: true,
|
||||
error: null,
|
||||
permissions: ["all (could not verify individual permissions)"],
|
||||
missing: [],
|
||||
});
|
||||
}
|
||||
|
||||
const keys = await keysRes.json();
|
||||
|
||||
// Find the key being used — it's the one that matches our request
|
||||
// Immich doesn't directly tell us which key is in use, so check all permissions across all keys
|
||||
// The safest check: try to access endpoints that require each permission
|
||||
const permissionChecks = await Promise.all([
|
||||
// asset.read — try searching assets
|
||||
fetch(`${ENV.IMMICH_URL}/api/assets?take=1`, {
|
||||
headers: { "x-api-key": apiKey },
|
||||
}).then((r) => ({ permission: "asset.read", granted: r.ok })),
|
||||
|
||||
// asset.update — try a dry validation (we just check if the endpoint doesn't 403)
|
||||
fetch(`${ENV.IMMICH_URL}/api/assets`, {
|
||||
method: "PUT",
|
||||
headers: { "x-api-key": apiKey, "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ ids: [], isFavorite: true }),
|
||||
}).then((r) => ({ permission: "asset.update", granted: r.status !== 403 })),
|
||||
|
||||
// album.create — check via OPTIONS or a minimal request
|
||||
fetch(`${ENV.IMMICH_URL}/api/albums`, {
|
||||
headers: { "x-api-key": apiKey },
|
||||
}).then((r) => ({ permission: "album.create", granted: r.ok })),
|
||||
|
||||
// album.update — same endpoint access implies read+write
|
||||
fetch(`${ENV.IMMICH_URL}/api/albums`, {
|
||||
headers: { "x-api-key": apiKey },
|
||||
}).then((r) => ({ permission: "album.update", granted: r.ok })),
|
||||
|
||||
// tag.create
|
||||
fetch(`${ENV.IMMICH_URL}/api/tags`, {
|
||||
headers: { "x-api-key": apiKey },
|
||||
}).then((r) => ({ permission: "tag.create", granted: r.ok || r.status !== 403 })),
|
||||
]);
|
||||
|
||||
const granted = permissionChecks.filter((p) => p.granted).map((p) => p.permission);
|
||||
const missing = REQUIRED_PERMISSIONS.filter((p) => !granted.includes(p));
|
||||
|
||||
return res.status(200).json({
|
||||
valid: missing.length === 0,
|
||||
error: missing.length > 0 ? `Missing permissions: ${missing.join(", ")}` : null,
|
||||
permissions: granted,
|
||||
missing,
|
||||
});
|
||||
} catch (error: any) {
|
||||
return res.status(200).json({
|
||||
valid: false,
|
||||
error: `Could not connect to Immich: ${error.message}`,
|
||||
permissions: [],
|
||||
missing: REQUIRED_PERMISSIONS,
|
||||
});
|
||||
}
|
||||
}
|
||||
+221
-82
@@ -6,11 +6,15 @@ import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { RefreshCw, Trash2, Save, Eye, EyeOff } from "lucide-react";
|
||||
import {
|
||||
RefreshCw, Trash2, Save, Eye, EyeOff, ExternalLink,
|
||||
Key, Workflow, Shield, CheckCircle, XCircle, Server, Globe,
|
||||
} from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import API from "@/lib/api";
|
||||
import { useConfig } from "@/contexts/ConfigContext";
|
||||
import Link from "next/link";
|
||||
|
||||
interface ApiKey {
|
||||
id: string;
|
||||
@@ -19,33 +23,90 @@ interface ApiKey {
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
function ConnectionStatus({ label, url, icon: Icon }: { label: string; url: string; icon: any }) {
|
||||
return (
|
||||
<div className="flex items-center justify-between py-2">
|
||||
<div className="flex items-center gap-2.5">
|
||||
<Icon className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-sm text-muted-foreground">{label}</span>
|
||||
</div>
|
||||
{url ? (
|
||||
<div className="flex items-center gap-1.5">
|
||||
<CheckCircle className="h-3.5 w-3.5 text-green-500" />
|
||||
<span className="text-xs font-mono text-foreground">{url}</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-center gap-1.5">
|
||||
<XCircle className="h-3.5 w-3.5 text-destructive" />
|
||||
<span className="text-xs text-muted-foreground">Not configured</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function SettingsPage() {
|
||||
const { exImmichUrl, immichURL, version, aiEnabled } = useConfig();
|
||||
const [keys, setKeys] = useState<ApiKey[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [deleting, setDeleting] = useState<string | null>(null);
|
||||
const [regenerating, setRegenerating] = useState<string | null>(null);
|
||||
|
||||
// Workflow API key
|
||||
const [workflowApiKey, setWorkflowApiKey] = useState("");
|
||||
const [workflowApiKeyLoading, setWorkflowApiKeyLoading] = useState(false);
|
||||
const [showWorkflowApiKey, setShowWorkflowApiKey] = useState(false);
|
||||
const [workflowApiKeySaved, setWorkflowApiKeySaved] = useState(false);
|
||||
const [validationResult, setValidationResult] = useState<{
|
||||
valid: boolean; error: string | null; permissions: string[]; missing: string[];
|
||||
} | null>(null);
|
||||
|
||||
const fetchWorkflowApiKey = async () => {
|
||||
try {
|
||||
const data = await API.get("/api/settings/kv/workflow_api_key");
|
||||
setWorkflowApiKey(data.value || "");
|
||||
setWorkflowApiKeySaved(!!data.value);
|
||||
} catch {
|
||||
// Not set yet
|
||||
setWorkflowApiKeySaved(false);
|
||||
}
|
||||
};
|
||||
|
||||
const saveWorkflowApiKey = async () => {
|
||||
if (!workflowApiKey.trim()) {
|
||||
// Clear the key
|
||||
setWorkflowApiKeyLoading(true);
|
||||
try {
|
||||
await API.put("/api/settings/kv/workflow_api_key", { value: "" });
|
||||
setWorkflowApiKeySaved(false);
|
||||
setValidationResult(null);
|
||||
toast.success("Workflow API key cleared");
|
||||
} catch {
|
||||
toast.error("Failed to clear workflow API key");
|
||||
}
|
||||
setWorkflowApiKeyLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setWorkflowApiKeyLoading(true);
|
||||
setValidationResult(null);
|
||||
toast("Validating API key...");
|
||||
|
||||
try {
|
||||
// Validate first
|
||||
const result = await API.post("/api/settings/validate-api-key", { apiKey: workflowApiKey });
|
||||
setValidationResult(result);
|
||||
|
||||
if (!result.valid) {
|
||||
toast.error(result.error || "API key validation failed");
|
||||
setWorkflowApiKeyLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Valid — save it
|
||||
await API.put("/api/settings/kv/workflow_api_key", { value: workflowApiKey });
|
||||
toast.success("Workflow API key saved");
|
||||
setWorkflowApiKeySaved(true);
|
||||
toast.success("API key validated and saved");
|
||||
} catch {
|
||||
toast.error("Failed to save workflow API key");
|
||||
toast.error("Failed to validate API key");
|
||||
}
|
||||
setWorkflowApiKeyLoading(false);
|
||||
};
|
||||
@@ -55,9 +116,7 @@ export default function SettingsPage() {
|
||||
try {
|
||||
const data = await getApiKeys();
|
||||
setKeys(data);
|
||||
} catch {
|
||||
// silently fail — keys list stays empty
|
||||
}
|
||||
} catch {}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
@@ -93,60 +152,182 @@ export default function SettingsPage() {
|
||||
return (
|
||||
<PageLayout>
|
||||
<Header leftComponent="Settings" />
|
||||
<div className="p-6 flex flex-col gap-6 max-w-2xl">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>API Keys</CardTitle>
|
||||
<CardDescription>
|
||||
Managed API keys created by Power Tools in your Immich instance.
|
||||
These are used internally for features that require unauthenticated access (e.g. share links).
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{loading && (
|
||||
<p className="text-sm text-muted-foreground">Loading...</p>
|
||||
<div className="p-6 max-w-2xl space-y-8">
|
||||
|
||||
{/* Connection Info */}
|
||||
<section>
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Server className="h-4 w-4 text-muted-foreground" />
|
||||
<h2 className="text-sm font-semibold tracking-wide uppercase text-muted-foreground">Connection</h2>
|
||||
{version && <Badge variant="outline" className="text-[10px] h-4 ml-auto font-mono">v{version}</Badge>}
|
||||
</div>
|
||||
<div className="border rounded-lg px-4 divide-y">
|
||||
<ConnectionStatus label="Internal URL" url={immichURL} icon={Server} />
|
||||
<ConnectionStatus label="External URL" url={exImmichUrl} icon={Globe} />
|
||||
<div className="flex items-center justify-between py-2">
|
||||
<div className="flex items-center gap-2.5">
|
||||
<Shield className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-sm text-muted-foreground">AI Search</span>
|
||||
</div>
|
||||
<Badge variant={aiEnabled ? "default" : "secondary"} className="text-[10px]">
|
||||
{aiEnabled ? "Enabled" : "Disabled"}
|
||||
</Badge>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Workflow API Key */}
|
||||
<section>
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Workflow className="h-4 w-4 text-muted-foreground" />
|
||||
<h2 className="text-sm font-semibold tracking-wide uppercase text-muted-foreground">Workflow API Key</h2>
|
||||
{workflowApiKeySaved ? (
|
||||
<CheckCircle className="h-3.5 w-3.5 text-green-500 ml-auto" />
|
||||
) : (
|
||||
<XCircle className="h-3.5 w-3.5 text-yellow-500 ml-auto" />
|
||||
)}
|
||||
{!loading && keys.length === 0 && (
|
||||
<p className="text-sm text-muted-foreground">No API keys created yet.</p>
|
||||
</div>
|
||||
<div className="border rounded-lg p-4 space-y-3">
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Immich API key used by workflows for scheduled and webhook-triggered runs.
|
||||
Needs permissions for assets, albums, and tags.
|
||||
</p>
|
||||
<div className="flex gap-2">
|
||||
<div className="relative flex-1">
|
||||
<Input
|
||||
id="workflowApiKey"
|
||||
type={showWorkflowApiKey ? "text" : "password"}
|
||||
className="h-9 text-sm font-mono pr-10"
|
||||
placeholder="Paste your Immich API key here"
|
||||
value={workflowApiKey}
|
||||
onChange={(e) => setWorkflowApiKey(e.target.value)}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors"
|
||||
onClick={() => setShowWorkflowApiKey((v) => !v)}
|
||||
>
|
||||
{showWorkflowApiKey ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
|
||||
</button>
|
||||
</div>
|
||||
<Button size="sm" className="h-9" onClick={saveWorkflowApiKey} disabled={workflowApiKeyLoading}>
|
||||
<Save className="h-3.5 w-3.5 mr-1" />
|
||||
{workflowApiKeyLoading ? "Saving..." : "Save"}
|
||||
</Button>
|
||||
</div>
|
||||
{validationResult && (
|
||||
<div className={`rounded-md p-2.5 text-xs ${validationResult.valid ? "bg-green-500/10 border border-green-500/20" : "bg-destructive/10 border border-destructive/20"}`}>
|
||||
<div className="flex items-center gap-1.5 mb-1.5">
|
||||
{validationResult.valid ? (
|
||||
<><CheckCircle className="h-3.5 w-3.5 text-green-500" /><span className="font-medium text-green-600 dark:text-green-400">All permissions verified</span></>
|
||||
) : (
|
||||
<><XCircle className="h-3.5 w-3.5 text-destructive" /><span className="font-medium text-destructive">{validationResult.error}</span></>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{["asset.read", "asset.update", "album.create", "album.update", "tag.create"].map((p) => {
|
||||
const granted = validationResult.permissions.includes(p);
|
||||
const missing = validationResult.missing.includes(p);
|
||||
return (
|
||||
<Badge
|
||||
key={p}
|
||||
variant="outline"
|
||||
className={`text-[10px] h-5 font-mono font-normal ${granted ? "border-green-500/40 text-green-600 dark:text-green-400" : missing ? "border-destructive/40 text-destructive" : ""}`}
|
||||
>
|
||||
{granted ? "✓" : "✗"} {p}
|
||||
</Badge>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{!loading && keys.length > 0 && (
|
||||
<ul className="flex flex-col divide-y">
|
||||
{!validationResult && (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{["asset.read", "asset.update", "album.create", "album.update", "tag.create"].map((p) => (
|
||||
<Badge key={p} variant="outline" className="text-[10px] h-5 font-mono font-normal">{p}</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center justify-between">
|
||||
<p className="text-[10px] text-muted-foreground">Required permissions</p>
|
||||
{exImmichUrl && (
|
||||
<Link
|
||||
href={`${exImmichUrl}/user-settings?isOpen=api-keys`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="flex items-center gap-1 text-xs text-primary hover:underline shrink-0 ml-3"
|
||||
>
|
||||
Create in Immich
|
||||
<ExternalLink className="h-3 w-3" />
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Managed API Keys */}
|
||||
<section>
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Key className="h-4 w-4 text-muted-foreground" />
|
||||
<h2 className="text-sm font-semibold tracking-wide uppercase text-muted-foreground">Managed API Keys</h2>
|
||||
<span className="text-xs text-muted-foreground ml-auto">{keys.length} key{keys.length !== 1 ? "s" : ""}</span>
|
||||
</div>
|
||||
<div className="border rounded-lg">
|
||||
{loading ? (
|
||||
<div className="px-4 py-6 text-center">
|
||||
<p className="text-sm text-muted-foreground">Loading...</p>
|
||||
</div>
|
||||
) : keys.length === 0 ? (
|
||||
<div className="px-4 py-6 text-center">
|
||||
<Key className="h-5 w-5 text-muted-foreground/40 mx-auto mb-2" />
|
||||
<p className="text-sm text-muted-foreground">No managed API keys yet.</p>
|
||||
<p className="text-xs text-muted-foreground/60 mt-0.5">Keys are created automatically when needed (e.g. share links).</p>
|
||||
</div>
|
||||
) : (
|
||||
<ul className="divide-y">
|
||||
{keys.map((key) => (
|
||||
<li key={key.id} className="flex items-center justify-between py-3 gap-4">
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-sm font-medium">{key.keyName}</span>
|
||||
<Badge variant="secondary" className="capitalize">{key.purpose}</Badge>
|
||||
<li key={key.id} className="flex items-center justify-between px-4 py-3 gap-4">
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
<div className="h-8 w-8 rounded-lg bg-muted flex items-center justify-center shrink-0">
|
||||
<Key className="h-3.5 w-3.5 text-muted-foreground" />
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-sm font-medium truncate">{key.keyName}</span>
|
||||
<Badge variant="secondary" className="capitalize text-[10px] h-4">{key.purpose}</Badge>
|
||||
</div>
|
||||
<span className="text-[10px] text-muted-foreground">
|
||||
Created {new Date(key.createdAt).toLocaleDateString()}
|
||||
</span>
|
||||
</div>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
Created {new Date(key.createdAt).toLocaleDateString()}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<div className="flex items-center gap-0.5 shrink-0">
|
||||
<AlertDialog
|
||||
title="Regenerate API Key"
|
||||
description={`This will delete the current "${key.keyName}" key from Immich and create a new one. Existing share links will continue to work.`}
|
||||
description={`This will delete the current "${key.keyName}" key from Immich and create a new one.`}
|
||||
onConfirm={() => handleRegenerate(key.purpose)}
|
||||
>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8"
|
||||
disabled={regenerating === key.purpose || deleting === key.purpose}
|
||||
>
|
||||
<RefreshCw className={`h-4 w-4 ${regenerating === key.purpose ? "animate-spin" : ""}`} />
|
||||
<RefreshCw className={`h-3.5 w-3.5 ${regenerating === key.purpose ? "animate-spin" : ""}`} />
|
||||
</Button>
|
||||
</AlertDialog>
|
||||
<AlertDialog
|
||||
title="Delete API Key"
|
||||
description={`This will remove the "${key.keyName}" key from Immich and Power Tools. Share links that depend on it will stop serving thumbnails.`}
|
||||
description={`This will remove the "${key.keyName}" key. Share links that depend on it will stop working.`}
|
||||
onConfirm={() => handleDelete(key.purpose)}
|
||||
>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8"
|
||||
disabled={deleting === key.purpose || regenerating === key.purpose}
|
||||
>
|
||||
<Trash2 className="h-4 w-4 text-destructive" />
|
||||
<Trash2 className="h-3.5 w-3.5 text-destructive" />
|
||||
</Button>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
@@ -154,50 +335,8 @@ export default function SettingsPage() {
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Workflow API Key</CardTitle>
|
||||
<CardDescription>
|
||||
Immich API key used by workflows to execute actions (create albums, favorite, archive, etc.).
|
||||
This key is used for scheduled and webhook-triggered runs. If not set, workflows will use the session of the user who created them.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-3">
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="workflowApiKey" className="text-xs">API Key</Label>
|
||||
<div className="flex gap-2">
|
||||
<div className="relative flex-1">
|
||||
<Input
|
||||
id="workflowApiKey"
|
||||
type={showWorkflowApiKey ? "text" : "password"}
|
||||
className="h-9 text-sm font-mono pr-10"
|
||||
placeholder="Paste your Immich API key here"
|
||||
value={workflowApiKey}
|
||||
onChange={(e) => setWorkflowApiKey(e.target.value)}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => setShowWorkflowApiKey((v) => !v)}
|
||||
>
|
||||
{showWorkflowApiKey ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
|
||||
</button>
|
||||
</div>
|
||||
<Button size="sm" onClick={saveWorkflowApiKey} disabled={workflowApiKeyLoading}>
|
||||
<Save className="h-3.5 w-3.5 mr-1" />
|
||||
{workflowApiKeyLoading ? "Saving..." : "Save"}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-[10px] text-muted-foreground">
|
||||
Create an API key in Immich (Account Settings → API Keys) with full permissions, then paste it here.
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</PageLayout>
|
||||
);
|
||||
|
||||
@@ -30,10 +30,11 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { ASSET_THUMBNAIL_PATH } from "@/config/routes";
|
||||
import { IWorkflowRun } from "@/types/workflow";
|
||||
import { ArrowLeft, Play, Save, Clock, Webhook, History, ChevronUp, ChevronDown, Bug } from "lucide-react";
|
||||
import { ArrowLeft, Play, Save, Clock, Webhook, History, ChevronUp, ChevronDown, Bug, TriangleAlert } from "lucide-react";
|
||||
import { format } from "date-fns";
|
||||
import Link from "next/link";
|
||||
import Loader from "@/components/ui/loader";
|
||||
import API from "@/lib/api";
|
||||
|
||||
function generateId() {
|
||||
return Math.random().toString(36).substring(2, 15);
|
||||
@@ -229,6 +230,7 @@ function WorkflowEditorInner() {
|
||||
const [runs, setRuns] = useState<IWorkflowRun[]>([]);
|
||||
const [showRuns, setShowRuns] = useState(false);
|
||||
const [expandedRunId, setExpandedRunId] = useState<string | null>(null);
|
||||
const [hasApiKey, setHasApiKey] = useState<boolean | null>(null);
|
||||
|
||||
const [nodes, setNodes, onNodesChange] = useNodesState([] as Node[]);
|
||||
const [edges, setEdges, onEdgesChange] = useEdgesState([] as Edge[]);
|
||||
@@ -252,6 +254,9 @@ function WorkflowEditorInner() {
|
||||
.finally(() => setLoading(false));
|
||||
|
||||
getWorkflowRuns(id).then(setRuns).catch(() => {});
|
||||
API.get("/api/settings/kv/workflow_api_key")
|
||||
.then((data) => setHasApiKey(!!data?.value))
|
||||
.catch(() => setHasApiKey(false));
|
||||
}, [id]);
|
||||
|
||||
const onConnect = useCallback((connection: Connection) => {
|
||||
@@ -466,6 +471,46 @@ function WorkflowEditorInner() {
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
||||
{/* API Key warning */}
|
||||
{hasApiKey === false && (
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button variant="ghost" size="sm" className="h-8 text-yellow-500 hover:text-yellow-600">
|
||||
<TriangleAlert className="h-4 w-4 mr-1" />
|
||||
<span className="text-xs">API Key Missing</span>
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-80" align="end">
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-start gap-2">
|
||||
<TriangleAlert className="h-4 w-4 text-yellow-500 mt-0.5 shrink-0" />
|
||||
<div>
|
||||
<p className="text-sm font-medium">Workflow API Key Not Configured</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Workflows need a dedicated Immich API key to execute actions like creating albums, favoriting assets, and managing tags.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="border rounded p-2 bg-muted/50">
|
||||
<p className="text-xs font-medium mb-1">Required Permissions:</p>
|
||||
<ul className="text-[10px] text-muted-foreground space-y-0.5">
|
||||
<li>- <strong>asset.read</strong> — Query and filter assets</li>
|
||||
<li>- <strong>asset.update</strong> — Favorite, archive, update metadata</li>
|
||||
<li>- <strong>album.create</strong> — Create new albums</li>
|
||||
<li>- <strong>album.update</strong> — Add/remove assets from albums</li>
|
||||
<li>- <strong>tag.create</strong> — Create and assign tags</li>
|
||||
</ul>
|
||||
</div>
|
||||
<Link href="/settings" className="block">
|
||||
<Button size="sm" className="w-full h-7 text-xs">
|
||||
Configure in Settings
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
)}
|
||||
|
||||
<div className="ml-auto flex items-center gap-2">
|
||||
<Button variant="outline" size="sm" onClick={() => handleRun("debug")} disabled={running}>
|
||||
<Bug className="h-3.5 w-3.5 mr-1" />
|
||||
|
||||
Reference in new issue
Block a user