Skip to content

Commit 8ff0417

Browse files
committed
path improvements
1 parent dbee379 commit 8ff0417

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

  • apps/sim/app

apps/sim/app/api/workspaces/[id]/files/download/route.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ function safeZipPath(path: string): string {
2929
.join('/')
3030
}
3131

32+
function withZipPathSuffix(path: string, suffix: number): string {
33+
const slashIndex = path.lastIndexOf('/')
34+
const directory = slashIndex >= 0 ? `${path.slice(0, slashIndex + 1)}` : ''
35+
const filename = slashIndex >= 0 ? path.slice(slashIndex + 1) : path
36+
const dotIndex = filename.lastIndexOf('.')
37+
38+
return dotIndex > 0
39+
? `${directory}${filename.slice(0, dotIndex)} (${suffix})${filename.slice(dotIndex)}`
40+
: `${directory}${filename} (${suffix})`
41+
}
42+
3243
function collectDescendantFolderIds(
3344
selectedFolderIds: string[],
3445
folders: Array<{ id: string; parentId: string | null }>
@@ -112,11 +123,7 @@ export const GET = withRouteHandler(
112123
let zipPath = basePath
113124
let suffix = 2
114125
while (usedPaths.has(zipPath)) {
115-
const dotIndex = basePath.lastIndexOf('.')
116-
zipPath =
117-
dotIndex > 0
118-
? `${basePath.slice(0, dotIndex)} (${suffix})${basePath.slice(dotIndex)}`
119-
: `${basePath} (${suffix})`
126+
zipPath = withZipPathSuffix(basePath, suffix)
120127
suffix++
121128
}
122129
usedPaths.add(zipPath)

apps/sim/app/workspace/[workspaceId]/files/files.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ const parseRowId = (rowId: string): { kind: 'file' | 'folder'; id: string } => {
141141
return { kind: 'file', id: rowId }
142142
}
143143

144+
const hasExternalFiles = (dataTransfer: DataTransfer): boolean =>
145+
dataTransfer.types.includes('Files')
146+
144147
function formatFileType(mimeType: string | null, filename: string): string {
145148
if (mimeType && MIME_TYPE_LABELS[mimeType]) {
146149
return MIME_TYPE_LABELS[mimeType]
@@ -672,12 +675,12 @@ export function Files() {
672675
},
673676
onDragOver: (e: DragEvent<HTMLTableRowElement>, rowId) => {
674677
const sourceRowIds = draggedRowIdsRef.current
675-
const hasExternalFiles = e.dataTransfer.types.includes('Files')
676-
if (!hasExternalFiles && isInvalidDropTarget(rowId, sourceRowIds)) return
678+
const isExternalFileDrag = hasExternalFiles(e.dataTransfer)
679+
if (!isExternalFileDrag && isInvalidDropTarget(rowId, sourceRowIds)) return
677680

678681
e.preventDefault()
679682
e.stopPropagation()
680-
e.dataTransfer.dropEffect = hasExternalFiles ? 'copy' : 'move'
683+
e.dataTransfer.dropEffect = isExternalFileDrag ? 'copy' : 'move'
681684
setActiveDropTargetId(rowId)
682685
},
683686
onDragLeave: (e: DragEvent<HTMLTableRowElement>, rowId) => {
@@ -771,22 +774,26 @@ export function Files() {
771774
}
772775

773776
const handleDragEnter = (e: React.DragEvent) => {
777+
if (!hasExternalFiles(e.dataTransfer)) return
774778
e.preventDefault()
775779
dragCounterRef.current++
776-
if (e.dataTransfer.types.includes('Files')) setIsDraggingOver(true)
780+
setIsDraggingOver(true)
777781
}
778782

779-
const handleDragLeave = () => {
783+
const handleDragLeave = (e: React.DragEvent) => {
784+
if (!hasExternalFiles(e.dataTransfer)) return
780785
dragCounterRef.current--
781786
if (dragCounterRef.current === 0) setIsDraggingOver(false)
782787
}
783788

784789
const handleDragOver = (e: React.DragEvent) => {
790+
if (!hasExternalFiles(e.dataTransfer)) return
785791
e.preventDefault()
786792
e.dataTransfer.dropEffect = 'copy'
787793
}
788794

789795
const handleDrop = async (e: React.DragEvent) => {
796+
if (!hasExternalFiles(e.dataTransfer)) return
790797
e.preventDefault()
791798
dragCounterRef.current = 0
792799
setIsDraggingOver(false)

0 commit comments

Comments
 (0)