feat: import API key, people card redesign, birthday popover, autocomplete portal
- Add import_api_key setting with auto-generate endpoint and settings UI - Import job runner uses import API key when available, falls back to session - Show ApiKeyGate empty state in both workflow and import pages when key missing - Replace workflow API key warning popover with full gate overlay - Redesign person cards: square avatar, hover action toolbar, cleaner layout - Birthday field now uses popover with calendar + natural language input - Fix autocomplete dropdown clipping inside overflow-hidden cards via portal - People grid column slider persisted to localStorage (min 3, max 20)
This commit is contained in:
1 parent
6a5b2b442a
commit
e47e99ccfc
10 files changed
+626
-266
No files matched your search
@@ -8,6 +8,15 @@ import { useRouter } from "next/router";
|
|||||||
import PeopleFilterContext from "@/contexts/PeopleFilterContext";
|
import PeopleFilterContext from "@/contexts/PeopleFilterContext";
|
||||||
import PageLayout from "../layouts/PageLayout";
|
import PageLayout from "../layouts/PageLayout";
|
||||||
import Header from "../shared/Header";
|
import Header from "../shared/Header";
|
||||||
|
import { Users } from "lucide-react";
|
||||||
|
|
||||||
|
const COLS_KEY = "people_grid_cols";
|
||||||
|
|
||||||
|
function getStoredCols(): number {
|
||||||
|
if (typeof window === "undefined") return 6;
|
||||||
|
const v = parseInt(localStorage.getItem(COLS_KEY) || "", 10);
|
||||||
|
return isNaN(v) ? 6 : Math.min(20, Math.max(3, v));
|
||||||
|
}
|
||||||
|
|
||||||
export default function PeopleList() {
|
export default function PeopleList() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -15,12 +24,22 @@ export default function PeopleList() {
|
|||||||
const [count, setCount] = useState(0);
|
const [count, setCount] = useState(0);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||||
|
const [cols, setCols] = useState<number>(6);
|
||||||
const [filters, setFilters] = useState<IPersonListFilters>({
|
const [filters, setFilters] = useState<IPersonListFilters>({
|
||||||
...router.query,
|
...router.query,
|
||||||
page: 1,
|
page: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Hydrate cols from localStorage after mount
|
||||||
|
useEffect(() => {
|
||||||
|
setCols(getStoredCols());
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleColsChange = (val: number) => {
|
||||||
|
setCols(val);
|
||||||
|
localStorage.setItem(COLS_KEY, String(val));
|
||||||
|
};
|
||||||
|
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
@@ -38,29 +57,36 @@ export default function PeopleList() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleRemove = (person: IPerson) => {
|
const handleRemove = (person: IPerson) => {
|
||||||
setPeople((prev) => prev.filter((p) => {
|
setPeople((prev) => prev.filter((p) => p.id !== person.id));
|
||||||
return p.id !== person.id
|
};
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!router.isReady) return;
|
if (!router.isReady) return;
|
||||||
fetchData();
|
fetchData();
|
||||||
}, [filters]);
|
}, [filters]);
|
||||||
|
|
||||||
|
|
||||||
const renderContent = () => {
|
const renderContent = () => {
|
||||||
if (loading) return <Loader />;
|
if (loading) return <Loader />;
|
||||||
if (errorMessage) return <div>{errorMessage}</div>;
|
if (errorMessage) return <div className="p-4 text-sm text-destructive">{errorMessage}</div>;
|
||||||
|
if (!people.length) return (
|
||||||
|
<div className="flex flex-col items-center justify-center py-20 gap-3 text-muted-foreground">
|
||||||
|
<Users className="h-10 w-10 opacity-30" />
|
||||||
|
<p className="text-sm">No people found</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-5 gap-1 p-2">
|
<div
|
||||||
|
className="grid gap-2 p-3"
|
||||||
|
style={{ gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))` }}
|
||||||
|
>
|
||||||
{people.map((person) => (
|
{people.map((person) => (
|
||||||
<PersonItem person={person} key={person.id} onRemove={handleRemove}/>
|
<PersonItem person={person} key={person.id} onRemove={handleRemove} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PeopleFilterContext.Provider
|
<PeopleFilterContext.Provider
|
||||||
value={{
|
value={{
|
||||||
@@ -69,12 +95,28 @@ export default function PeopleList() {
|
|||||||
setFilters((prev) => ({ ...prev, ...newConfig })),
|
setFilters((prev) => ({ ...prev, ...newConfig })),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PageLayout className="!p-0 !mb-0">
|
<PageLayout className="!p-0 !mb-0 relative">
|
||||||
<Header
|
<Header
|
||||||
leftComponent="Manage People"
|
leftComponent="Manage People"
|
||||||
rightComponent={<PeopleFilters />}
|
rightComponent={<PeopleFilters />}
|
||||||
/>
|
/>
|
||||||
{renderContent()}
|
{renderContent()}
|
||||||
|
|
||||||
|
{/* Grid size slider — fixed bottom-left */}
|
||||||
|
<div className="fixed bottom-4 left-[210px] lg:left-[250px] z-20 flex items-center gap-3 bg-background/90 backdrop-blur-sm border rounded-full px-4 py-2 shadow-md">
|
||||||
|
<Users className="h-3.5 w-3.5 text-muted-foreground shrink-0" />
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min={3}
|
||||||
|
max={20}
|
||||||
|
step={1}
|
||||||
|
value={cols}
|
||||||
|
onChange={(e) => handleColsChange(Number(e.target.value))}
|
||||||
|
className="w-28 h-1.5 appearance-none rounded-full bg-muted cursor-pointer accent-foreground"
|
||||||
|
title={`${cols} per row`}
|
||||||
|
/>
|
||||||
|
<span className="text-xs font-mono text-muted-foreground w-4 text-center">{cols}</span>
|
||||||
|
</div>
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
</PeopleFilterContext.Provider>
|
</PeopleFilterContext.Provider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,102 +1,141 @@
|
|||||||
import { IPerson } from '@/types/person'
|
import { IPerson } from '@/types/person'
|
||||||
import React, { useEffect, useMemo, useState } from 'react'
|
import React, { useEffect, useMemo, useRef, useState } from 'react'
|
||||||
import { DatePicker } from '../ui/datepicker'
|
|
||||||
import { updatePerson } from '@/handlers/api/people.handler';
|
import { updatePerson } from '@/handlers/api/people.handler';
|
||||||
import { Input } from '../ui/input';
|
|
||||||
import { useToast } from '../ui/use-toast';
|
import { useToast } from '../ui/use-toast';
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
|
import { CalendarDays, X } from 'lucide-react';
|
||||||
|
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
|
||||||
|
import { Calendar } from '../ui/calendar';
|
||||||
|
import { Button } from '../ui/button';
|
||||||
|
import { Input } from '../ui/input';
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import chrono from 'chrono-node'
|
import chrono from 'chrono-node'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
person: IPerson
|
person: IPerson
|
||||||
}
|
}
|
||||||
|
|
||||||
const normalizeDateOnly = (value?: Date | string | null): Date | null => {
|
const normalizeDateOnly = (value?: Date | string | null): Date | null => {
|
||||||
if (!value) {
|
if (!value) return null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
const dateOnlyMatch = value.match(/^(\d{4})-(\d{2})-(\d{2})/);
|
const m = value.match(/^(\d{4})-(\d{2})-(\d{2})/);
|
||||||
if (dateOnlyMatch) {
|
if (m) return new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]));
|
||||||
const [, year, month, day] = dateOnlyMatch;
|
|
||||||
return new Date(Number(year), Number(month) - 1, Number(day));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
const d = new Date(value);
|
||||||
const parsedDate = new Date(value);
|
if (Number.isNaN(d.getTime())) return null;
|
||||||
if (Number.isNaN(parsedDate.getTime())) {
|
return new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Date(
|
|
||||||
parsedDate.getUTCFullYear(),
|
|
||||||
parsedDate.getUTCMonth(),
|
|
||||||
parsedDate.getUTCDate()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function PersonBirthdayCell(
|
export default function PersonBirthdayCell({ person }: IProps) {
|
||||||
{ person }: IProps
|
|
||||||
) {
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
|
||||||
const normalizedBirthDate = useMemo(() => normalizeDateOnly(person.birthDate), [person.birthDate]);
|
const normalizedBirthDate = useMemo(() => normalizeDateOnly(person.birthDate), [person.birthDate]);
|
||||||
const [selectedDate, setSelectedDate] = useState<Date | null>(normalizedBirthDate);
|
const [selectedDate, setSelectedDate] = useState<Date | null>(normalizedBirthDate);
|
||||||
const [textDate, setTextDate] = useState<string>(normalizedBirthDate ? format(normalizedBirthDate, 'PPP') : '');
|
const [textInput, setTextInput] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSelectedDate(normalizedBirthDate);
|
setSelectedDate(normalizeDateOnly(person.birthDate));
|
||||||
setTextDate(normalizedBirthDate ? format(normalizedBirthDate, 'PPP') : '');
|
}, [person.birthDate]);
|
||||||
}, [normalizedBirthDate]);
|
|
||||||
|
const handleSave = (date: Date | null) => {
|
||||||
const handleEdit = (date?: Date | null) => {
|
const formatted = date ? format(date, 'yyyy-MM-dd') : null;
|
||||||
const formatedDate = date ? format(date, 'yyyy-MM-dd') : null;
|
|
||||||
setSelectedDate(date || null);
|
|
||||||
setTextDate(date ? format(date, 'PPP') : '');
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
return updatePerson(person.id, {
|
updatePerson(person.id, { birthDate: formatted })
|
||||||
birthDate: formatedDate,
|
|
||||||
})
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
toast({
|
setSelectedDate(date);
|
||||||
title: "Success",
|
setOpen(false);
|
||||||
description: "Person updated successfully",
|
setTextInput('');
|
||||||
})
|
toast({ title: "Birthday saved" });
|
||||||
})
|
})
|
||||||
.catch(() => {})
|
.catch(() => {
|
||||||
.finally(() => {
|
toast({ title: "Error", description: "Failed to save birthday", variant: "destructive" });
|
||||||
setLoading(false);
|
})
|
||||||
});
|
.finally(() => setLoading(false));
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const handleCalendarSelect = (date?: Date) => {
|
||||||
|
handleSave(date ?? null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTextCommit = () => {
|
||||||
|
if (!textInput.trim()) {
|
||||||
|
handleSave(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const parsed = chrono.parseDate(textInput);
|
||||||
|
if (parsed) {
|
||||||
|
handleSave(parsed);
|
||||||
|
} else {
|
||||||
|
toast({ title: "Couldn't parse date", description: 'Try "Jan 1 1990" or "1990-01-01"', variant: "destructive" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClear = (e: React.MouseEvent) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
handleSave(null);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex gap-1'>
|
<Popover open={open} onOpenChange={(v) => { setOpen(v); if (v) setTextInput(''); }}>
|
||||||
<Input
|
<PopoverTrigger asChild>
|
||||||
className=''
|
<button
|
||||||
value={textDate}
|
className="flex items-center gap-1.5 w-full text-left text-xs text-muted-foreground hover:text-foreground transition-colors group/bday"
|
||||||
placeholder='Enter a date'
|
title={selectedDate ? `Birthday: ${format(selectedDate, 'PPP')}` : "Add birthday"}
|
||||||
onKeyDown={(e) => {
|
>
|
||||||
if (e.key === 'Enter') {
|
<CalendarDays size={11} className="shrink-0 opacity-60" />
|
||||||
const parsedDate = chrono.parseDate(textDate || "");
|
{selectedDate ? (
|
||||||
if (parsedDate) {
|
<span className="flex-1 truncate">{format(selectedDate, 'PPP')}</span>
|
||||||
handleEdit(parsedDate);
|
) : (
|
||||||
} else {
|
<span className="italic opacity-50">Add birthday</span>
|
||||||
handleEdit(null);
|
)}
|
||||||
}
|
{selectedDate && (
|
||||||
}
|
<span
|
||||||
}}
|
role="button"
|
||||||
disabled={loading}
|
title="Clear birthday"
|
||||||
onChange={(e) => setTextDate(e.target.value)}
|
onClick={handleClear}
|
||||||
/>
|
className="ml-auto opacity-0 group-hover/bday:opacity-60 hover:!opacity-100 transition-opacity p-0.5 rounded"
|
||||||
<DatePicker date={selectedDate} onSelect={handleEdit} iconOnly/>
|
>
|
||||||
</div>
|
<X size={10} />
|
||||||
)
|
</span>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent className="w-auto p-0" align="start" side="bottom">
|
||||||
|
<div className="p-3 border-b">
|
||||||
|
<p className="text-xs font-medium text-muted-foreground mb-2">Type a date or pick from calendar</p>
|
||||||
|
<div className="flex gap-1.5">
|
||||||
|
<Input
|
||||||
|
className="h-7 text-xs"
|
||||||
|
placeholder='e.g. "Jan 1 1990"'
|
||||||
|
value={textInput}
|
||||||
|
onChange={(e) => setTextInput(e.target.value)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === 'Enter') handleTextCommit();
|
||||||
|
if (e.key === 'Escape') setOpen(false);
|
||||||
|
}}
|
||||||
|
autoFocus
|
||||||
|
disabled={loading}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
className="h-7 text-xs px-2"
|
||||||
|
onClick={handleTextCommit}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
Set
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Calendar
|
||||||
|
mode="single"
|
||||||
|
selected={selectedDate ?? undefined}
|
||||||
|
onSelect={handleCalendarSelect}
|
||||||
|
defaultMonth={selectedDate ?? new Date(1990, 0, 1)}
|
||||||
|
disabled={loading}
|
||||||
|
/>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,22 @@
|
|||||||
import { IPerson } from "@/types/person";
|
import { IPerson } from "@/types/person";
|
||||||
import React, { useRef, useState } from "react";
|
import React, { useRef, useState } from "react";
|
||||||
import { Avatar } from "../ui/avatar";
|
|
||||||
import { mergePerson, searchPeople, updatePerson } from "@/handlers/api/people.handler";
|
import { mergePerson, searchPeople, updatePerson } from "@/handlers/api/people.handler";
|
||||||
import { PersonMergeDropdown } from "./PersonMergeDropdown";
|
import { PersonMergeDropdown } from "./PersonMergeDropdown";
|
||||||
import PersonBirthdayCell from "./PersonBirthdayCell";
|
import PersonBirthdayCell from "./PersonBirthdayCell";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { ArrowUpRight, Info } from "lucide-react";
|
import { ArrowUpRight, Eye, EyeOff, Info } from "lucide-react";
|
||||||
import { useConfig } from "@/contexts/ConfigContext";
|
import { useConfig } from "@/contexts/ConfigContext";
|
||||||
import { useToast } from "../ui/use-toast";
|
import { useToast } from "../ui/use-toast";
|
||||||
import { Badge } from "../ui/badge";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import ShareAssetsTrigger from "../shared/ShareAssetsTrigger";
|
import ShareAssetsTrigger from "../shared/ShareAssetsTrigger";
|
||||||
import { Autocomplete, AutocompleteOption } from "../ui/autocomplete";
|
import { Autocomplete, AutocompleteOption } from "../ui/autocomplete";
|
||||||
import { AlertDialog, IAlertDialogActions } from "../ui/alert-dialog";
|
import { AlertDialog, IAlertDialogActions } from "../ui/alert-dialog";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
person: IPerson;
|
person: IPerson;
|
||||||
onRemove: (person: IPerson) => void;
|
onRemove: (person: IPerson) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function PersonItem({ person, onRemove }: IProps) {
|
export default function PersonItem({ person, onRemove }: IProps) {
|
||||||
const { exImmichUrl } = useConfig();
|
const { exImmichUrl } = useConfig();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
@@ -30,26 +29,15 @@ export default function PersonItem({ person, onRemove }: IProps) {
|
|||||||
const handleEdit = () => {
|
const handleEdit = () => {
|
||||||
if (formData.name && formData.name !== person.name) {
|
if (formData.name && formData.name !== person.name) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
return updatePerson(person.id, {
|
return updatePerson(person.id, { name: formData.name })
|
||||||
name: formData.name,
|
|
||||||
})
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
setEditMode(!editMode);
|
setEditMode(false);
|
||||||
toast({
|
toast({ title: "Success", description: "Person updated successfully" });
|
||||||
title: "Success",
|
|
||||||
description: "Person updated successfully",
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
toast({
|
toast({ title: "Error", description: "Failed to update person", variant: "destructive" });
|
||||||
title: "Error",
|
|
||||||
description: "Failed to update person",
|
|
||||||
variant: "destructive",
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => setLoading(false));
|
||||||
setLoading(false);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
setEditMode(!editMode);
|
setEditMode(!editMode);
|
||||||
}
|
}
|
||||||
@@ -57,19 +45,10 @@ export default function PersonItem({ person, onRemove }: IProps) {
|
|||||||
|
|
||||||
const handleHide = (hidden: boolean) => {
|
const handleHide = (hidden: boolean) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
return updatePerson(person.id, {
|
return updatePerson(person.id, { isHidden: hidden })
|
||||||
isHidden: hidden,
|
.then(() => setFormData((p) => ({ ...p, isHidden: hidden })))
|
||||||
})
|
.catch(() => {})
|
||||||
.then(() => {
|
.finally(() => setLoading(false));
|
||||||
setFormData((person) => ({
|
|
||||||
...person,
|
|
||||||
isHidden: hidden,
|
|
||||||
}));
|
|
||||||
})
|
|
||||||
.catch(() => { })
|
|
||||||
.finally(() => {
|
|
||||||
setLoading(false);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMerge = async (option: AutocompleteOption) => {
|
const handleMerge = async (option: AutocompleteOption) => {
|
||||||
@@ -79,87 +58,125 @@ export default function PersonItem({ person, onRemove }: IProps) {
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"flex flex-col rounded-lg pb-2 border border-2 border-transparent items-center gap-2",
|
"group relative flex flex-col rounded-xl overflow-hidden border bg-card transition-all duration-200",
|
||||||
|
"hover:shadow-lg hover:border-border/80",
|
||||||
{
|
{
|
||||||
"opacity-50": formData.isHidden,
|
"opacity-40": formData.isHidden,
|
||||||
"border border-blue-500": formData.name,
|
"border-blue-500/60 shadow-blue-500/10 shadow-md": formData.name,
|
||||||
|
"border-border/40": !formData.name,
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="relative w-full h-auto group">
|
{/* Image area */}
|
||||||
<Avatar
|
<div className="relative aspect-square w-full overflow-hidden bg-muted">
|
||||||
className="w-full min-h-full h-auto rounded-lg"
|
{person.thumbnailPath ? (
|
||||||
src={person.thumbnailPath}
|
<img
|
||||||
alt={person.name}
|
src={person.thumbnailPath}
|
||||||
/>
|
alt={formData.name || "Unknown"}
|
||||||
<div className="absolute bottom-2 w-full flex justify-center items-center">
|
className="w-full h-full object-cover object-top transition-transform duration-300 group-hover:scale-[1.03]"
|
||||||
<Badge variant={"secondary"} className="text-xs !font-medium font-mono">{person.assetCount} Assets</Badge>
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="w-full h-full flex items-center justify-center bg-muted">
|
||||||
|
<span className="text-4xl text-muted-foreground/30 font-light select-none">?</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Gradient overlay — always visible at bottom */}
|
||||||
|
<div className="absolute inset-x-0 bottom-0 h-16 bg-gradient-to-t from-black/70 to-transparent pointer-events-none" />
|
||||||
|
|
||||||
|
{/* Asset count — bottom of image */}
|
||||||
|
<div className="absolute bottom-2 left-0 right-0 flex justify-center pointer-events-none">
|
||||||
|
<span className="text-[11px] font-medium text-white/90 tabular-nums tracking-wide">
|
||||||
|
{formData.isHidden && <span className="mr-1 opacity-70">Hidden ·</span>}
|
||||||
|
{person.assetCount} assets
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="absolute top-2 left-2 group-hover:flex hidden items-center gap-2">
|
|
||||||
<Link
|
{/* Action row — slides in from top on hover */}
|
||||||
className="bg-green-300 block rounded-lg px-2 py-1 text-sm dark:text-gray-900"
|
<div className="absolute top-0 inset-x-0 flex items-center justify-between p-1.5 translate-y-[-100%] group-hover:translate-y-0 transition-transform duration-200 bg-gradient-to-b from-black/60 to-transparent">
|
||||||
href={`${exImmichUrl}/people/${person.id}`}
|
{/* Left: immich + info links */}
|
||||||
target="_blank"
|
<div className="flex items-center gap-1">
|
||||||
>
|
<Link
|
||||||
<ArrowUpRight size={16} />
|
href={`${exImmichUrl}/people/${person.id}`}
|
||||||
</Link>
|
target="_blank"
|
||||||
<Link
|
title="Open in Immich"
|
||||||
className="bg-gray-300 block rounded-lg px-2 py-1 text-sm dark:text-gray-900"
|
className="p-1 rounded-md bg-white/10 hover:bg-white/25 text-white transition-colors"
|
||||||
href={`/people/${person.id}`}
|
onClick={(e) => e.stopPropagation()}
|
||||||
>
|
>
|
||||||
<Info size={16} />
|
<ArrowUpRight size={13} />
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
<Link
|
||||||
<div className="absolute top-2 right-2 flex flex-col gap-2">
|
href={`/people/${person.id}`}
|
||||||
<PersonMergeDropdown person={person} onRemove={onRemove} />
|
title="View details"
|
||||||
<Button variant="outline" className="!py-0.5 !px-2 text-xs h-7" onClick={() => {
|
className="p-1 rounded-md bg-white/10 hover:bg-white/25 text-white transition-colors"
|
||||||
handleHide(!formData.isHidden);
|
onClick={(e) => e.stopPropagation()}
|
||||||
}}>
|
>
|
||||||
{formData.isHidden ? "Show" : "Hide"}
|
<Info size={13} />
|
||||||
</Button>
|
</Link>
|
||||||
<ShareAssetsTrigger filters={{ personIds: [person.id] }} buttonProps={{ variant: "outline", className: "!py-0.5 !px-2 text-xs h-7" }} />
|
</div>
|
||||||
|
|
||||||
|
{/* Right: hide + share + merge */}
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<button
|
||||||
|
title={formData.isHidden ? "Show person" : "Hide person"}
|
||||||
|
disabled={loading}
|
||||||
|
onClick={() => handleHide(!formData.isHidden)}
|
||||||
|
className="p-1 rounded-md bg-white/10 hover:bg-white/25 text-white transition-colors disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{formData.isHidden ? <Eye size={13} /> : <EyeOff size={13} />}
|
||||||
|
</button>
|
||||||
|
<ShareAssetsTrigger
|
||||||
|
filters={{ personIds: [person.id] }}
|
||||||
|
buttonProps={{
|
||||||
|
variant: "ghost",
|
||||||
|
className: "!p-1 !h-auto !w-auto rounded-md bg-white/10 hover:bg-white/25 text-white hover:text-white [&>svg]:h-[13px] [&>svg]:w-[13px]",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<PersonMergeDropdown
|
||||||
|
person={person}
|
||||||
|
onRemove={onRemove}
|
||||||
|
triggerClassName="!p-1 !h-auto !w-auto rounded-md !bg-white/10 hover:!bg-white/25 !text-white !border-transparent text-[10px] leading-none"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{!editMode ? (
|
|
||||||
<h2
|
{/* Name + birthday section */}
|
||||||
className="text-lg text-center font-semibold hover:bg-gray-300 dark:hover:bg-gray-800 w-full px-2 py-1 rounded-lg"
|
<div className="px-2 pt-2 pb-2 flex flex-col gap-1.5">
|
||||||
onClick={() => {
|
{!editMode ? (
|
||||||
setEditMode((prev) => !prev);
|
<button
|
||||||
}}
|
className="text-left w-full text-sm font-semibold leading-snug hover:text-muted-foreground transition-colors truncate"
|
||||||
>
|
onClick={() => setEditMode(true)}
|
||||||
{formData.name ? (
|
title={formData.name || "Click to set name"}
|
||||||
formData.name
|
>
|
||||||
) : (
|
{formData.name || (
|
||||||
<span className="text-gray-400">Unknown</span>
|
<span className="text-muted-foreground/50 font-normal italic text-xs">Unknown</span>
|
||||||
)}
|
)}
|
||||||
</h2>
|
</button>
|
||||||
) : (
|
) : (
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
loadOptions={(query: string) => searchPeople(query).then((people) => people.map((person: any) => ({
|
loadOptions={(query: string) =>
|
||||||
label: person.name, value: person.id,
|
searchPeople(query).then((people) =>
|
||||||
imageUrl: person.thumbnailPath
|
people.map((p: any) => ({ label: p.name, value: p.id, imageUrl: p.thumbnailPath }))
|
||||||
})))}
|
)
|
||||||
type="text"
|
}
|
||||||
className="text-lg font-semibold text-center w-full px-2 py-1 rounded-lg"
|
type="text"
|
||||||
defaultValue={formData.name}
|
className="text-sm font-semibold w-full px-1.5 py-0.5 rounded-md"
|
||||||
placeholder="Enter name"
|
defaultValue={formData.name}
|
||||||
autoFocus
|
placeholder="Enter name"
|
||||||
onChange={(e) => {
|
autoFocus
|
||||||
setFormData({ ...formData, name: e.target.value });
|
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
|
||||||
}}
|
value={formData.name}
|
||||||
value={formData.name}
|
onOptionSelect={(value) => {
|
||||||
onOptionSelect={(value) => {
|
mergeDialogRef.current?.open();
|
||||||
mergeDialogRef.current?.open();
|
selectedPerson.current = value;
|
||||||
selectedPerson.current = value;
|
}}
|
||||||
}}
|
createNewLabel="Save"
|
||||||
createNewLabel="Create"
|
disabled={loading}
|
||||||
disabled={loading}
|
onCreateNew={() => handleEdit()}
|
||||||
onCreateNew={(value) => {
|
/>
|
||||||
handleEdit();
|
)}
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<div className="flex flex-col gap-2">
|
|
||||||
<PersonBirthdayCell person={person} />
|
<PersonBirthdayCell person={person} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -168,9 +185,7 @@ export default function PersonItem({ person, onRemove }: IProps) {
|
|||||||
title="Merge Person"
|
title="Merge Person"
|
||||||
description="Are you sure you want to merge this person with the selected person?"
|
description="Are you sure you want to merge this person with the selected person?"
|
||||||
onConfirm={() => {
|
onConfirm={() => {
|
||||||
if (selectedPerson.current) {
|
if (selectedPerson.current) handleMerge(selectedPerson.current);
|
||||||
handleMerge(selectedPerson.current);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
import React, { useState } from "react";
|
||||||
|
import { KeyRound, Wand2, Settings } from "lucide-react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
interface Permission {
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ApiKeyGateProps {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
permissions: Permission[];
|
||||||
|
generateEndpoint: string;
|
||||||
|
onGenerated: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ApiKeyGate({ title, description, permissions, generateEndpoint, onGenerated }: ApiKeyGateProps) {
|
||||||
|
const [generating, setGenerating] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const handleGenerate = async () => {
|
||||||
|
setGenerating(true);
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
const res = await fetch(generateEndpoint, { method: "POST" });
|
||||||
|
if (!res.ok) {
|
||||||
|
const data = await res.json().catch(() => ({}));
|
||||||
|
throw new Error(data.message ?? "Failed to generate API key");
|
||||||
|
}
|
||||||
|
onGenerated();
|
||||||
|
} catch (err: any) {
|
||||||
|
setError(err.message ?? "Failed to generate API key");
|
||||||
|
} finally {
|
||||||
|
setGenerating(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-1 items-center justify-center p-8">
|
||||||
|
<div className="max-w-md w-full text-center space-y-6">
|
||||||
|
<div className="mx-auto h-14 w-14 rounded-2xl bg-muted flex items-center justify-center">
|
||||||
|
<KeyRound className="h-6 w-6 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<h2 className="text-lg font-semibold">{title}</h2>
|
||||||
|
<p className="text-sm text-muted-foreground leading-relaxed">{description}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="rounded-lg border bg-muted/40 p-4 text-left space-y-2">
|
||||||
|
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wide">Required permissions</p>
|
||||||
|
<div className="flex flex-wrap gap-1.5">
|
||||||
|
{permissions.map((p) => (
|
||||||
|
<Badge key={p.name} variant="outline" className="text-[11px] font-mono font-normal" title={p.description}>
|
||||||
|
{p.name}
|
||||||
|
</Badge>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<p className="text-xs text-destructive">{error}</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<Button onClick={handleGenerate} disabled={generating} className="w-full">
|
||||||
|
<Wand2 className="h-4 w-4 mr-2" />
|
||||||
|
{generating ? "Generating…" : "Generate API key automatically"}
|
||||||
|
</Button>
|
||||||
|
<Link href="/settings">
|
||||||
|
<Button variant="outline" className="w-full">
|
||||||
|
<Settings className="h-4 w-4 mr-2" />
|
||||||
|
Configure manually in Settings
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
|
import ReactDOM from "react-dom"
|
||||||
import { Input } from "./input"
|
import { Input } from "./input"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import { Avatar, AvatarImage } from "./avatar"
|
import { Avatar, AvatarImage } from "./avatar"
|
||||||
@@ -43,10 +44,18 @@ const Autocomplete = React.forwardRef<HTMLInputElement, AutocompleteProps>(
|
|||||||
const [options, setOptions] = React.useState<AutocompleteOption[]>(staticOptions || [])
|
const [options, setOptions] = React.useState<AutocompleteOption[]>(staticOptions || [])
|
||||||
const [isLoading, setIsLoading] = React.useState(false)
|
const [isLoading, setIsLoading] = React.useState(false)
|
||||||
const [selectedIndex, setSelectedIndex] = React.useState(-1)
|
const [selectedIndex, setSelectedIndex] = React.useState(-1)
|
||||||
|
const [dropdownRect, setDropdownRect] = React.useState<{ top: number; left: number; width: number } | null>(null)
|
||||||
const containerRef = React.useRef<HTMLDivElement>(null)
|
const containerRef = React.useRef<HTMLDivElement>(null)
|
||||||
const inputRef = React.useRef<HTMLInputElement>(null)
|
const inputRef = React.useRef<HTMLInputElement>(null)
|
||||||
const debounceTimeout = React.useRef<NodeJS.Timeout>(undefined)
|
const debounceTimeout = React.useRef<NodeJS.Timeout>(undefined)
|
||||||
|
|
||||||
|
const updateDropdownRect = React.useCallback(() => {
|
||||||
|
if (inputRef.current) {
|
||||||
|
const rect = inputRef.current.getBoundingClientRect()
|
||||||
|
setDropdownRect({ top: rect.bottom + window.scrollY + 4, left: rect.left + window.scrollX, width: rect.width })
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
// Find the label for the current value
|
// Find the label for the current value
|
||||||
const currentLabel = React.useMemo(() => {
|
const currentLabel = React.useMemo(() => {
|
||||||
if (!value) return ""
|
if (!value) return ""
|
||||||
@@ -181,6 +190,7 @@ const Autocomplete = React.forwardRef<HTMLInputElement, AutocompleteProps>(
|
|||||||
}}
|
}}
|
||||||
value={inputValue}
|
value={inputValue}
|
||||||
onFocus={() => {
|
onFocus={() => {
|
||||||
|
updateDropdownRect()
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
setSelectedIndex(showCreateNew ? 0 : -1)
|
setSelectedIndex(showCreateNew ? 0 : -1)
|
||||||
}}
|
}}
|
||||||
@@ -194,8 +204,11 @@ const Autocomplete = React.forwardRef<HTMLInputElement, AutocompleteProps>(
|
|||||||
props.onChange?.(e)
|
props.onChange?.(e)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{open && (filteredOptions.length > 0 || isLoading || showCreateNew) && (
|
{open && (filteredOptions.length > 0 || isLoading || showCreateNew) && dropdownRect && typeof document !== "undefined" && ReactDOM.createPortal(
|
||||||
<div className={cn("absolute left-0 right-0 z-50 mt-1 max-h-[300px] overflow-auto rounded-md border bg-popover shadow-md", position === "top" ? "top-full" : "bottom-full")}>
|
<div
|
||||||
|
style={{ position: "absolute", top: dropdownRect.top, left: dropdownRect.left, width: dropdownRect.width }}
|
||||||
|
className="z-[9999] max-h-[300px] overflow-auto rounded-md border bg-popover shadow-md"
|
||||||
|
>
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<div className="px-3 py-2 text-sm text-muted-foreground">
|
<div className="px-3 py-2 text-sm text-muted-foreground">
|
||||||
Loading...
|
Loading...
|
||||||
@@ -241,7 +254,8 @@ const Autocomplete = React.forwardRef<HTMLInputElement, AutocompleteProps>(
|
|||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>,
|
||||||
|
document.body
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
import { desc, eq } from "drizzle-orm";
|
import { desc, eq, and } from "drizzle-orm";
|
||||||
import { appDb } from "@/db";
|
import { appDb } from "@/db";
|
||||||
import { importJobs, importJobItems } from "@/db/schema";
|
import { importJobs, importJobItems } from "@/db/schema";
|
||||||
|
import { settings } from "@/db/schema/settings.schema";
|
||||||
import { getCurrentUser } from "@/handlers/serverUtils/user.utils";
|
import { getCurrentUser } from "@/handlers/serverUtils/user.utils";
|
||||||
import { getUserHeaders } from "@/helpers/user.helper";
|
import { getUserHeaders } from "@/helpers/user.helper";
|
||||||
import { runImportJob } from "@/workers/import/runner";
|
import { runImportJob } from "@/workers/import/runner";
|
||||||
import { getProcessor } from "@/workers/import/registry";
|
import { getProcessor } from "@/workers/import/registry";
|
||||||
|
import { ENV } from "@/config/environment";
|
||||||
|
|
||||||
|
const IMPORT_API_KEY_SETTING = "import_api_key";
|
||||||
|
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
if (req.method === "GET") {
|
if (req.method === "GET") {
|
||||||
@@ -66,7 +70,19 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|
||||||
const headers = getUserHeaders(currentUser) as Record<string, string>;
|
// Prefer import API key over user session for uploads
|
||||||
|
const [importKeyRow] = await appDb
|
||||||
|
.select()
|
||||||
|
.from(settings)
|
||||||
|
.where(and(eq(settings.key, IMPORT_API_KEY_SETTING), eq(settings.ownerId, currentUser.id)));
|
||||||
|
|
||||||
|
let headers: Record<string, string>;
|
||||||
|
if (importKeyRow?.value) {
|
||||||
|
headers = { "x-api-key": importKeyRow.value, "Content-Type": "application/json" };
|
||||||
|
} else {
|
||||||
|
headers = getUserHeaders(currentUser) as Record<string, string>;
|
||||||
|
}
|
||||||
|
|
||||||
runImportJob(job.id, headers).catch((err) =>
|
runImportJob(job.id, headers).catch((err) =>
|
||||||
console.error("Unhandled error in runImportJob", err)
|
console.error("Unhandled error in runImportJob", err)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import { ENV } from "@/config/environment";
|
||||||
|
import { appDb } from "@/db";
|
||||||
|
import { settings } from "@/db/schema/settings.schema";
|
||||||
|
import { getCurrentUser } from "@/handlers/serverUtils/user.utils";
|
||||||
|
import { getUserHeaders } from "@/helpers/user.helper";
|
||||||
|
import { and, eq } from "drizzle-orm";
|
||||||
|
import { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
|
||||||
|
export const IMPORT_API_KEY_SETTING = "import_api_key";
|
||||||
|
const IMPORT_KEY_NAME = "Power Tools Import Key";
|
||||||
|
const IMPORT_PERMISSIONS = [
|
||||||
|
"asset.read",
|
||||||
|
"asset.upload",
|
||||||
|
"album.read",
|
||||||
|
"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 immichRes = await fetch(`${ENV.IMMICH_URL}/api/api-keys`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: getUserHeaders(currentUser, { "Content-Type": "application/json" }),
|
||||||
|
body: JSON.stringify({ name: IMPORT_KEY_NAME, permissions: IMPORT_PERMISSIONS }),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!immichRes.ok) {
|
||||||
|
const err = await immichRes.json().catch(() => ({}));
|
||||||
|
return res.status(immichRes.status).json({ message: err.message ?? "Failed to create API key in Immich" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { secret } = await immichRes.json();
|
||||||
|
|
||||||
|
const [existing] = await appDb
|
||||||
|
.select()
|
||||||
|
.from(settings)
|
||||||
|
.where(and(eq(settings.key, IMPORT_API_KEY_SETTING), eq(settings.ownerId, currentUser.id)));
|
||||||
|
|
||||||
|
if (existing) {
|
||||||
|
await appDb.update(settings).set({ value: secret }).where(eq(settings.id, existing.id));
|
||||||
|
} else {
|
||||||
|
await appDb.insert(settings).values({ key: IMPORT_API_KEY_SETTING, value: secret, ownerId: currentUser.id });
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).json({ success: true });
|
||||||
|
}
|
||||||
@@ -20,6 +20,16 @@ import {
|
|||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import PageLayout from "@/components/layouts/PageLayout";
|
import PageLayout from "@/components/layouts/PageLayout";
|
||||||
import Header from "@/components/shared/Header";
|
import Header from "@/components/shared/Header";
|
||||||
|
import ApiKeyGate from "@/components/shared/ApiKeyGate";
|
||||||
|
|
||||||
|
const IMPORT_PERMISSIONS = [
|
||||||
|
{ name: "asset.read", description: "Check for existing assets" },
|
||||||
|
{ name: "asset.upload", description: "Upload new assets" },
|
||||||
|
{ name: "album.read", description: "Read album data" },
|
||||||
|
{ name: "album.create", description: "Create new albums" },
|
||||||
|
{ name: "album.update", description: "Add assets to albums" },
|
||||||
|
{ name: "tag.create", description: "Tag imported assets" },
|
||||||
|
];
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
@@ -152,6 +162,15 @@ export default function ImportSharedPage() {
|
|||||||
const [tagAssets, setTagAssets] = useState(true);
|
const [tagAssets, setTagAssets] = useState(true);
|
||||||
const [detailJobId, setDetailJobId] = useState<string | null>(null);
|
const [detailJobId, setDetailJobId] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const [hasImportApiKey, setHasImportApiKey] = useState<boolean | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetch("/api/settings/kv/import_api_key")
|
||||||
|
.then((r) => r.ok ? r.json() : null)
|
||||||
|
.then((data) => setHasImportApiKey(!!data?.value))
|
||||||
|
.catch(() => setHasImportApiKey(false));
|
||||||
|
}, []);
|
||||||
|
|
||||||
const { data: permissions } = useQuery({
|
const { data: permissions } = useQuery({
|
||||||
queryKey: ["validate-permissions"],
|
queryKey: ["validate-permissions"],
|
||||||
queryFn: validatePermissions,
|
queryFn: validatePermissions,
|
||||||
@@ -440,8 +459,19 @@ export default function ImportSharedPage() {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* ── API key gate ── */}
|
||||||
|
{hasImportApiKey === false && (
|
||||||
|
<ApiKeyGate
|
||||||
|
title="Import API Key Required"
|
||||||
|
description="Importing shared albums requires a dedicated Immich API key with upload permissions. Generate one automatically or configure it in Settings."
|
||||||
|
permissions={IMPORT_PERMISSIONS}
|
||||||
|
generateEndpoint="/api/settings/generate-import-api-key"
|
||||||
|
onGenerated={() => setHasImportApiKey(true)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* ── Landing state ── */}
|
{/* ── Landing state ── */}
|
||||||
{!sharedData && (
|
{hasImportApiKey !== false && !sharedData && (
|
||||||
<div className="flex flex-1 justify-center px-4 py-8">
|
<div className="flex flex-1 justify-center px-4 py-8">
|
||||||
<div className="w-full max-w-2xl space-y-6">
|
<div className="w-full max-w-2xl space-y-6">
|
||||||
{permissions?.canUpload === false && (
|
{permissions?.canUpload === false && (
|
||||||
@@ -552,7 +582,7 @@ export default function ImportSharedPage() {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* ── Album detail + gallery view ── */}
|
{/* ── Album detail + gallery view ── */}
|
||||||
{sharedData && albumDetails && sharedLinkDetails && (
|
{hasImportApiKey !== false && sharedData && albumDetails && sharedLinkDetails && (
|
||||||
<>
|
<>
|
||||||
<div className="flex flex-col gap-4 p-4 pb-36">
|
<div className="flex flex-col gap-4 p-4 pb-36">
|
||||||
{/* Upload banner */}
|
{/* Upload banner */}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { Input } from "@/components/ui/input";
|
|||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import {
|
import {
|
||||||
RefreshCw, Trash2, Save, Eye, EyeOff, ExternalLink,
|
RefreshCw, Trash2, Save, Eye, EyeOff, ExternalLink,
|
||||||
Key, Workflow, Shield, CheckCircle, XCircle, Server, Globe,
|
Key, Workflow, Shield, CheckCircle, XCircle, Server, Globe, Download, Wand2,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
@@ -60,6 +60,12 @@ export default function SettingsPage() {
|
|||||||
valid: boolean; error: string | null; permissions: string[]; missing: string[];
|
valid: boolean; error: string | null; permissions: string[]; missing: string[];
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
|
||||||
|
const [importApiKey, setImportApiKey] = useState("");
|
||||||
|
const [importApiKeyLoading, setImportApiKeyLoading] = useState(false);
|
||||||
|
const [showImportApiKey, setShowImportApiKey] = useState(false);
|
||||||
|
const [importApiKeySaved, setImportApiKeySaved] = useState(false);
|
||||||
|
const [generatingImportKey, setGeneratingImportKey] = useState(false);
|
||||||
|
|
||||||
const fetchWorkflowApiKey = async () => {
|
const fetchWorkflowApiKey = async () => {
|
||||||
try {
|
try {
|
||||||
const data = await API.get("/api/settings/kv/workflow_api_key");
|
const data = await API.get("/api/settings/kv/workflow_api_key");
|
||||||
@@ -70,6 +76,40 @@ export default function SettingsPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fetchImportApiKey = async () => {
|
||||||
|
try {
|
||||||
|
const data = await API.get("/api/settings/kv/import_api_key");
|
||||||
|
setImportApiKey(data.value || "");
|
||||||
|
setImportApiKeySaved(!!data.value);
|
||||||
|
} catch {
|
||||||
|
setImportApiKeySaved(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveImportApiKey = async () => {
|
||||||
|
setImportApiKeyLoading(true);
|
||||||
|
try {
|
||||||
|
await API.put("/api/settings/kv/import_api_key", { value: importApiKey.trim() });
|
||||||
|
setImportApiKeySaved(!!importApiKey.trim());
|
||||||
|
toast.success(importApiKey.trim() ? "Import API key saved" : "Import API key cleared");
|
||||||
|
} catch {
|
||||||
|
toast.error("Failed to save import API key");
|
||||||
|
}
|
||||||
|
setImportApiKeyLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleGenerateImportKey = async () => {
|
||||||
|
setGeneratingImportKey(true);
|
||||||
|
try {
|
||||||
|
await API.post("/api/settings/generate-import-api-key", {});
|
||||||
|
await fetchImportApiKey();
|
||||||
|
toast.success("Import API key generated and saved");
|
||||||
|
} catch (err: any) {
|
||||||
|
toast.error(err?.message ?? "Failed to generate import API key");
|
||||||
|
}
|
||||||
|
setGeneratingImportKey(false);
|
||||||
|
};
|
||||||
|
|
||||||
const saveWorkflowApiKey = async () => {
|
const saveWorkflowApiKey = async () => {
|
||||||
if (!workflowApiKey.trim()) {
|
if (!workflowApiKey.trim()) {
|
||||||
// Clear the key
|
// Clear the key
|
||||||
@@ -123,6 +163,7 @@ export default function SettingsPage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchKeys();
|
fetchKeys();
|
||||||
fetchWorkflowApiKey();
|
fetchWorkflowApiKey();
|
||||||
|
fetchImportApiKey();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleDelete = async (purpose: string) => {
|
const handleDelete = async (purpose: string) => {
|
||||||
@@ -265,6 +306,74 @@ export default function SettingsPage() {
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
{/* Import API Key */}
|
||||||
|
<section>
|
||||||
|
<div className="flex items-center gap-2 mb-3">
|
||||||
|
<Download className="h-4 w-4 text-muted-foreground" />
|
||||||
|
<h2 className="text-sm font-semibold tracking-wide uppercase text-muted-foreground">Import API Key</h2>
|
||||||
|
{importApiKeySaved ? (
|
||||||
|
<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" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="border rounded-lg p-4 space-y-3">
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Immich API key used when importing from shared links. Needs asset upload, album, and tag permissions.
|
||||||
|
</p>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<div className="relative flex-1">
|
||||||
|
<Input
|
||||||
|
type={showImportApiKey ? "text" : "password"}
|
||||||
|
className="h-9 text-sm font-mono pr-10"
|
||||||
|
placeholder="Paste your Immich API key here"
|
||||||
|
value={importApiKey}
|
||||||
|
onChange={(e) => setImportApiKey(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={() => setShowImportApiKey((v) => !v)}
|
||||||
|
>
|
||||||
|
{showImportApiKey ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<Button size="sm" className="h-9" onClick={saveImportApiKey} disabled={importApiKeyLoading}>
|
||||||
|
<Save className="h-3.5 w-3.5 mr-1" />
|
||||||
|
{importApiKeyLoading ? "Saving..." : "Save"}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap gap-1">
|
||||||
|
{["asset.read", "asset.upload", "album.read", "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">
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
className="h-7 text-xs"
|
||||||
|
onClick={handleGenerateImportKey}
|
||||||
|
disabled={generatingImportKey}
|
||||||
|
>
|
||||||
|
<Wand2 className="h-3 w-3 mr-1" />
|
||||||
|
{generatingImportKey ? "Generating..." : "Generate automatically"}
|
||||||
|
</Button>
|
||||||
|
{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"
|
||||||
|
>
|
||||||
|
Create in Immich
|
||||||
|
<ExternalLink className="h-3 w-3" />
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
{/* Managed API Keys */}
|
{/* Managed API Keys */}
|
||||||
<section>
|
<section>
|
||||||
<div className="flex items-center gap-2 mb-3">
|
<div className="flex items-center gap-2 mb-3">
|
||||||
|
|||||||
@@ -30,12 +30,22 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
|||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { ASSET_THUMBNAIL_PATH } from "@/config/routes";
|
import { ASSET_THUMBNAIL_PATH } from "@/config/routes";
|
||||||
import { IWorkflowRun } from "@/types/workflow";
|
import { IWorkflowRun } from "@/types/workflow";
|
||||||
import { ArrowLeft, Play, Save, Clock, Webhook, History, ChevronUp, ChevronDown, Bug, TriangleAlert, Wand2 } from "lucide-react";
|
import { ArrowLeft, Play, Save, Clock, Webhook, History, ChevronUp, ChevronDown, Bug } from "lucide-react";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import Loader from "@/components/ui/loader";
|
import Loader from "@/components/ui/loader";
|
||||||
import API from "@/lib/api";
|
import API from "@/lib/api";
|
||||||
|
import ApiKeyGate from "@/components/shared/ApiKeyGate";
|
||||||
|
|
||||||
|
const WORKFLOW_PERMISSIONS = [
|
||||||
|
{ name: "asset.read", description: "Query and filter assets" },
|
||||||
|
{ name: "asset.update", description: "Favorite, archive, update metadata" },
|
||||||
|
{ name: "album.read", description: "Read album data" },
|
||||||
|
{ name: "album.create", description: "Create new albums" },
|
||||||
|
{ name: "album.update", description: "Add/remove assets from albums" },
|
||||||
|
{ name: "tag.create", description: "Create and assign tags" },
|
||||||
|
];
|
||||||
|
|
||||||
function generateId() {
|
function generateId() {
|
||||||
return Math.random().toString(36).substring(2, 15);
|
return Math.random().toString(36).substring(2, 15);
|
||||||
@@ -232,7 +242,6 @@ function WorkflowEditorInner() {
|
|||||||
const [showRuns, setShowRuns] = useState(false);
|
const [showRuns, setShowRuns] = useState(false);
|
||||||
const [expandedRunId, setExpandedRunId] = useState<string | null>(null);
|
const [expandedRunId, setExpandedRunId] = useState<string | null>(null);
|
||||||
const [hasApiKey, setHasApiKey] = useState<boolean | null>(null);
|
const [hasApiKey, setHasApiKey] = useState<boolean | null>(null);
|
||||||
const [generatingKey, setGeneratingKey] = useState(false);
|
|
||||||
|
|
||||||
const [nodes, setNodes, onNodesChange] = useNodesState([] as Node[]);
|
const [nodes, setNodes, onNodesChange] = useNodesState([] as Node[]);
|
||||||
const [edges, setEdges, onEdgesChange] = useEdgesState([] as Edge[]);
|
const [edges, setEdges, onEdgesChange] = useEdgesState([] as Edge[]);
|
||||||
@@ -261,19 +270,6 @@ function WorkflowEditorInner() {
|
|||||||
.catch(() => setHasApiKey(false));
|
.catch(() => setHasApiKey(false));
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
const handleGenerateApiKey = async () => {
|
|
||||||
setGeneratingKey(true);
|
|
||||||
try {
|
|
||||||
await API.post("/api/settings/generate-workflow-api-key", {});
|
|
||||||
setHasApiKey(true);
|
|
||||||
hotToast.success("Workflow API key created and saved");
|
|
||||||
} catch (err: any) {
|
|
||||||
hotToast.error(err?.message ?? "Failed to create API key");
|
|
||||||
} finally {
|
|
||||||
setGeneratingKey(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onConnect = useCallback((connection: Connection) => {
|
const onConnect = useCallback((connection: Connection) => {
|
||||||
setEdges((eds) => addEdge({ ...connection, animated: true }, eds));
|
setEdges((eds) => addEdge({ ...connection, animated: true }, eds));
|
||||||
}, [setEdges]);
|
}, [setEdges]);
|
||||||
@@ -491,54 +487,6 @@ function WorkflowEditorInner() {
|
|||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</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>
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
className="w-full h-7 text-xs"
|
|
||||||
onClick={handleGenerateApiKey}
|
|
||||||
disabled={generatingKey}
|
|
||||||
>
|
|
||||||
<Wand2 className="h-3 w-3 mr-1" />
|
|
||||||
{generatingKey ? "Creating..." : "Generate automatically"}
|
|
||||||
</Button>
|
|
||||||
<Link href="/settings" className="block">
|
|
||||||
<Button size="sm" variant="outline" className="w-full h-7 text-xs">
|
|
||||||
Configure manually in Settings
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
</PopoverContent>
|
|
||||||
</Popover>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="ml-auto flex items-center gap-2">
|
<div className="ml-auto flex items-center gap-2">
|
||||||
<Button variant="outline" size="sm" onClick={() => handleRun("debug")} disabled={running}>
|
<Button variant="outline" size="sm" onClick={() => handleRun("debug")} disabled={running}>
|
||||||
@@ -561,8 +509,19 @@ function WorkflowEditorInner() {
|
|||||||
{/* Left: Node palette */}
|
{/* Left: Node palette */}
|
||||||
<NodePalette />
|
<NodePalette />
|
||||||
|
|
||||||
|
{/* API Key gate — shown instead of canvas when key is missing */}
|
||||||
|
{hasApiKey === false && (
|
||||||
|
<ApiKeyGate
|
||||||
|
title="Workflow API Key Required"
|
||||||
|
description="Workflows need a dedicated Immich API key to execute actions like creating albums, favoriting assets, and managing tags. Generate one automatically or configure it in Settings."
|
||||||
|
permissions={WORKFLOW_PERMISSIONS}
|
||||||
|
generateEndpoint="/api/settings/generate-workflow-api-key"
|
||||||
|
onGenerated={() => setHasApiKey(true)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Center: Canvas */}
|
{/* Center: Canvas */}
|
||||||
<div className="flex-1" ref={reactFlowWrapper}>
|
<div className={`flex-1 ${hasApiKey === false ? "hidden" : ""}`} ref={reactFlowWrapper}>
|
||||||
<ReactFlow
|
<ReactFlow
|
||||||
nodes={nodes}
|
nodes={nodes}
|
||||||
edges={edges}
|
edges={edges}
|
||||||
@@ -585,9 +544,11 @@ function WorkflowEditorInner() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right: Config panel */}
|
{/* Right: Config panel */}
|
||||||
<div className="w-72 min-w-[288px] border-l bg-background overflow-y-auto h-full">
|
{hasApiKey !== false && (
|
||||||
{renderConfigPanel()}
|
<div className="w-72 min-w-[288px] border-l bg-background overflow-y-auto h-full">
|
||||||
</div>
|
{renderConfigPanel()}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Runs panel */}
|
{/* Runs panel */}
|
||||||
|
|||||||
Reference in new issue
Block a user