fix: decode URI components in object path handling
- Added decodeURIComponent to the objectName in getObjectByPathname and getObjectName functions to ensure proper handling of encoded paths. - Updated newNamePath in renameProxy to decode the pathname before processing. - Removed redundant comment regarding file renaming in renameProxy.
This commit is contained in:
@@ -201,6 +201,8 @@ export const getObjectByPathname = (opts: {
|
||||
prefix = `${user}/`; // root/resources
|
||||
}
|
||||
let objectName = opts.pathname.replace(replaceKey, prefix);
|
||||
// 解码decodeURIComponent编码的路径
|
||||
objectName = decodeURIComponent(objectName);
|
||||
return { prefix, replaceKey, objectName, user, app };
|
||||
}
|
||||
export const getObjectName = async (req: IncomingMessage, opts?: { checkOwner?: boolean }) => {
|
||||
@@ -217,6 +219,8 @@ export const getObjectName = async (req: IncomingMessage, opts?: { checkOwner?:
|
||||
} else {
|
||||
objectName = pathname.replace(`/${user}/${app}/`, `${user}/`); // root/resources
|
||||
}
|
||||
// 解码decodeURIComponent编码的路径
|
||||
objectName = decodeURIComponent(objectName);
|
||||
owner = user;
|
||||
let isOwner = undefined;
|
||||
let loginUser: Awaited<ReturnType<typeof getLoginUser>> = null;
|
||||
@@ -287,7 +291,7 @@ export const renameProxy = async (req: IncomingMessage, res: ServerResponse, opt
|
||||
}
|
||||
const newUrl = new URL(newName, 'http://localhost');
|
||||
const version = _u.searchParams.get('version') || '1.0.0';
|
||||
const newNamePath = newUrl.pathname;
|
||||
const newNamePath = decodeURIComponent(newUrl.pathname);
|
||||
// 确保 newName 有正确的前缀路径
|
||||
|
||||
const newObject = getObjectByPathname({ pathname: newNamePath, version });
|
||||
@@ -314,7 +318,6 @@ export const renameProxy = async (req: IncomingMessage, res: ServerResponse, opt
|
||||
await oss.deleteObject(obj.name);
|
||||
}
|
||||
} else {
|
||||
// 重命名文件
|
||||
await oss.copyObject(objectName, newObjectName);
|
||||
await oss.deleteObject(objectName);
|
||||
copiedCount = 1;
|
||||
|
||||
Reference in New Issue
Block a user