diff --git a/.env.sample b/.env.sample index 1971f20..a47d796 100644 --- a/.env.sample +++ b/.env.sample @@ -15,4 +15,5 @@ GEMINI_API_KEY="" # Gemini API Key for parsing search query in "Find" # Immich Share Link IMMICH_SHARE_LINK_KEY="" # Share link key for Immich -POWER_TOOLS_ENDPOINT_URL="" # URL of the Power Tools endpoint (Used for share links) \ No newline at end of file +POWER_TOOLS_ENDPOINT_URL="" # URL of the Power Tools endpoint (Used for share links) +JWT_SECRET="" # JWT Secret for authentication diff --git a/.eslintrc.json b/.eslintrc.json index 7d8b7fc..474b69e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -6,5 +6,9 @@ "files": ["remotion/*.{ts,tsx}"], "extends": ["plugin:@remotion/recommended"] } - ] + ], + "rules": { + "react-hooks/exhaustive-deps": "off", + "@next/next/no-img-element": "off" + } } diff --git a/bun.lockb b/bun.lockb index 741a0e0..c4de24e 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/docker-compose-all-immich.yml b/docker-compose-all-immich.yml index 1dfaefc..a5e49ad 100644 --- a/docker-compose-all-immich.yml +++ b/docker-compose-all-immich.yml @@ -57,6 +57,12 @@ services: - "8001:3000" env_file: - .env + healthcheck: + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/api/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s volumes: model-cache: diff --git a/docker-compose.yml b/docker-compose.yml index 38fd9a2..b11157e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,3 +8,9 @@ services: - "3000:3000" env_file: - .env + healthcheck: + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/api/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s diff --git a/package.json b/package.json index c4869bc..f9e7cbf 100644 --- a/package.json +++ b/package.json @@ -34,9 +34,11 @@ "@radix-ui/react-tooltip": "^1.1.2", "@remotion/cli": "4.0.232", "@remotion/eslint-plugin": "^4.0.232", + "@tanstack/react-query": "^5.69.0", "@tanstack/react-table": "^8.20.1", "@types/cookie": "^0.6.0", "@types/qs": "^6.9.15", + "@types/react-autosuggest": "^10.1.11", "@types/react-calendar-heatmap": "^1.6.7", "@vis.gl/react-google-maps": "^1.4.2", "axios": "^1.7.4", @@ -57,13 +59,13 @@ "pg": "^8.12.0", "qs": "^6.13.0", "react": "^18", + "react-autosuggest": "^10.1.0", "react-day-picker": "9.0.8", "react-dom": "^18", "react-grid-gallery": "^1.0.1", "react-hot-toast": "^2.5.1", "react-leaflet": "^4.2.1", "react-mentions": "^4.4.10", - "react-query": "^3.39.3", "recharts": "^2.12.7", "remotion": "4.0.232", "sass": "^1.77.8", @@ -78,6 +80,7 @@ "@semantic-release/github": "^10.1.7", "@semantic-release/npm": "^12.0.1", "@semantic-release/release-notes-generator": "^14.0.1", + "@tanstack/eslint-plugin-query": "^5.68.0", "@types/jsonwebtoken": "^9.0.6", "@types/leaflet": "^1.9.15", "@types/node": "^20", diff --git a/src/components/albums/info/AlbumImages.tsx b/src/components/albums/info/AlbumImages.tsx index c040931..f7b1b3e 100644 --- a/src/components/albums/info/AlbumImages.tsx +++ b/src/components/albums/info/AlbumImages.tsx @@ -6,11 +6,9 @@ import { IAsset } from '@/types/asset' import React, { useEffect, useMemo, useRef, useState } from 'react' import { ExternalLink, Hourglass } from 'lucide-react'; import { useRouter } from 'next/router'; -import { CalendarArrowUp } from 'lucide-react'; import Lightbox from 'yet-another-react-lightbox'; import Captions from 'yet-another-react-lightbox/plugins/captions'; import LazyImage from '@/components/ui/lazy-image'; -import Image from 'next/image'; import { Button } from "@/components/ui/button"; import Link from "next/link"; diff --git a/src/components/albums/info/AlbumPeople.tsx b/src/components/albums/info/AlbumPeople.tsx index cd4dc33..4981c04 100644 --- a/src/components/albums/info/AlbumPeople.tsx +++ b/src/components/albums/info/AlbumPeople.tsx @@ -1,22 +1,19 @@ import React, { useEffect, useMemo, useState } from 'react' import { IAlbum } from '@/types/album' -import { IPerson } from '@/types/person' import { getAlbumPeople } from '@/handlers/api/album.handler' import Loader from '@/components/ui/loader' import LazyImage from '@/components/ui/lazy-image' import { PERSON_THUBNAIL_PATH } from '@/config/routes' import Link from 'next/link' import { useConfig } from '@/contexts/ConfigContext' -import { Tooltip } from '@/components/ui/tooltip' import { cn } from '@/lib/utils' -import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion' -import { Users, X } from 'lucide-react' import { useRouter } from 'next/router' import Image from 'next/image' import { PersonMergeDropdown } from '@/components/people/PersonMergeDropdown' import { Button } from '@/components/ui/button' import { updatePerson } from '@/handlers/api/people.handler' import { Checkbox } from '@/components/ui/checkbox' +import { Input } from '@/components/ui/input' interface AlbumPeopleProps { album: IAlbum @@ -40,11 +37,16 @@ export default function AlbumPeople({ album, onSelect, readOnly }: AlbumPeoplePr const [hidingPerson, setHidingPerson] = useState(false) const [selectionMode, setSelectionMode] = useState(false) const [selectedPeople, setSelectedPeople] = useState([]) + const [searchQuery, setSearchQuery] = useState("") const selectedPerson = useMemo(() => { return people.find((person) => query.faceId === person.id) }, [people, query.faceId]) + const filteredPeople = useMemo(() => { + return people.filter((person) => person.name.toLowerCase().includes(searchQuery.toLowerCase())) + }, [people, searchQuery]) + const fetchPeople = async () => { return getAlbumPeople(album.id).then((people) => { setPeople(people) @@ -102,7 +104,12 @@ export default function AlbumPeople({ album, onSelect, readOnly }: AlbumPeoplePr return (
- + setSearchQuery(e.target.value)} + /> {selectedPerson && (
@@ -172,7 +179,7 @@ export default function AlbumPeople({ album, onSelect, readOnly }: AlbumPeoplePr )}
- {people.map((person) => ( + {filteredPeople.map((person) => (
Promise; diff --git a/src/components/find/FindInput.tsx b/src/components/find/FindInput.tsx index 094985e..7b7bbf9 100644 --- a/src/components/find/FindInput.tsx +++ b/src/components/find/FindInput.tsx @@ -3,8 +3,6 @@ import inputStyle from './findInputStyle' import { MentionsInput, Mention } from 'react-mentions' import { searchPeople } from '@/handlers/api/people.handler'; import mentionStyle from './findMentionStyle'; -import classNames from './FindInput.module.css'; - interface FindInputProps { onSearch: (query: string) => void; diff --git a/src/components/layouts/PageLayout.tsx b/src/components/layouts/PageLayout.tsx index 16a3e52..578e789 100644 --- a/src/components/layouts/PageLayout.tsx +++ b/src/components/layouts/PageLayout.tsx @@ -1,8 +1,6 @@ import React from "react"; import Header from "../shared/Header"; import { cn } from "@/lib/utils"; -import Head from "next/head"; - interface IProps { children: React.ReactNode[] | React.ReactNode; diff --git a/src/components/layouts/RootLayout.tsx b/src/components/layouts/RootLayout.tsx index f5bbbab..5a366a4 100644 --- a/src/components/layouts/RootLayout.tsx +++ b/src/components/layouts/RootLayout.tsx @@ -11,7 +11,6 @@ import { LoginForm } from "../auth/LoginForm"; import { useConfig } from "@/contexts/ConfigContext"; import { Toaster } from "react-hot-toast"; import { useRouter } from "next/router"; -import PageLayout from "./PageLayout"; type RootLayoutProps = { children: ReactNode; diff --git a/src/components/people/PeopleFilters.tsx b/src/components/people/PeopleFilters.tsx index 6915039..c3ab871 100644 --- a/src/components/people/PeopleFilters.tsx +++ b/src/components/people/PeopleFilters.tsx @@ -16,11 +16,11 @@ import { Input } from "../ui/input"; import { IPersonListFilters } from "@/handlers/api/people.handler"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select"; import { removeNullOrUndefinedProperties } from "@/helpers/data.helper"; -import { ParsedUrlQueryInput } from "querystring"; export function PeopleFilters() { const router = useRouter(); - const { updateContext, page, maximumAssetCount, type = "all", query = "", visibility = "all" } = usePeopleFilterContext(); + const filters = usePeopleFilterContext(); + const { updateContext, page, maximumAssetCount, type = "all", query = "", visibility = "all" } = filters; const handleChange = (data: Partial) => { updateContext(data); @@ -69,7 +69,10 @@ export function PeopleFilters() { }} /> - handleChange({ + ...removeNullOrUndefinedProperties(filters), + type: value as "all" | "nameless" | "named" + })}> @@ -80,7 +83,10 @@ export function PeopleFilters() { - handleChange({ + ...removeNullOrUndefinedProperties(filters), + visibility: value as "all" | "visible" | "hidden" + })}> diff --git a/src/components/people/PersonHideCell.tsx b/src/components/people/PersonHideCell.tsx index 81971d1..f1ffb6c 100644 --- a/src/components/people/PersonHideCell.tsx +++ b/src/components/people/PersonHideCell.tsx @@ -1,11 +1,6 @@ import { IPerson } from "@/types/person"; import React, { useState } from "react"; -import { DatePicker } from "../ui/datepicker"; import { updatePerson } from "@/handlers/api/people.handler"; -import { formatDate } from "@/helpers/date.helper"; -import { Button } from "../ui/button"; -import { Switch } from "../ui/switch"; -import { Label } from "../ui/label"; interface IProps { person: IPerson; diff --git a/src/components/people/PersonItem.tsx b/src/components/people/PersonItem.tsx index a0dee00..d444b10 100644 --- a/src/components/people/PersonItem.tsx +++ b/src/components/people/PersonItem.tsx @@ -1,17 +1,19 @@ import { IPerson } from "@/types/person"; -import React, { useState } from "react"; +import React, { useRef, useState } from "react"; import { Avatar } from "../ui/avatar"; -import { updatePerson } from "@/handlers/api/people.handler"; +import { mergePerson, searchPeople, updatePerson } from "@/handlers/api/people.handler"; import { PersonMergeDropdown } from "./PersonMergeDropdown"; import PersonBirthdayCell from "./PersonBirthdayCell"; import clsx from "clsx"; import Link from "next/link"; -import { ArrowUpRight, Info, Search } from "lucide-react"; +import { ArrowUpRight, Info } from "lucide-react"; import { useConfig } from "@/contexts/ConfigContext"; import { useToast } from "../ui/use-toast"; import { Badge } from "../ui/badge"; import { Button } from "@/components/ui/button"; import ShareAssetsTrigger from "../shared/ShareAssetsTrigger"; +import { Autocomplete, AutocompleteOption } from "../ui/autocomplete"; +import { AlertDialog, IAlertDialogActions } from "../ui/alert-dialog"; interface IProps { person: IPerson; onRemove: (person: IPerson) => void; @@ -22,6 +24,8 @@ export default function PersonItem({ person, onRemove }: IProps) { const [editMode, setEditMode] = useState(false); const [loading, setLoading] = useState(false); const [formData, setFormData] = useState(person); + const selectedPerson = useRef(null); + const mergeDialogRef = useRef(null); const handleEdit = () => { if (formData.name && formData.name !== person.name) { @@ -62,12 +66,16 @@ export default function PersonItem({ person, onRemove }: IProps) { isHidden: hidden, })); }) - .catch(() => {}) + .catch(() => { }) .finally(() => { setLoading(false); }); }; + const handleMerge = async (option: AutocompleteOption) => { + await mergePerson(person.id, [option.value]); + }; + return (
- +
{person.assetCount} Assets
@@ -103,13 +111,13 @@ export default function PersonItem({ person, onRemove }: IProps) {
- + - + {formData.isHidden ? "Show" : "Hide"} + +
{!editMode ? ( @@ -126,7 +134,11 @@ export default function PersonItem({ person, onRemove }: IProps) { )} ) : ( - searchPeople(query).then((people) => people.map((person: any) => ({ + label: person.name, value: person.id, + imageUrl: person.thumbnailPath + })))} type="text" className="text-lg font-semibold text-center w-full px-2 py-1 rounded-lg" defaultValue={formData.name} @@ -135,18 +147,32 @@ export default function PersonItem({ person, onRemove }: IProps) { onChange={(e) => { setFormData({ ...formData, name: e.target.value }); }} - onKeyDown={(e) => { - if (e.key === "Enter") { - handleEdit(); - } + value={formData.name} + onOptionSelect={(value) => { + mergeDialogRef.current?.open(); + selectedPerson.current = value; }} + createNewLabel="Create" disabled={loading} - onBlur={handleEdit} + onCreateNew={(value) => { + handleEdit(); + }} /> )}
+ + { + if (selectedPerson.current) { + handleMerge(selectedPerson.current); + } + }} + />
); } diff --git a/src/components/people/info/PersonAlbumList.tsx b/src/components/people/info/PersonAlbumList.tsx index 5d4447e..32d50b6 100644 --- a/src/components/people/info/PersonAlbumList.tsx +++ b/src/components/people/info/PersonAlbumList.tsx @@ -1,6 +1,5 @@ import { ASSET_THUMBNAIL_PATH } from '@/config/routes'; import { useConfig } from '@/contexts/ConfigContext'; -import { ExternalLink } from 'lucide-react'; import Image from 'next/image'; import Link from 'next/link'; import React, { useMemo } from 'react' diff --git a/src/components/shared/AlbumDropdown.tsx b/src/components/shared/AlbumDropdown.tsx index 8ff4f3f..f23e4dc 100644 --- a/src/components/shared/AlbumDropdown.tsx +++ b/src/components/shared/AlbumDropdown.tsx @@ -2,7 +2,6 @@ import { listAlbums } from '@/handlers/api/album.handler'; import { IAlbum } from '@/types/album'; import React, { useEffect, useState } from 'react' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select'; -import { X } from 'lucide-react'; interface IAlbumDropdownProps { albumIds?: string[]; diff --git a/src/components/shared/ErrorBlock.tsx b/src/components/shared/ErrorBlock.tsx index 6cdf5a9..cf6605c 100644 --- a/src/components/shared/ErrorBlock.tsx +++ b/src/components/shared/ErrorBlock.tsx @@ -1,5 +1,3 @@ -import { useConfig } from '@/contexts/ConfigContext'; -import { Link } from 'lucide-react'; import React from 'react' interface ErrorBlockProps { diff --git a/src/components/shared/FloatingBar.tsx b/src/components/shared/FloatingBar.tsx index 73e3aa7..06d1a4c 100644 --- a/src/components/shared/FloatingBar.tsx +++ b/src/components/shared/FloatingBar.tsx @@ -1,4 +1,3 @@ -import { Button } from '@/components/ui/button' import React from 'react' interface FloatingBarProps { diff --git a/src/components/shared/Header.tsx b/src/components/shared/Header.tsx index e8898c7..c9606e8 100644 --- a/src/components/shared/Header.tsx +++ b/src/components/shared/Header.tsx @@ -1,23 +1,7 @@ import React, { useMemo } from "react"; import Link from "next/link"; -import { - Home, - LineChart, - Menu, - Package, - Package2, - ShoppingCart, - Users, -} from "lucide-react"; -import { Badge } from "@/components/ui/badge"; +import { Menu } from "lucide-react"; import { Button } from "@/components/ui/button"; -import { - Card, - CardContent, - CardDescription, - CardHeader, - CardTitle, -} from "@/components/ui/card"; import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet"; import Head from "next/head"; import { sidebarNavs } from "@/config/constants/sidebarNavs"; diff --git a/src/components/shared/PeopleList.tsx b/src/components/shared/PeopleList.tsx index 8a6084a..3ac016f 100644 --- a/src/components/shared/PeopleList.tsx +++ b/src/components/shared/PeopleList.tsx @@ -1,8 +1,8 @@ -import React, { useCallback } from 'react' +import React, { useCallback, useMemo, useState } from 'react' import { IPerson } from '@/types/person'; import { cn } from '@/lib/utils'; import LazyImage from '../ui/lazy-image'; -import { PERSON_THUBNAIL_PATH } from '@/config/routes'; +import { Input } from '../ui/input'; interface PeopleListProps { people: IPerson[]; @@ -11,14 +11,25 @@ interface PeopleListProps { } export default function PeopleList({ people, onSelect, selectedIds }: PeopleListProps) { - + const [searchQuery, setSearchQuery] = useState("") + + const filteredPeople = useMemo(() => { + return people.filter((person) => person.name.toLowerCase().includes(searchQuery.toLowerCase())) + }, [people, searchQuery]) + const isSelected = useCallback((person: IPerson) => { return selectedIds?.includes(person.id) }, [selectedIds]) return ( -
- {people.map((person) => ( +
+ setSearchQuery(e.target.value)} + /> + {filteredPeople.map((person) => (
{theme === "light" ? : } diff --git a/src/components/ui/alert-dialog.tsx b/src/components/ui/alert-dialog.tsx index 35c8942..524494d 100644 --- a/src/components/ui/alert-dialog.tsx +++ b/src/components/ui/alert-dialog.tsx @@ -128,7 +128,7 @@ const AlertDialogCancel = React.forwardRef< AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName -export interface INewChangelogButtonActions { +export interface IAlertDialogActions { open: () => void } interface AlertDialogProps extends AlertDialogPrimitive.AlertDialogProps { @@ -142,7 +142,7 @@ interface AlertDialogProps extends AlertDialogPrimitive.AlertDialogProps { disabled?: boolean } -const AlertDialog = React.forwardRef>(({ +const AlertDialog = React.forwardRef>(({ children, title, description, diff --git a/src/components/ui/autocomplete.tsx b/src/components/ui/autocomplete.tsx new file mode 100644 index 0000000..3baa2f0 --- /dev/null +++ b/src/components/ui/autocomplete.tsx @@ -0,0 +1,251 @@ +import * as React from "react" +import { Input } from "./input" +import { cn } from "@/lib/utils" +import { Avatar, AvatarImage } from "./avatar" + +export interface AutocompleteOption { + label: string + value: string + imageUrl?: string +} + +export interface AutocompleteProps extends React.InputHTMLAttributes { + options?: AutocompleteOption[] + value: string + onOptionSelect: (value: AutocompleteOption) => void + placeholder?: string + className?: string + loadOptions?: (inputValue: string) => Promise + initialValue?: string + isLoading?: boolean + onCreateNew?: (inputValue: string) => void + createNewLabel?: string +} + +const Autocomplete = React.forwardRef( + ({ + options: staticOptions, + value, + onOptionSelect, + placeholder, + className, + loadOptions, + initialValue, + isLoading: externalLoading, + onCreateNew, + createNewLabel = "Create new", + ...props + }, forwardedRef) => { + const [open, setOpen] = React.useState(false) + const [inputValue, setInputValue] = React.useState(initialValue || value) + const [options, setOptions] = React.useState(staticOptions || []) + const [isLoading, setIsLoading] = React.useState(false) + const [selectedIndex, setSelectedIndex] = React.useState(-1) + const containerRef = React.useRef(null) + const inputRef = React.useRef(null) + const debounceTimeout = React.useRef() + + // Find the label for the current value + const currentLabel = React.useMemo(() => { + if (!value) return "" + const option = options.find(opt => opt.value === value) + return option?.label || value + }, [value, options]) + + React.useEffect(() => { + setInputValue(initialValue || currentLabel) + }, [initialValue, currentLabel]) + + // Close dropdown when clicking outside + React.useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if (containerRef.current && !containerRef.current.contains(event.target as Node)) { + setOpen(false) + setSelectedIndex(-1) + } + } + + document.addEventListener("mousedown", handleClickOutside) + return () => document.removeEventListener("mousedown", handleClickOutside) + }, []) + + // Handle async loading of options + React.useEffect(() => { + if (!loadOptions) return + + const loadOptionsAsync = async () => { + if (!inputValue.trim()) { + setOptions([]) + return + } + + setIsLoading(true) + try { + const results = await loadOptions(inputValue) + setOptions(results) + } catch (error) { + console.error('Error loading options:', error) + setOptions([]) + } finally { + setIsLoading(false) + } + } + + // Debounce the search to avoid too many API calls + if (debounceTimeout.current) { + clearTimeout(debounceTimeout.current) + } + debounceTimeout.current = setTimeout(loadOptionsAsync, 300) + + return () => { + if (debounceTimeout.current) { + clearTimeout(debounceTimeout.current) + } + } + }, [inputValue, loadOptions]) + + const filteredOptions = loadOptions + ? options + : (staticOptions || []).filter((option) => + option.label.toLowerCase().includes(inputValue.toLowerCase()) + ) + + const showCreateNew = onCreateNew && inputValue.trim() && !isLoading + const totalOptions = filteredOptions.length + (showCreateNew ? 1 : 0) + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (!open) { + if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { + e.preventDefault() + setOpen(true) + setSelectedIndex(showCreateNew ? 0 : -1) + } + return + } + + switch (e.key) { + case 'ArrowDown': + e.preventDefault() + setSelectedIndex((prev) => { + const next = prev + 1 + return next >= totalOptions ? 0 : next + }) + break + case 'ArrowUp': + e.preventDefault() + setSelectedIndex((prev) => { + const next = prev - 1 + return next < 0 ? totalOptions - 1 : next + }) + break + case 'Enter': + e.preventDefault() + if (showCreateNew && selectedIndex === 0) { + onCreateNew(inputValue.trim()) + setOpen(false) + setSelectedIndex(-1) + } else if (selectedIndex >= (showCreateNew ? 1 : 0) && selectedIndex < totalOptions) { + const option = filteredOptions[selectedIndex - (showCreateNew ? 1 : 0)] + setInputValue(option.label) + onOptionSelect(option) + setOpen(false) + setSelectedIndex(-1) + } + break + case 'Escape': + e.preventDefault() + setOpen(false) + setSelectedIndex(-1) + break + } + } + + return ( +
+ { + // Handle both the forwarded ref and our internal ref + if (typeof forwardedRef === 'function') { + forwardedRef(node) + } + if (node) { + (inputRef as React.MutableRefObject).current = node + } + }} + value={inputValue} + onFocus={() => { + setOpen(true) + setSelectedIndex(showCreateNew ? 0 : -1) + }} + onKeyDown={handleKeyDown} + placeholder={placeholder} + className={cn("w-full", className)} + {...props} + onChange={(e) => { + setInputValue(e.target.value) + setSelectedIndex(showCreateNew ? 0 : -1) + props.onChange?.(e) + }} + /> + {open && (filteredOptions.length > 0 || isLoading || showCreateNew) && ( +
+ {isLoading ? ( +
+ Loading... +
+ ) : ( + <> + {showCreateNew && ( + + )} + {filteredOptions.map((option, index) => ( + + ))} + + )} +
+ )} +
+ ) + } +) + +Autocomplete.displayName = "Autocomplete" + +export { Autocomplete } diff --git a/src/components/ui/skeleton.tsx b/src/components/ui/skeleton.tsx new file mode 100644 index 0000000..d7e45f7 --- /dev/null +++ b/src/components/ui/skeleton.tsx @@ -0,0 +1,15 @@ +import { cn } from "@/lib/utils" + +function Skeleton({ + className, + ...props +}: React.HTMLAttributes) { + return ( +
+ ) +} + +export { Skeleton } diff --git a/src/config/queryClient.ts b/src/config/queryClient.ts new file mode 100644 index 0000000..498e530 --- /dev/null +++ b/src/config/queryClient.ts @@ -0,0 +1,3 @@ +import { QueryClient } from "@tanstack/react-query"; + +export const queryClient = new QueryClient(); \ No newline at end of file diff --git a/src/config/routes.ts b/src/config/routes.ts index d92ef88..dabca57 100644 --- a/src/config/routes.ts +++ b/src/config/routes.ts @@ -68,4 +68,6 @@ export const FIND_ASSETS = BASE_API_ENDPOINT + "/find/search"; export const SHARE_LINK_PATH = (token: string) => BASE_API_ENDPOINT + "/share-link/" + token; export const SHARE_LINK_GENERATE_PATH = BASE_API_ENDPOINT + "/share-link/generate"; export const SHARE_LINK_ASSETS_PATH = (token: string) => BASE_API_ENDPOINT + "/share-link/" + token + "/assets"; -export const SHARE_LINK_PEOPLE_PATH = (token: string) => BASE_API_ENDPOINT + "/share-link/" + token + "/people"; \ No newline at end of file +export const SHARE_LINK_PEOPLE_PATH = (token: string) => BASE_API_ENDPOINT + "/share-link/" + token + "/people"; +export const SHARE_LINK_DOWNLOAD_PATH = (token: string) => BASE_API_ENDPOINT + "/share-link/" + token + "/download"; +export const DOWNLOAD_ASSETS_PATH = BASE_PROXY_ENDPOINT + "/download/archive"; \ No newline at end of file diff --git a/src/handlers/api/shareLink.handler.ts b/src/handlers/api/shareLink.handler.ts index a6886a9..b6616a4 100644 --- a/src/handlers/api/shareLink.handler.ts +++ b/src/handlers/api/shareLink.handler.ts @@ -1,6 +1,7 @@ import { SHARE_LINK_ASSETS_PATH, + SHARE_LINK_DOWNLOAD_PATH, SHARE_LINK_GENERATE_PATH, SHARE_LINK_PATH, SHARE_LINK_PEOPLE_PATH @@ -22,4 +23,8 @@ export const generateShareLink = async (filters: ShareLinkFilters) => { export const getShareLinkPeople = async (token: string) => { return API.get(SHARE_LINK_PEOPLE_PATH(token)); +} + +export const downloadShareLink = async (token: string, assetIds: string[]) => { + return API.post(SHARE_LINK_DOWNLOAD_PATH(token), { assetIds }); } \ No newline at end of file diff --git a/src/helpers/gemini.helper.ts b/src/helpers/gemini.helper.ts index bfe853e..959f59e 100644 --- a/src/helpers/gemini.helper.ts +++ b/src/helpers/gemini.helper.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { removeNullOrUndefinedProperties } from "./data.helper"; const gemini = new GoogleGenerativeAI(ENV.GEMINI_API_KEY); -const model = gemini.getGenerativeModel({ model: "gemini-1.5-flash" }); +const model = gemini.getGenerativeModel({ model: "gemini-2.0-flash" }); interface FindQuery { query: string; @@ -80,9 +80,12 @@ export const parseFindQuery = async (query: string): Promise => { } }); + console.log("response from gemini", response.text()); + const parsedResponse = JSON.parse(response.text()) as FindQuery; const cleanedResponse = { ...parsedResponse }; + return removeNullOrUndefinedProperties(cleanedResponse) as any as FindQuery; } diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 649a4b7..4954850 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -5,6 +5,8 @@ import { ThemeProvider } from "next-themes"; import { ENV } from "@/config/environment"; import ConfigContext, { ConfigContextType } from "@/contexts/ConfigContext"; import { useRef } from "react"; +import { queryClient } from "@/config/queryClient"; +import { QueryClientProvider } from "@tanstack/react-query"; interface AppPropsWithProps extends AppProps { props: ConfigContextType; } @@ -13,11 +15,13 @@ const App = ({ Component, pageProps, ...props }: AppPropsWithProps) => { return ( - - - - - + + + + + + + ); }; diff --git a/src/pages/albums/potential-albums.tsx b/src/pages/albums/potential-albums.tsx index e715b5a..509de92 100644 --- a/src/pages/albums/potential-albums.tsx +++ b/src/pages/albums/potential-albums.tsx @@ -66,10 +66,6 @@ export default function PotentialAlbums() { return createAlbum({ ...formData, assetIds: config.selectedIds, - albumUsers: [{ - role: "editor", - userId: id, - }] }).then(() => { toast({ title: "Album created", diff --git a/src/pages/api/albums/[id]/assets.ts b/src/pages/api/albums/[id]/assets.ts index c82df39..8ed26f8 100644 --- a/src/pages/api/albums/[id]/assets.ts +++ b/src/pages/api/albums/[id]/assets.ts @@ -3,13 +3,10 @@ import { NextApiRequest } from "next"; import { db } from "@/config/db"; import { getCurrentUser } from "@/handlers/serverUtils/user.utils"; import { NextApiResponse } from "next"; -import { albums } from "@/schema/albums.schema"; -import { count, desc, eq, min, max, sql, and, asc, isNotNull } from "drizzle-orm"; +import { and, eq, isNotNull } from "drizzle-orm"; import { assets } from "@/schema/assets.schema"; import { albumsAssetsAssets } from "@/schema/albumAssetsAssets.schema"; -import { users } from "@/schema/users.schema"; import { assetFaces, exif, person } from "@/schema"; -import { IAlbum } from "@/types/album"; export default async function handler( req: NextApiRequest, diff --git a/src/pages/api/albums/[id]/people.ts b/src/pages/api/albums/[id]/people.ts index 63b7392..81f3b3c 100644 --- a/src/pages/api/albums/[id]/people.ts +++ b/src/pages/api/albums/[id]/people.ts @@ -4,12 +4,10 @@ import { db } from "@/config/db"; import { getCurrentUser } from "@/handlers/serverUtils/user.utils"; import { NextApiResponse } from "next"; import { albums } from "@/schema/albums.schema"; -import { count, desc, eq, min, max, sql, and, asc, isNotNull } from "drizzle-orm"; +import { count, desc, eq, and, isNotNull } from "drizzle-orm"; import { assets } from "@/schema/assets.schema"; import { albumsAssetsAssets } from "@/schema/albumAssetsAssets.schema"; -import { users } from "@/schema/users.schema"; -import { assetFaces, exif, person } from "@/schema"; -import { IAlbum } from "@/types/album"; +import { assetFaces, person } from "@/schema"; export default async function handler( req: NextApiRequest, diff --git a/src/pages/api/albums/[id]/public-info.ts b/src/pages/api/albums/[id]/public-info.ts index 33333ab..07fdef5 100644 --- a/src/pages/api/albums/[id]/public-info.ts +++ b/src/pages/api/albums/[id]/public-info.ts @@ -1,7 +1,6 @@ import { NextApiRequest } from "next"; import { db } from "@/config/db"; -import { getCurrentUser } from "@/handlers/serverUtils/user.utils"; import { NextApiResponse } from "next"; import { albums } from "@/schema/albums.schema"; import { count, eq, min, max, sql, and } from "drizzle-orm"; diff --git a/src/pages/api/albums/list.ts b/src/pages/api/albums/list.ts index 0174da7..0624c44 100644 --- a/src/pages/api/albums/list.ts +++ b/src/pages/api/albums/list.ts @@ -7,7 +7,6 @@ import { albums } from "@/schema/albums.schema"; import { count, desc, eq, min, max, sql, and, sum, isNotNull } from "drizzle-orm"; import { assets } from "@/schema/assets.schema"; import { albumsAssetsAssets } from "@/schema/albumAssetsAssets.schema"; -import { users } from "@/schema/users.schema"; import { assetFaces, exif, person } from "@/schema"; import { IAlbum } from "@/types/album"; diff --git a/src/pages/api/albums/potential-albums-assets.ts b/src/pages/api/albums/potential-albums-assets.ts index fa725b2..bc860c2 100644 --- a/src/pages/api/albums/potential-albums-assets.ts +++ b/src/pages/api/albums/potential-albums-assets.ts @@ -1,10 +1,7 @@ -// Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import { CHART_COLORS } from "@/config/constants/chart.constant"; import { db } from "@/config/db"; import { getCurrentUser } from "@/handlers/serverUtils/user.utils"; import { isFlipped } from "@/helpers/asset.helper"; -import { exif } from "@/schema"; -import { count, desc, isNotNull, ne, sql } from "drizzle-orm"; +import { sql } from "drizzle-orm"; import type { NextApiRequest, NextApiResponse } from "next"; const SELECT_ORPHAN_PHOTOS = (date: string, ownerId: string) => @@ -39,6 +36,8 @@ const SELECT_ORPHAN_PHOTOS = (date: string, ownerId: string) => AND a."ownerId" = '${ownerId}' AND e."dateTimeOriginal"::date = '${date}' AND a."isVisible" = true + ORDER BY + e."dateTimeOriginal" DESC `); export default async function handler( diff --git a/src/pages/api/albums/potential-albums-dates.ts b/src/pages/api/albums/potential-albums-dates.ts index ebbd867..ad37a5e 100644 --- a/src/pages/api/albums/potential-albums-dates.ts +++ b/src/pages/api/albums/potential-albums-dates.ts @@ -4,12 +4,10 @@ import { IPotentialAlbumsDatesResponse } from "@/handlers/api/album.handler"; import { getCurrentUser } from "@/handlers/serverUtils/user.utils"; import { parseDate } from "@/helpers/date.helper"; import { albumsAssetsAssets } from "@/schema/albumAssetsAssets.schema"; -import { albums } from "@/schema/albums.schema"; import { assets } from "@/schema/assets.schema"; import { exif } from "@/schema/exif.schema"; -import { and, count, desc, eq, gte, isNotNull, isNull, sql } from "drizzle-orm"; +import { and, count, desc, eq, isNotNull, isNull, sql } from "drizzle-orm"; import type { NextApiRequest, NextApiResponse } from "next"; -import { number } from "zod"; export default async function handler( diff --git a/src/pages/api/analytics/exif/[property].ts b/src/pages/api/analytics/exif/[property].ts index 0fe51d9..dc44eed 100644 --- a/src/pages/api/analytics/exif/[property].ts +++ b/src/pages/api/analytics/exif/[property].ts @@ -1,4 +1,3 @@ -// Next.js API route support: https://nextjs.org/docs/api-routes/introduction import { db } from "@/config/db"; import { getCurrentUser } from "@/handlers/serverUtils/user.utils"; import { assets, exif } from "@/schema"; diff --git a/src/pages/api/analytics/exif/storage.ts b/src/pages/api/analytics/exif/storage.ts index 285ab28..a1eebb1 100644 --- a/src/pages/api/analytics/exif/storage.ts +++ b/src/pages/api/analytics/exif/storage.ts @@ -2,7 +2,6 @@ import { db } from "@/config/db"; import { getCurrentUser } from "@/handlers/serverUtils/user.utils"; import { humanizeBytes } from "@/helpers/string.helper"; import { assets, exif, users } from "@/schema"; -import { Value } from "@radix-ui/react-select"; import { desc, eq } from "drizzle-orm"; import { sum } from "drizzle-orm"; import { NextApiResponse } from "next"; diff --git a/src/pages/api/assets/missing-location-albums.ts b/src/pages/api/assets/missing-location-albums.ts index 3a30e0f..20ec3d6 100644 --- a/src/pages/api/assets/missing-location-albums.ts +++ b/src/pages/api/assets/missing-location-albums.ts @@ -1,7 +1,6 @@ import { db } from "@/config/db"; import { IMissingLocationDatesResponse } from "@/handlers/api/asset.handler"; import { getCurrentUser } from "@/handlers/serverUtils/user.utils"; -import { parseDate } from "@/helpers/date.helper"; import { assets, exif } from "@/schema"; import { albumsAssetsAssets } from "@/schema/albumAssetsAssets.schema"; import { albums } from "@/schema/albums.schema"; diff --git a/src/pages/api/assets/missing-location-dates.ts b/src/pages/api/assets/missing-location-dates.ts index 5cde150..62b50f8 100644 --- a/src/pages/api/assets/missing-location-dates.ts +++ b/src/pages/api/assets/missing-location-dates.ts @@ -1,5 +1,3 @@ -// Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import { CHART_COLORS } from "@/config/constants/chart.constant"; import { db } from "@/config/db"; import { IMissingLocationDatesResponse } from "@/handlers/api/asset.handler"; import { getCurrentUser } from "@/handlers/serverUtils/user.utils"; diff --git a/src/pages/api/find/search.ts b/src/pages/api/find/search.ts index 471bc40..3e715ed 100644 --- a/src/pages/api/find/search.ts +++ b/src/pages/api/find/search.ts @@ -1,19 +1,20 @@ import { db } from '@/config/db'; import { ENV } from '@/config/environment'; import { getCurrentUser } from '@/handlers/serverUtils/user.utils'; -import { cleanUpAsset, cleanUpAssets, isFlipped } from '@/helpers/asset.helper'; +import { cleanUpAsset, isFlipped } from '@/helpers/asset.helper'; import { parseFindQuery } from '@/helpers/gemini.helper'; -import { assetFaces, assets, person } from '@/schema'; +import { person } from '@/schema'; import { Person } from '@/schema/person.schema'; -import { and, eq, inArray } from 'drizzle-orm'; +import { inArray } from 'drizzle-orm'; import { NextApiRequest, NextApiResponse } from 'next'; export default async function search(req: NextApiRequest, res: NextApiResponse) { - const { query } = req.body; - const currentUser = await getCurrentUser(req); - const parsedQuery = await parseFindQuery(query as string); - const { personIds } = parsedQuery; - const url = ENV.IMMICH_URL + "/api/search/smart"; + try { + const { query } = req.body; + const currentUser = await getCurrentUser(req); + const parsedQuery = await parseFindQuery(query as string); + const { personIds } = parsedQuery; + const url = ENV.IMMICH_URL + "/api/search/smart"; let dbPeople: Person[] = []; if (personIds) { @@ -57,7 +58,11 @@ export default async function search(req: NextApiRequest, res: NextApiResponse) }, }); }).catch(err => { - res.status(500).json({ error: err.message }); + res.status(500).json({ message: err.message }); }); + } catch (err: any) { + console.error(err); + res.status(500).json({ message: err.message || "Failed to parse query" }); + } } \ No newline at end of file diff --git a/src/pages/api/health.ts b/src/pages/api/health.ts new file mode 100644 index 0000000..6acd1f6 --- /dev/null +++ b/src/pages/api/health.ts @@ -0,0 +1,9 @@ +import { NextApiRequest, NextApiResponse } from 'next'; + +export default function handler(req: NextApiRequest, res: NextApiResponse) { + if (req.method !== 'GET') { + return res.status(405).json({ message: 'Method not allowed' }); + } + + return res.status(200).json({ status: 'healthy' }); +} \ No newline at end of file diff --git a/src/pages/api/immich-proxy/[...path].ts b/src/pages/api/immich-proxy/[...path].ts index bc5187a..95afe27 100644 --- a/src/pages/api/immich-proxy/[...path].ts +++ b/src/pages/api/immich-proxy/[...path].ts @@ -1,5 +1,3 @@ -// pages/api/proxy/[...path].ts - import { ENV } from '@/config/environment'; import { getCurrentUser } from '@/handlers/serverUtils/user.utils'; import { getUserHeaders } from '@/helpers/user.helper'; diff --git a/src/pages/api/people/[id]/similar-faces.ts b/src/pages/api/people/[id]/similar-faces.ts index 32741d3..4a2e01a 100644 --- a/src/pages/api/people/[id]/similar-faces.ts +++ b/src/pages/api/people/[id]/similar-faces.ts @@ -1,9 +1,7 @@ // Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import { CHART_COLORS } from "@/config/constants/chart.constant"; import { db } from "@/config/db"; import { getCurrentUser } from "@/handlers/serverUtils/user.utils"; -import { stringToBoolean } from "@/helpers/data.helper"; -import { assetFaces, assets, exif, person } from "@/schema"; +import { assetFaces, person } from "@/schema"; import { faceSearch } from "@/schema/faceSearch.schema"; import { and, cosineDistance, desc, eq, gt, ne, sql } from "drizzle-orm"; import type { NextApiRequest, NextApiResponse } from "next"; diff --git a/src/pages/api/share-link/[token]/assets.ts b/src/pages/api/share-link/[token]/assets.ts index c6338ae..9b3892e 100644 --- a/src/pages/api/share-link/[token]/assets.ts +++ b/src/pages/api/share-link/[token]/assets.ts @@ -2,7 +2,7 @@ import { db } from "@/config/db"; import { ENV } from "@/config/environment"; import { desc, gte, lte } from "drizzle-orm"; import { eq, inArray } from "drizzle-orm"; -import { assetFaces, assets, exif, person } from "@/schema"; +import { assetFaces, assets, exif } from "@/schema"; import { and } from "drizzle-orm"; import { JsonWebTokenError, sign, verify } from "jsonwebtoken"; import { NextApiResponse } from "next"; diff --git a/src/pages/api/share-link/[token]/download.ts b/src/pages/api/share-link/[token]/download.ts new file mode 100644 index 0000000..9915a03 --- /dev/null +++ b/src/pages/api/share-link/[token]/download.ts @@ -0,0 +1,62 @@ +import { ENV } from "@/config/environment"; +import { JsonWebTokenError, verify } from "jsonwebtoken"; +import { NextApiResponse } from "next"; + +import { NextApiRequest } from "next"; +import { getUserHeaders } from "@/helpers/user.helper"; + +interface ShareLinkFilters { + personIds: string[]; + albumIds: string[]; + startDate: string; + endDate: string; +} + +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + const { token } = req.query; + const { assetIds } = req.body; + try { + if (!token) { + return res.status(404).json({ message: "Token not found" }); + } + if (req.method !== "POST") { + return res.status(405).json({ message: "Method not allowed" }); + } + + const decoded = verify(token as string, ENV.JWT_SECRET); + + if (!decoded) { + return res.status(401).json({ message: "Unauthorized" }); + } + + const targetUrl = `${ENV.IMMICH_URL}/api/download/archive`; + + const response = await fetch(targetUrl, { + method: 'POST', + body: JSON.stringify({ assetIds }), + headers: getUserHeaders({ isUsingShareKey: true }, { + 'Content-Type': 'application/json', + }), + }) + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + + // Get the image data from the response + const imageBuffer = await response.arrayBuffer() + + // Set the appropriate headers for the image response + res.setHeader('Content-Type', response.headers.get('Content-Type') || 'image/png') + res.setHeader('Content-Length', imageBuffer.byteLength) + + // Send the image data + res.send(Buffer.from(imageBuffer)) + + } catch (error) { + if (error instanceof JsonWebTokenError) { + return res.status(401).json({ message: "Please check your link and try again. Looks like it's expired." }); + } + return res.status(500).json({ message: (error as Error).message }); + } +} \ No newline at end of file diff --git a/src/pages/api/users/login.ts b/src/pages/api/users/login.ts index 9410e7d..0125aea 100644 --- a/src/pages/api/users/login.ts +++ b/src/pages/api/users/login.ts @@ -1,7 +1,5 @@ -// pages/api/proxy.js - import { appConfig } from "@/config/app.config"; -import { getCurrentUser, loginUser } from "@/handlers/serverUtils/user.utils"; +import { loginUser } from "@/handlers/serverUtils/user.utils"; import { serializeCookie } from "@/lib/cookie"; import { NextApiRequest, NextApiResponse } from "next"; diff --git a/src/pages/assets/missing-locations.tsx b/src/pages/assets/missing-locations.tsx index 2105088..3517254 100644 --- a/src/pages/assets/missing-locations.tsx +++ b/src/pages/assets/missing-locations.tsx @@ -3,9 +3,7 @@ import MissingLocationDates from "@/components/assets/missing-location/MissingLo import TagMissingLocationDialog from "@/components/assets/missing-location/TagMissingLocationDialog/TagMissingLocationDialog"; import PageLayout from "@/components/layouts/PageLayout"; import Header from "@/components/shared/Header"; -import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; -import { useToast } from "@/components/ui/use-toast"; import MissingLocationContext, { IMissingLocationConfig, } from "@/contexts/MissingLocationContext"; diff --git a/src/pages/find/index.tsx b/src/pages/find/index.tsx index a714348..aec79b4 100644 --- a/src/pages/find/index.tsx +++ b/src/pages/find/index.tsx @@ -1,18 +1,13 @@ -import "yet-another-react-lightbox/styles.css"; import FindInput from '@/components/find/FindInput'; import PageLayout from '@/components/layouts/PageLayout'; import Header from '@/components/shared/Header'; import Loader from '@/components/ui/loader'; -import { ASSET_PREVIEW_PATH, ASSET_THUMBNAIL_PATH } from '@/config/routes'; +import { ASSET_PREVIEW_PATH } from '@/config/routes'; import { useConfig } from '@/contexts/ConfigContext'; import { findAssets } from '@/handlers/api/asset.handler'; import { IAsset } from '@/types/asset'; -import { ArrowUpRight, Captions, Megaphone, Search, Speaker, TriangleAlert, WandSparkles } from 'lucide-react'; -import Image from 'next/image'; +import { Search, TriangleAlert, WandSparkles } from 'lucide-react'; import React, { useMemo, useState } from 'react' -import Lightbox from 'yet-another-react-lightbox'; -import { Button } from "@/components/ui/button"; -import Link from "next/link"; import AssetGrid from "@/components/shared/AssetGrid"; import FloatingBar from "@/components/shared/FloatingBar"; import AssetsBulkDeleteButton from "@/components/shared/AssetsBulkDeleteButton"; @@ -39,6 +34,7 @@ export default function FindPage() { const [assets, setAssets] = useState([]); const [loading, setLoading] = useState(false); const [filters, setFilters] = useState({}); + const [error, setError] = useState(null); const slides = useMemo( () => @@ -76,6 +72,9 @@ export default function FindPage() { setAssets(assets); setFilters(_filters); }) + .catch((error: any) => { + setError(error.message || error.error || "Failed to fetch assets"); + }) .finally(() => { setLoading(false); }); @@ -87,7 +86,7 @@ export default function FindPage() { const handleDelete = (ids: string[]) => { setSelectedIds([]); - setAssets(assets.filter((asset) => !ids.includes(asset.id))); + setAssets(assets.filter((asset) => !ids.includes(asset.id))); } @@ -111,6 +110,18 @@ export default function FindPage() {
} + else if (error) { + return ( + +
+ +

Oops, something went wrong

+

+ Error: {error} +

+
+ ) + } else if (query.length === 0) { return (
diff --git a/src/pages/people/[personId].tsx b/src/pages/people/[personId].tsx index d206988..187dff7 100644 --- a/src/pages/people/[personId].tsx +++ b/src/pages/people/[personId].tsx @@ -2,12 +2,9 @@ import PageLayout from '@/components/layouts/PageLayout'; import PersonAlbumList from '@/components/people/info/PersonAlbumList'; import PersonCityList from '@/components/people/info/PersonCityList'; import Header from '@/components/shared/Header'; -import { Button } from '@/components/ui/button'; import Loader from '@/components/ui/loader'; -import { ASSET_THUMBNAIL_PATH, PERSON_THUBNAIL_PATH } from '@/config/routes'; -import { useConfig } from '@/contexts/ConfigContext'; +import { PERSON_THUBNAIL_PATH } from '@/config/routes'; import { getPersonInfo } from '@/handlers/api/person.handler'; -import { IAlbum } from '@/types/album'; import { IPerson } from '@/types/person' import { GalleryThumbnails, MapPin, Plus } from 'lucide-react'; import Image from 'next/image'; diff --git a/src/pages/s/[token].tsx b/src/pages/s/[token].tsx index 0abe807..d842d40 100644 --- a/src/pages/s/[token].tsx +++ b/src/pages/s/[token].tsx @@ -1,7 +1,7 @@ import PageLayout from '@/components/layouts/PageLayout' import Header from '@/components/shared/Header' import Loader from '@/components/ui/loader' -import React, { useEffect, useMemo, useState } from 'react' +import React, { useEffect, useState } from 'react' import { useRouter } from 'next/router' import { Camera } from 'lucide-react' import { humanizeNumber } from '@/helpers/string.helper'