diff --git a/src/components/find/FindInput.tsx b/src/components/find/FindInput.tsx index 7b7bbf9..fa75919 100644 --- a/src/components/find/FindInput.tsx +++ b/src/components/find/FindInput.tsx @@ -6,11 +6,11 @@ import mentionStyle from './findMentionStyle'; interface FindInputProps { onSearch: (query: string) => void; + value: string; + onChange: (value: string) => void; } -export default function FindInput({ onSearch }: FindInputProps) { - - const [query, setQuery] = useState(""); +export default function FindInput({ onSearch, value, onChange }: FindInputProps) { const handleSearchPeople = async (e: any, callback: any) => { if (!e.length) return []; @@ -22,16 +22,16 @@ export default function FindInput({ onSearch }: FindInputProps) { return ( { if (e.key === 'Enter') { - onSearch(query); + onSearch(value); } }} - onChange={(e) => setQuery(e.target.value)}> + onChange={(e) => onChange(e.target.value)}> = 0} index={index} close={() => setIndex(-1)} diff --git a/src/components/ui/lazy-grid-image.tsx b/src/components/ui/lazy-grid-image.tsx index 6fd03ff..3f39d61 100644 --- a/src/components/ui/lazy-grid-image.tsx +++ b/src/components/ui/lazy-grid-image.tsx @@ -1,8 +1,11 @@ /* eslint-disable @next/next/no-img-element */ +import { humanizeDuration } from '@/helpers/string.helper' +import { PlayIcon } from '@radix-ui/react-icons' import React, { useEffect } from 'react' import { Image, ImageExtended, ThumbnailImageProps } from 'react-grid-gallery' -interface LazyImageProps extends ThumbnailImageProps> {} +interface LazyImageProps extends ThumbnailImageProps> {} + export default function LazyGridImage( props: LazyImageProps @@ -39,6 +42,12 @@ export default function LazyGridImage( ) return ( - {props.imageProps.alt +
+ {props.imageProps.alt + {props.item.isVideo &&
+ + {!!props.item.duration && {humanizeDuration(props.item.duration)}} +
} +
) } diff --git a/src/helpers/gemini.helper.ts b/src/helpers/gemini.helper.ts index 959f59e..af54e9e 100644 --- a/src/helpers/gemini.helper.ts +++ b/src/helpers/gemini.helper.ts @@ -14,7 +14,14 @@ interface FindQuery { model?: string; createdAfter?: string; state?: string; + type?: string; } + +const allowedTypes = [ + 'IMAGE', + 'VIDEO', + 'AUDIO' +] const responseSchema = { type: SchemaType.OBJECT, properties: { @@ -50,6 +57,10 @@ const responseSchema = { type: SchemaType.STRING, description: "Name of the device that the query is about" }, + type: { + type: SchemaType.STRING, + description: "One of the allowed media types (IMAGE, VIDEO, AUDIO, OTHER)", + } }, required: ["query"], }; @@ -80,9 +91,13 @@ export const parseFindQuery = async (query: string): Promise => { } }); - console.log("response from gemini", response.text()); - const parsedResponse = JSON.parse(response.text()) as FindQuery; + + if (parsedResponse.type) { + if (!allowedTypes.includes(parsedResponse.type)) { + delete parsedResponse.type; + } + } const cleanedResponse = { ...parsedResponse }; diff --git a/src/helpers/string.helper.ts b/src/helpers/string.helper.ts index 0963cb3..28e77e4 100644 --- a/src/helpers/string.helper.ts +++ b/src/helpers/string.helper.ts @@ -18,3 +18,23 @@ export const humanizeBytes = (bytes: number) => { } return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB` } + +export const humanizeDuration = (duration: string) => { + if (!duration) { + return null; + } + // Example input : 00:00:04.350 + const [hours, minutes, seconds] = duration.split(':').map(Number); + const totalSeconds = Math.round(hours * 3600 + minutes * 60 + seconds); + + if (totalSeconds < 60) { + return `${totalSeconds}s`; + } + if (totalSeconds < 3600) { + // Show only minutes + return `${Math.round(minutes)}m`; + } + + + return `${Math.round(hours)}h ${Math.round(minutes)}m`; +} diff --git a/src/pages/api/find/search.ts b/src/pages/api/find/search.ts index 3e715ed..534e931 100644 --- a/src/pages/api/find/search.ts +++ b/src/pages/api/find/search.ts @@ -1,5 +1,6 @@ import { db } from '@/config/db'; import { ENV } from '@/config/environment'; +import { ASSET_VIDEO_PATH } from '@/config/routes'; import { getCurrentUser } from '@/handlers/serverUtils/user.utils'; import { cleanUpAsset, isFlipped } from '@/helpers/asset.helper'; import { parseFindQuery } from '@/helpers/gemini.helper'; @@ -48,6 +49,7 @@ export default async function search(req: NextApiRequest, res: NextApiResponse) exifImageHeight: isFlipped(item?.exifInfo?.orientation) ? item?.exifInfo?.exifImageWidth : item?.exifInfo?.exifImageHeight, exifImageWidth: isFlipped(item?.exifInfo?.orientation) ? item?.exifInfo?.exifImageHeight : item?.exifInfo?.exifImageWidth, orientation: item?.exifInfo?.orientation, + downloadUrl: ASSET_VIDEO_PATH(item.id) } }).map(cleanUpAsset) res.status(200).json({ diff --git a/src/pages/find/index.tsx b/src/pages/find/index.tsx index e59ccf6..2ba8c8a 100644 --- a/src/pages/find/index.tsx +++ b/src/pages/find/index.tsx @@ -5,7 +5,6 @@ import Loader from '@/components/ui/loader'; 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 { Search, TriangleAlert, WandSparkles } from 'lucide-react'; import React, { useMemo, useState } from 'react' import AssetGrid from "@/components/shared/AssetGrid"; @@ -18,6 +17,7 @@ import AlbumSelectorDialog from '@/components/albums/AlbumSelectorDialog'; import { addAssetToAlbum, createAlbum } from '@/handlers/api/album.handler'; import { IAlbum, IAlbumCreate } from '@/types/album'; import { useToast } from '@/components/ui/use-toast'; // Import useToast +import { Button } from '@/components/ui/button'; // Import Button interface IFindFilters { [key: string]: string; @@ -33,6 +33,16 @@ const FILTER_KEY_MAP = { "model": "Model", "personIds": "People", } + +// Add suggestion list +const SUGGESTIONS = [ + { label: "Last week's photos", query: "Photos from last week" }, + { label: "Photos from last summer", query: "Photos taken last summer" }, + { label: "Videos from New York", query: "Videos taken in New York" }, + { label: "Photos with @alex", query: "Photos with @alex" }, // Example with person tag + { label: "Recent screenshots", query: "Screenshots taken recently" }, +]; + export default function FindPage() { // Remove local selectedIds and assets state @@ -198,10 +208,24 @@ export default function FindPage() {

Search for photos in natural language

-

{/* Centered and max-width */} +

{/* Centered and max-width */} Example: Sunset photos from last week. Use @ to search for photos of a specific person.

-

{/* Added margin top */} + {/* Render suggestions */} +

+ {SUGGESTIONS.map((suggestion) => ( + + ))} +
+

{/* Adjusted margin top */} Power tools uses Google Gemini only for parsing your query. None of your data is sent to Gemini.

@@ -261,7 +285,11 @@ export default function FindPage() { {geminiEnabled ? ( <>
- +
{/* renderContent now includes the Provider */} {renderContent()}