Bug:修复移动文件时的路径错误

This commit is contained in:
MarSeventh
2025-11-27 00:42:11 +08:00
parent c295e38ec8
commit a66b431fd4
15 changed files with 30 additions and 30 deletions

View File

@@ -32,7 +32,7 @@ export async function onRequest(context) {
while (folderQueue.length > 0) {
const currentFolder = folderQueue.shift();
const curFolderName = currentFolder.path.split('/').pop();
// 获取指定目录下的所有文件
const listUrl = new URL(`${url.origin}/api/manage/list?count=-1&dir=${currentFolder.path}`);
const listRequest = new Request(listUrl, request);
@@ -166,10 +166,10 @@ async function moveFile(env, fileId, newFileId, cdnUrl, url) {
throw new Error('Unsupported Channel');
}
// 更新文件夹信息
const folderPath = newFileId.split('/').slice(0, -1).join('/');
img.metadata.Folder = folderPath;
// 更新文件夹信息,根目录为空,否则为 aaa/123/ 的格式
const DirectoryPath = newFileId.split('/').slice(0, -1).join('/') === '' ? '' : newFileId.split('/').slice(0, -1).join('/') + '/';
img.metadata.Directory = DirectoryPath;
// 更新KV存储
await db.put(newFileId, img.value, { metadata: img.metadata });
await db.delete(fileId);
@@ -183,7 +183,7 @@ async function moveFile(env, fileId, newFileId, cdnUrl, url) {
const nullResponse = new Response(null, {
headers: { 'Cache-Control': 'max-age=0' },
});
const normalizedFolder = fileId.split('/').slice(0, -1).join('/');
const normalizedDist = newFileId.split('/').slice(0, -1).join('/');
await cache.put(`${url.origin}/api/randomFileList?dir=${normalizedFolder}`, nullResponse);

View File

@@ -3,21 +3,21 @@ import { getDatabase } from '../../../utils/databaseAdapter.js';
export async function onRequest(context) {
const { request, env } = context;
try {
const url = new URL(request.url);
const action = url.searchParams.get('action');
switch (action) {
case 'backup':
return await handleBackup(context);
case 'restore':
return await handleRestore(request, env);
default:
return new Response(JSON.stringify({ error: '不支持的操作' }), {
status: 400,
headers: { 'Content-Type': 'application/json' }
});
case 'backup':
return await handleBackup(context);
case 'restore':
return await handleRestore(request, env);
default:
return new Response(JSON.stringify({ error: '不支持的操作' }), {
status: 400,
headers: { 'Content-Type': 'application/json' }
});
}
} catch (error) {
console.error('备份操作错误:', error);
@@ -36,7 +36,7 @@ async function handleBackup(context) {
const backupData = {
timestamp: Date.now(),
version: '2.0.2',
version: '2.2.5',
data: {
fileCount: 0,
files: {},
@@ -45,7 +45,7 @@ async function handleBackup(context) {
};
// 首先从索引中读取所有文件信息
const indexResult = await readIndex(context, {
const indexResult = await readIndex(context, {
count: -1, // 获取所有文件
start: 0,
includeSubdirFiles: true // 包含子目录下的文件
@@ -56,7 +56,7 @@ async function handleBackup(context) {
for (const file of indexResult.files) {
const fileId = file.id;
const metadata = file.metadata;
// 对于TelegramNew渠道且IsChunked为true的文件需要从数据库读取其值
if (metadata.Channel === 'TelegramNew' && metadata.IsChunked === true) {
try {
@@ -95,7 +95,7 @@ async function handleBackup(context) {
}
const backupJson = JSON.stringify(backupData, null, 2);
return new Response(backupJson, {
status: 200,
headers: {
@@ -114,7 +114,7 @@ async function handleRestore(request, env) {
const db = getDatabase(env);
const contentType = request.headers.get('content-type');
if (!contentType || !contentType.includes('application/json')) {
return new Response(JSON.stringify({ error: '请上传JSON格式的备份文件' }), {
status: 400,
@@ -123,7 +123,7 @@ async function handleRestore(request, env) {
}
const backupData = await request.json();
// 验证备份文件格式
if (!backupData.data || !backupData.data.files || !backupData.data.settings) {
return new Response(JSON.stringify({ error: '备份文件格式无效' }), {
@@ -165,7 +165,7 @@ async function handleRestore(request, env) {
}
}
return new Response(JSON.stringify({
return new Response(JSON.stringify({
success: true,
message: '恢复完成',
stats: {

View File

@@ -1,4 +1,4 @@
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/logo.png"><link rel="apple-touch-icon" href="/logo.png"><link rel="mask-icon" href="/logo.png" color="#f4b400"><meta name="description" content="Sanyue ImgHub - A modern file hosting platform"><meta name="keywords" content="Sanyue, ImgHub, file hosting, image hosting, cloud storage"><meta name="author" content="SanyueQi"><title>Sanyue ImgHub</title><script defer="defer" src="/js/app.4e994b97.js"></script><link href="/css/app.dab02a4f.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but sanyue_imghub doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html><style>/* 下拉菜单样式 */
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/logo.png"><link rel="apple-touch-icon" href="/logo.png"><link rel="mask-icon" href="/logo.png" color="#f4b400"><meta name="description" content="Sanyue ImgHub - A modern file hosting platform"><meta name="keywords" content="Sanyue, ImgHub, file hosting, image hosting, cloud storage"><meta name="author" content="SanyueQi"><title>Sanyue ImgHub</title><script defer="defer" src="/js/app.7b4ce17b.js"></script><link href="/css/app.dab02a4f.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but sanyue_imghub doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html><style>/* 下拉菜单样式 */
.el-dropdown__popper.el-popper {
border-radius: 12px;
border: none;

Binary file not shown.

File diff suppressed because one or more lines are too long

BIN
js/459.2e371884.js.gz Normal file

Binary file not shown.

File diff suppressed because one or more lines are too long

BIN
js/459.2e371884.js.map.gz Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

BIN
js/app.7b4ce17b.js.gz Normal file

Binary file not shown.

File diff suppressed because one or more lines are too long