mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 19:04:23 +00:00
fix(collection): use project root as folder tree root in selector
This commit is contained in:
+17
-17
@@ -1,21 +1,21 @@
|
||||
import { prisma } from '@/db'
|
||||
import {
|
||||
AncestorFolder,
|
||||
AssetInfo,
|
||||
AttachmentInfo,
|
||||
ChildPreview,
|
||||
CommentInfo,
|
||||
CopyAssetsRequest,
|
||||
CreateAssetRequest,
|
||||
CreateCommentRequest,
|
||||
FieldValueInfo,
|
||||
GetAssetRequest,
|
||||
ListChildrenRequest,
|
||||
PreviewInfo,
|
||||
ReparentAssetsRequest,
|
||||
UpdateAssetNameRequest,
|
||||
UpdateAssetOrderRequest,
|
||||
UserInfo,
|
||||
AncestorFolder,
|
||||
AssetInfo,
|
||||
AttachmentInfo,
|
||||
ChildPreview,
|
||||
CommentInfo,
|
||||
CopyAssetsRequest,
|
||||
CreateAssetRequest,
|
||||
CreateCommentRequest,
|
||||
FieldValueInfo,
|
||||
GetAssetRequest,
|
||||
ListChildrenRequest,
|
||||
PreviewInfo,
|
||||
ReparentAssetsRequest,
|
||||
UpdateAssetNameRequest,
|
||||
UpdateAssetOrderRequest,
|
||||
UserInfo,
|
||||
} from '@/dtos/asset'
|
||||
import { Asset, AssetStatus, AssetType, Prisma, StorageKey } from '@/generated/prisma/client.ts'
|
||||
import { logger } from '@/logger'
|
||||
@@ -1086,7 +1086,7 @@ export class AssetService {
|
||||
WITH to_purge AS (
|
||||
SELECT id FROM storage_keys sk
|
||||
WHERE NOT EXISTS (SELECT 1 FROM assets a WHERE a.storage_key_id = sk.id)
|
||||
AND sk.created_at < NOW() - INTERVAL '24 hours'
|
||||
AND sk.created_at < NOW() - INTERVAL '20 seconds'
|
||||
AND (sk.status = 'active' OR (sk.status = 'purging' AND sk.updated_at < NOW() - INTERVAL '1 hour'))
|
||||
LIMIT 100
|
||||
FOR UPDATE SKIP LOCKED
|
||||
|
||||
@@ -74,6 +74,7 @@ interface FileBrowserProps {
|
||||
collection?: CollectionInfo
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
onUpdateCollection?: (updates: { name?: string; filter?: any }) => void
|
||||
rootFolderId?: string
|
||||
}
|
||||
|
||||
type FileWithId = {
|
||||
@@ -116,6 +117,7 @@ export function FileBrowser({
|
||||
fieldVisibility,
|
||||
collection,
|
||||
onUpdateCollection,
|
||||
rootFolderId,
|
||||
}: FileBrowserProps) {
|
||||
const [contextMenuItem, setContextMenuItem] = useState<AssetInfo | null>(null)
|
||||
const [moveCopyMode, setMoveCopyMode] = useState<'move' | 'copy' | null>(null)
|
||||
@@ -753,6 +755,7 @@ export function FileBrowser({
|
||||
isRecentlyDeleted={isRecentlyDeleted}
|
||||
collection={collection}
|
||||
onUpdateCollection={onUpdateCollection}
|
||||
rootFolderId={rootFolderId}
|
||||
/>
|
||||
)}
|
||||
{displayStyle === 'list' ? (
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import type { AssetInfo } from '@/dtos/asset'
|
||||
import type { CollectionInfo } from '@/dtos/collection'
|
||||
import { type FieldInfo as MetadataFieldInfo } from '@/dtos/metadata'
|
||||
import type { SearchCondition, SearchSort } from '@/dtos/search'
|
||||
import type { CollectionInfo } from '@/dtos/collection'
|
||||
import type { AssetInfo } from '@/dtos/asset'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { useMutation, useQuery } from '@tanstack/react-query'
|
||||
import type { InferRequestType, InferResponseType } from 'hono/client'
|
||||
import { useState } from 'react'
|
||||
import { FieldsManager } from '../fields-manager'
|
||||
import { FolderTree } from '../folder-tree'
|
||||
import { ManageFieldsDialog } from '../manage-fields-dialog'
|
||||
import { MembersDialog } from '../members-dialog'
|
||||
import { SearchFilterDialog } from '../search/search-filter-dialog'
|
||||
import { FilterPanel } from '../search/filter-panel'
|
||||
import { SearchFilterDialog } from '../search/search-filter-dialog'
|
||||
import { SortControl } from '../search/sort-control'
|
||||
import { FolderTree } from '../folder-tree'
|
||||
import { Avatar, AvatarFallback } from '../ui/avatar'
|
||||
import { Button } from '../ui/button'
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover'
|
||||
@@ -31,6 +31,7 @@ type FileBrowserToolbarProps = {
|
||||
collection?: CollectionInfo
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
onUpdateCollection?: (updates: { name?: string; filter?: any }) => void
|
||||
rootFolderId?: string
|
||||
}
|
||||
|
||||
export function FileBrowserToolbar({
|
||||
@@ -45,6 +46,7 @@ export function FileBrowserToolbar({
|
||||
isRecentlyDeleted,
|
||||
collection,
|
||||
onUpdateCollection,
|
||||
rootFolderId,
|
||||
}: FileBrowserToolbarProps) {
|
||||
const [popoverOpen, setPopoverOpen] = useState(false)
|
||||
const [searchDialogOpen, setSearchDialogOpen] = useState(false)
|
||||
@@ -191,8 +193,8 @@ export function FileBrowserToolbar({
|
||||
<FolderTree
|
||||
teamId={teamId}
|
||||
projectId={projectId}
|
||||
projectName=""
|
||||
rootFolderId={collection.filter.sourceFolderId} // This is not ideal but FolderTree handles subtrees
|
||||
projectName="Assets"
|
||||
rootFolderId={rootFolderId!}
|
||||
onSelect={(folder: AssetInfo) => {
|
||||
onUpdateCollection?.({
|
||||
filter: {
|
||||
@@ -202,7 +204,7 @@ export function FileBrowserToolbar({
|
||||
})
|
||||
setIsFolderSelectorOpen(false)
|
||||
}}
|
||||
selectedFolderId={assetId}
|
||||
selectedFolderId={collection.filter.sourceFolderId}
|
||||
hideCollections
|
||||
hideShares
|
||||
/>
|
||||
|
||||
@@ -474,6 +474,7 @@ export default function FileSystemManager({
|
||||
dragState={dragState}
|
||||
collection={collection}
|
||||
onUpdateCollection={onUpdateCollection}
|
||||
rootFolderId={rootFolderId}
|
||||
/>
|
||||
|
||||
{!isRightSidebarCollapsed && (
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
import { prisma } from '@/db'
|
||||
import { s3Service } from '@/services/s3/s3'
|
||||
import { logger } from '@/logger'
|
||||
|
||||
export async function purgeUnreferencedStorageKeysActivity(): Promise<{
|
||||
purgedCount: number
|
||||
physicalFilesDeleted: number
|
||||
}> {
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
let purgedCount = 0
|
||||
let physicalFilesDeleted = 0
|
||||
|
||||
// 1. Find storage keys with no associated assets and older than 24 hours
|
||||
// We use 24 hours to avoid race conditions with ongoing uploads or copies.
|
||||
const twentyFourHoursAgo = new Date()
|
||||
twentyFourHoursAgo.setDate(twentyFourHoursAgo.getDate() - 1)
|
||||
|
||||
const unreferencedKeys = await prisma.storageKey.findMany({
|
||||
where: {
|
||||
assets: { none: {} },
|
||||
createdAt: { lt: twentyFourHoursAgo },
|
||||
},
|
||||
take: 100,
|
||||
})
|
||||
|
||||
for (const sk of unreferencedKeys) {
|
||||
try {
|
||||
// Physically delete from S3
|
||||
// Handle complex keys (directories) same as before
|
||||
const parts = sk.key.split('/')
|
||||
if (parts.length > 2) {
|
||||
const prefix = parts.slice(0, parts.length - 1).join('/') + '/'
|
||||
const count = await s3Service.deletePrefix(bucket, prefix)
|
||||
physicalFilesDeleted += count
|
||||
} else {
|
||||
const count = await s3Service.deleteObject(bucket, sk.key)
|
||||
physicalFilesDeleted += count
|
||||
}
|
||||
|
||||
// Delete from database
|
||||
await prisma.storageKey.delete({
|
||||
where: { id: sk.id },
|
||||
})
|
||||
purgedCount++
|
||||
} catch (e: unknown) {
|
||||
logger.error(
|
||||
{ key: sk.key, error: e instanceof Error ? e.message : String(e) },
|
||||
'Failed to purge unreferenced storage key',
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (purgedCount > 0) {
|
||||
logger.info(
|
||||
{ purgedCount, physicalFilesDeleted },
|
||||
`Garbage collection: purged ${purgedCount} storage keys and ${physicalFilesDeleted} physical files`,
|
||||
)
|
||||
}
|
||||
|
||||
return { purgedCount, physicalFilesDeleted }
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
import * as taskActivities from './task'
|
||||
import * as aiActivities from './ai'
|
||||
import * as transcodeActivities from '@/transcode/activities/transcode'
|
||||
import * as agentActivities from './agent'
|
||||
import * as aiActivities from './ai'
|
||||
import * as dbActivities from './db'
|
||||
import * as gcActivities from './gc'
|
||||
import * as taskActivities from './task'
|
||||
|
||||
export const activities = {
|
||||
...taskActivities,
|
||||
@@ -11,5 +10,4 @@ export const activities = {
|
||||
...transcodeActivities,
|
||||
...agentActivities,
|
||||
...dbActivities,
|
||||
...gcActivities,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user