From fb0041bb19165c6ff2e2836b47a6aada6e4828a0 Mon Sep 17 00:00:00 2001 From: jingrow Date: Tue, 23 Sep 2025 18:13:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0files=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E7=94=9F=E4=BA=A7=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E4=B8=8B=E6=96=B0=E5=A2=9E=E5=9B=BE=E7=89=87=E5=90=8E=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E9=87=8D=E5=90=AFjsite=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E6=89=8D=E8=83=BD=E6=98=BE=E7=A4=BA=E5=9B=BE=E7=89=87=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/files/[...path]/route.js | 68 ++++++++++ public/sitemap.xml | 233 +++++++++++++++++++++++++++-------- utils/data.js | 13 +- 3 files changed, 259 insertions(+), 55 deletions(-) create mode 100644 app/files/[...path]/route.js diff --git a/app/files/[...path]/route.js b/app/files/[...path]/route.js new file mode 100644 index 0000000..00d001c --- /dev/null +++ b/app/files/[...path]/route.js @@ -0,0 +1,68 @@ +import fs from 'fs'; +import path from 'path'; +import { NextResponse } from 'next/server'; + +const BACKEND_SERVER_URL = process.env.BACKEND_SERVER_URL || ''; +const PUBLIC_FILES_DIR = path.join(process.cwd(), 'public/files'); + +function getContentType(filePath) { + const ext = path.extname(filePath).toLowerCase(); + switch (ext) { + case '.jpg': + case '.jpeg': + return 'image/jpeg'; + case '.png': + return 'image/png'; + case '.gif': + return 'image/gif'; + case '.svg': + return 'image/svg+xml'; + case '.webp': + return 'image/webp'; + case '.mp4': + return 'video/mp4'; + case '.pdf': + return 'application/pdf'; + default: + return 'application/octet-stream'; + } +} + +export async function GET(req, { params }) { + try { + const parts = params.path || []; + const fileName = parts.join('/'); + if (!fileName) return new NextResponse('Not Found', { status: 404 }); + + const localPath = path.join(PUBLIC_FILES_DIR, fileName); + + if (fs.existsSync(localPath)) { + const data = fs.readFileSync(localPath); + return new NextResponse(data, { + status: 200, + headers: { 'Content-Type': getContentType(localPath) } + }); + } + + const remoteUrl = `${BACKEND_SERVER_URL}/files/${fileName}`; + const res = await fetch(remoteUrl); + if (!res.ok) { + return new NextResponse('Not Found', { status: 404 }); + } + const arrayBuffer = await res.arrayBuffer(); + const buffer = Buffer.from(arrayBuffer); + + // 确保目录存在并写入本地 + fs.mkdirSync(path.dirname(localPath), { recursive: true }); + fs.writeFileSync(localPath, buffer); + + return new NextResponse(buffer, { + status: 200, + headers: { 'Content-Type': getContentType(localPath) } + }); + } catch (e) { + return new NextResponse('Server Error', { status: 500 }); + } +} + + diff --git a/public/sitemap.xml b/public/sitemap.xml index 8550b27..402dcc9 100644 --- a/public/sitemap.xml +++ b/public/sitemap.xml @@ -7,7 +7,182 @@ 0.7 - http://192.168.2.200:3001/products/chic-crossbody-bag-for-trendy-women + http://192.168.2.200:3001/products + weekly + 0.7 + + + http://192.168.2.200:3001/products/womens-handbags/exquisite-original-fashion-womens-handbag-4 + weekly + 0.7 + + + http://192.168.2.200:3001/products/fashion-handbags/chic-leather-crossbody-bag-4 + weekly + 0.7 + + + http://192.168.2.200:3001/products/fashion-handbags/chic-leather-crossbody-bag-2 + weekly + 0.7 + + + http://192.168.2.200:3001/products/womens-handbags + weekly + 0.7 + + + http://192.168.2.200:3001/contact + weekly + 0.7 + + + http://192.168.2.200:3001/products/shoulder-bags/chic-leather-crossbody-bag + weekly + 0.7 + + + http://192.168.2.200:3001/products/fashion-handbags/chic-envelope-crossbody-bag + weekly + 0.7 + + + http://192.168.2.200:3001/products/shoulder-bags/exquisite-original-fashion-womens-handbag + weekly + 0.7 + + + http://192.168.2.200:3001/blog/the-latest-trends-in-original-fashionable-womens-handbags + weekly + 0.7 + + + http://192.168.2.200:3001/blog/stylish-pursuits-unraveling-the-charm-of-our-original-fashion-womens-handbags + weekly + 0.7 + + + http://192.168.2.200:3001/blog/explore-the-world-of-original-fashionable-womens-handbags + weekly + 0.7 + + + http://192.168.2.200:3001/products/fashion-handbags/chic-leather-crossbody-bag-3 + weekly + 0.7 + + + http://192.168.2.200:3001/products/tote-bags/elegant-leather-crossbody-bag-4 + weekly + 0.7 + + + http://192.168.2.200:3001/products/fashion-handbags/elegant-leather-crossbody-bag-1 + weekly + 0.7 + + + http://192.168.2.200:3001/products/shoulder-bags/chic-leather-crossbody-bag-1 + weekly + 0.7 + + + http://192.168.2.200:3001/products/crossbody-bags/elegant-leather-crossbody-bag-5 + weekly + 0.7 + + + http://192.168.2.200:3001/products/crossbody-bags/elegant-leather-crossbody-bag-2 + weekly + 0.7 + + + http://192.168.2.200:3001/blog/the-artistry-behind-our-original-fashionable-womens-handbags + weekly + 0.7 + + + http://192.168.2.200:3001/blog + weekly + 0.7 + + + http://192.168.2.200:3001/products/crossbody-bags/elegant-leather-crossbody-bag-3 + weekly + 0.7 + + + http://192.168.2.200:3001/products/fashion-handbags/exquisite-original-fashion-womens-handbag-1 + weekly + 0.7 + + + http://192.168.2.200:3001/products/fashion-handbags/chic-leather-crossbody-bag-5 + weekly + 0.7 + + + http://192.168.2.200:3001/products/crossbody-bags/elegant-pink-leather-shoulder-bag + weekly + 0.7 + + + http://192.168.2.200:3001/products/fashion-handbags/exquisite-original-fashion-womens-handbag-2 + weekly + 0.7 + + + http://192.168.2.200:3001/blog/the-allure-of-our-exclusive-original-fashion-womens-handbags + weekly + 0.7 + + + http://192.168.2.200:3001/about-us + weekly + 0.7 + + + http://192.168.2.200:3001/blog/the-enchanting-journey-of-our-original-fashionable-womens-handbags + weekly + 0.7 + + + http://192.168.2.200:3001/products/shoulder-bags/elegant-leather-crossbody-bag + weekly + 0.7 + + + http://192.168.2.200:3001/blog/discover-the-timeless-elegance-of-our-original-fashion-womens-handbags + weekly + 0.7 + + + http://192.168.2.200:3001/blog/chic-pursuits-our-original-fashion-womens-handbags-collection + weekly + 0.7 + + + http://192.168.2.200:3001/products/crossbody-bags/exquisite-original-fashion-womens-handbag-3 + weekly + 0.7 + + + http://192.168.2.200:3001/blog/elevate-your-style-with-our-exquisite-original-fashion-womens-handbags + weekly + 0.7 + + + http://192.168.2.200:3001/blog/the-secret-to-choosing-the-perfect-original-fashion-womens-handbag + weekly + 0.7 + + + http://192.168.2.200:3001/blog/accessorize-with-confidence-our-handpicked-original-fashion-womens-bags + weekly + 0.7 + + + http://192.168.2.200:3001/products/crossbody-bags weekly 0.7 @@ -17,47 +192,17 @@ 0.7 - http://192.168.2.200:3001/products/chic-leather-crossbody-bag-2 + http://192.168.2.200:3001/products/crossbody-bags/chic-leather-crossbody-bag-6 weekly 0.7 - http://192.168.2.200:3001/products/elegant-leather-crossbody-bag-2 + http://192.168.2.200:3001/products/fashion-handbags/elegant-ladys-tote-bag-1 weekly 0.7 - http://192.168.2.200:3001/products/elegant-ladys-tote-bag - weekly - 0.7 - - - http://192.168.2.200:3001/products/exquisite-womens-original-fashion-handbag - weekly - 0.7 - - - http://192.168.2.200:3001/products/chic-leather-crossbody-bag-4 - weekly - 0.7 - - - http://192.168.2.200:3001/products/fashion-handbags/elegant-pink-leather-handbag - weekly - 0.7 - - - http://192.168.2.200:3001/products/elegant-leather-crossbody-bag - weekly - 0.7 - - - http://192.168.2.200:3001/products/elegant-leather-tote-bag - weekly - 0.7 - - - http://192.168.2.200:3001/products/chic-pink-leather-crossbody-bag + http://192.168.2.200:3001/blog/unleash-your-style-with-our-trendy-original-fashion-womens-handbags weekly 0.7 @@ -67,37 +212,27 @@ 0.7 - http://192.168.2.200:3001/products/exquisite-ladys-handbag + http://192.168.2.200:3001/products/shoulder-bags/elegant-ladys-tote-bag weekly 0.7 - http://192.168.2.200:3001/products/exquisite-fashionable-womens-handbag-1 + http://192.168.2.200:3001/blog/unveiling-the-allure-of-handcrafted-original-fashion-womens-bags weekly 0.7 - http://192.168.2.200:3001/products/chic-leather-crossbody-bag-5 + http://192.168.2.200:3001/products/shoulder-bags weekly 0.7 - http://192.168.2.200:3001/products/elegant-leather-crossbody-bag-1 + http://192.168.2.200:3001/products/tote-bags/exquisite-fashionable-womens-handbag-1 weekly 0.7 - http://192.168.2.200:3001/products - weekly - 0.7 - - - http://192.168.2.200:3001/products/chic-leather-crossbody-bag-1 - weekly - 0.7 - - - http://192.168.2.200:3001/products/elegant-leather-crossbody-bag-4 + http://192.168.2.200:3001/products/tote-bags weekly 0.7 diff --git a/utils/data.js b/utils/data.js index b2eccf1..141536a 100644 --- a/utils/data.js +++ b/utils/data.js @@ -136,8 +136,8 @@ export async function processDataItem(item, downloadFiles) { } downloadTasks.push(...htmlTasks); - // 并发执行所有下载任务 - await Promise.all(downloadTasks); + // 并发执行所有下载任务并获取结果 + const results = await Promise.all(downloadTasks); // 更新主表字段 if (downloadMap.has('image')) item.image = downloadMap.get('image'); @@ -148,7 +148,7 @@ export async function processDataItem(item, downloadFiles) { // 更新attachments字段 if (item.attachments && Array.isArray(item.attachments)) { - const attachmentResults = downloadTasks.filter(task => + const attachmentResults = results.filter(task => task && typeof task === 'object' && 'index' in task ); for (const result of attachmentResults) { @@ -160,7 +160,7 @@ export async function processDataItem(item, downloadFiles) { // 更新items字段 if (item.items && Array.isArray(item.items)) { - const itemResults = downloadTasks.filter(task => + const itemResults = results.filter(task => task && typeof task === 'object' && 'itemIndex' in task ); for (const result of itemResults) { @@ -173,7 +173,7 @@ export async function processDataItem(item, downloadFiles) { } // 更新HTML内容 - const htmlResults = downloadTasks.filter(task => + const htmlResults = results.filter(task => task && typeof task === 'object' && 'key' in task ); for (const result of htmlResults) { @@ -224,8 +224,9 @@ export async function getPageData({ data = await processDataItem(data, downloadFiles); } + // 返回处理后的数据,确保前端能拿到本地化后的图片地址 return { - data: message.data, + data, total: message.total, page_info: message.page_info, };