mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 21:44:27 +00:00
feat(search): add image similarity search (#537)
* feat(search): add image similarity search * feat(search): support pasting image attachments
This commit is contained in:
@@ -25,9 +25,10 @@ import {
|
||||
ArrowRight,
|
||||
Copy,
|
||||
Layers,
|
||||
ScanSearch,
|
||||
} from 'lucide-react'
|
||||
import { CopyContextMenuSub } from './copy-submenu'
|
||||
import type { CopyKind } from './copy-options'
|
||||
import { isImageItem, type CopyKind } from './copy-options'
|
||||
|
||||
interface FileBrowserContextMenuProps {
|
||||
item: AssetInfo | null
|
||||
@@ -36,6 +37,7 @@ interface FileBrowserContextMenuProps {
|
||||
onDelete: (items: AssetInfo[]) => void
|
||||
onDownload: (items: AssetInfo[]) => void
|
||||
onCopy?: (kind: CopyKind, items: AssetInfo[]) => void
|
||||
onFindSimilar?: (item: AssetInfo) => void
|
||||
onRestore: (items: AssetInfo[]) => void
|
||||
onArchive?: (items: AssetInfo[]) => void
|
||||
onRestoreArchive?: (items: AssetInfo[]) => void
|
||||
@@ -69,6 +71,7 @@ export function FileBrowserContextMenu({
|
||||
onDelete,
|
||||
onDownload,
|
||||
onCopy,
|
||||
onFindSimilar,
|
||||
onRestore,
|
||||
onArchive,
|
||||
onRestoreArchive,
|
||||
@@ -222,6 +225,15 @@ export function FileBrowserContextMenu({
|
||||
)
|
||||
}
|
||||
|
||||
const findSimilarItem = onFindSimilar &&
|
||||
(item.type === 'file' || item.type === 'version_stack') &&
|
||||
isImageItem(item) && (
|
||||
<ContextMenuItem onSelect={() => onFindSimilar(item)}>
|
||||
<ScanSearch className="mr-2 h-4 w-4" />
|
||||
<span>{m.find_similar()}</span>
|
||||
</ContextMenuItem>
|
||||
)
|
||||
|
||||
const contextMenuContent =
|
||||
isItemSelected && selectedIds.size > 1 ? (
|
||||
<ContextMenuContent
|
||||
@@ -234,6 +246,7 @@ export function FileBrowserContextMenu({
|
||||
<Download className="mr-2 h-4 w-4" />
|
||||
<span>{m.download()}</span>
|
||||
</ContextMenuItem>
|
||||
{findSimilarItem}
|
||||
<CopyContextMenuSub
|
||||
items={itemsToModify}
|
||||
context={{
|
||||
@@ -331,6 +344,7 @@ export function FileBrowserContextMenu({
|
||||
<Download className="mr-2 h-4 w-4" />
|
||||
<span>{m.download()}</span>
|
||||
</ContextMenuItem>
|
||||
{findSimilarItem}
|
||||
<CopyContextMenuSub
|
||||
items={itemsToModify}
|
||||
context={{
|
||||
|
||||
@@ -29,6 +29,8 @@ import { ManageVersionsDialog } from '../manage-versions-dialog'
|
||||
import { FilePreviewDialog } from '../file-preview-dialog'
|
||||
import { FileBrowserContentSkeleton } from '../loading-skeletons'
|
||||
import { FileBrowserContextMenu } from './context-menu'
|
||||
import { FindSimilarDialog } from '../search/find-similar-dialog'
|
||||
import { useSemanticSearchEnabled } from '../search/use-semantic-search-enabled'
|
||||
|
||||
import {
|
||||
AlertDialog,
|
||||
@@ -156,6 +158,13 @@ export function FileBrowser({
|
||||
allowDownload = true,
|
||||
}: FileBrowserProps) {
|
||||
const [contextMenuItem, setContextMenuItem] = useState<AssetInfo | null>(null)
|
||||
const [similarImage, setSimilarImage] = useState<AssetInfo | null>(null)
|
||||
const semanticSearchEnabled = useSemanticSearchEnabled(
|
||||
teamId,
|
||||
Boolean(
|
||||
rootFolderId && !isShareView && !isPublic && !isRecents && !isRecentlyDeleted && !collection,
|
||||
),
|
||||
)
|
||||
const [manageVersionsStackId, setManageVersionsStackId] = useState<string | null>(null)
|
||||
const [moveCopyMode, setMoveCopyMode] = useState<'move' | 'copy' | null>(null)
|
||||
const [itemsToMoveCopy, setItemsToMoveCopy] = useState<AssetInfo[]>([])
|
||||
@@ -1179,6 +1188,7 @@ export function FileBrowser({
|
||||
onDelete={handleDelete}
|
||||
onDownload={handleDownload}
|
||||
onCopy={handleCopy}
|
||||
onFindSimilar={semanticSearchEnabled && rootFolderId ? setSimilarImage : undefined}
|
||||
onNewFolder={handleNewFolder}
|
||||
onUploadFile={handleUploadFilesClick}
|
||||
onUploadFolder={handleUploadFolderClick}
|
||||
@@ -1239,6 +1249,16 @@ export function FileBrowser({
|
||||
)}
|
||||
{renderContent()}
|
||||
|
||||
{semanticSearchEnabled && similarImage && rootFolderId && (
|
||||
<FindSimilarDialog
|
||||
image={similarImage}
|
||||
folderId={rootFolderId}
|
||||
teamId={teamId}
|
||||
projectId={projectId}
|
||||
onClose={() => setSimilarImage(null)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{moveCopyMode && (
|
||||
<MoveCopyDialog
|
||||
isOpen={!!moveCopyMode}
|
||||
|
||||
@@ -112,8 +112,9 @@ export const FilePreview = ({ item, showDuration = false, matchDuration }: FileP
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full h-full flex items-center justify-center">
|
||||
<div className="relative w-full h-full flex items-center justify-center">
|
||||
<File className="w-8 h-8 fill-primary/60 stroke-0" />
|
||||
{overlay}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user