mirror of
https://github.com/rustfs/console.git
synced 2026-08-28 19:47:21 +08:00
fix: normalize upload objects prefix rustfs/rustfs#2768
This commit is contained in:
@@ -8,6 +8,7 @@ import { Progress } from "@/components/ui/progress"
|
||||
import { useAddUploadFiles, useTaskPanelOpen } from "@/contexts/task-context"
|
||||
import { formatBytes } from "@/lib/functions"
|
||||
import { useMessage } from "@/lib/feedback/message"
|
||||
import { buildUploadObjectKey, normalizeUploadPrefix } from "@/lib/object-upload"
|
||||
import { RiDeleteBinLine, RiFileAddLine, RiFolderAddLine, RiUploadCloudLine } from "@remixicon/react"
|
||||
import { useVirtualizer } from "@tanstack/react-virtual"
|
||||
import * as React from "react"
|
||||
@@ -228,7 +229,7 @@ export function ObjectUploadPicker({
|
||||
}
|
||||
}, [canUpload, onShowChange, show])
|
||||
|
||||
const effectivePrefix = editablePrefix.replace(/\/$/, "") || ""
|
||||
const effectivePrefix = normalizeUploadPrefix(editablePrefix)
|
||||
|
||||
const ensureCapacity = React.useCallback(
|
||||
(incoming: number): boolean => {
|
||||
@@ -416,7 +417,7 @@ export function ObjectUploadPicker({
|
||||
try {
|
||||
const tasks = items.map(({ relativePath, file }) => ({
|
||||
file,
|
||||
key: effectivePrefix ? `${effectivePrefix}/${relativePath}` : relativePath,
|
||||
key: buildUploadObjectKey(effectivePrefix, relativePath),
|
||||
}))
|
||||
const batchSize = 50
|
||||
let processed = 0
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export function normalizeUploadPrefix(prefix) {
|
||||
return prefix.trim().replace(/^\/+/, "").replace(/\/+$/, "")
|
||||
}
|
||||
|
||||
export function buildUploadObjectKey(prefix, relativePath) {
|
||||
const normalizedPrefix = normalizeUploadPrefix(prefix)
|
||||
const normalizedRelativePath = relativePath.replace(/^\/+/, "")
|
||||
return normalizedPrefix ? `${normalizedPrefix}/${normalizedRelativePath}` : normalizedRelativePath
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
export function normalizeUploadPrefix(prefix: string): string {
|
||||
return prefix.trim().replace(/^\/+/, "").replace(/\/+$/, "")
|
||||
}
|
||||
|
||||
export function buildUploadObjectKey(prefix: string, relativePath: string): string {
|
||||
const normalizedPrefix = normalizeUploadPrefix(prefix)
|
||||
const normalizedRelativePath = relativePath.replace(/^\/+/, "")
|
||||
return normalizedPrefix ? `${normalizedPrefix}/${normalizedRelativePath}` : normalizedRelativePath
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import test from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
import { buildUploadObjectKey, normalizeUploadPrefix } from "../../lib/object-upload.js"
|
||||
|
||||
test("normalizeUploadPrefix removes leading and trailing slashes", () => {
|
||||
assert.equal(normalizeUploadPrefix("/Normal/"), "Normal")
|
||||
assert.equal(normalizeUploadPrefix("//Normal//"), "Normal")
|
||||
})
|
||||
|
||||
test("buildUploadObjectKey avoids leading slash when prefix starts with slash", () => {
|
||||
assert.equal(buildUploadObjectKey("/Normal/", "file.txt"), "Normal/file.txt")
|
||||
})
|
||||
|
||||
test("buildUploadObjectKey keeps nested relative paths under the normalized prefix", () => {
|
||||
assert.equal(buildUploadObjectKey("Normal/", "folder/file.txt"), "Normal/folder/file.txt")
|
||||
})
|
||||
|
||||
test("buildUploadObjectKey uses relative path when prefix is empty or slash only", () => {
|
||||
assert.equal(buildUploadObjectKey("", "file.txt"), "file.txt")
|
||||
assert.equal(buildUploadObjectKey("/", "file.txt"), "file.txt")
|
||||
})
|
||||
Reference in New Issue
Block a user