feat: 新增135编辑器转换子功能
- 新增 /editor135 子页面:上传幼儿园食谱docx → 解析并填充135模板 → 预览/源代码/解析结果三视图 - 新增 /api/editor135/render 解析接口(jsdom 解析填充,逐条回读校验 mismatch) - 新增 /api/editor135/img 微信CDN图片代理(解决预览防盗链,仅允许 *.qpic.cn) - 缺失星期自动删除:docx 缺某天(含周末/间隔天)时整段移除该天内容,尾部三审三校/温馨提示保留 - 逐节点精确区间删除算法:处理相邻天共用容器、嵌套结构,不误删保留天 - 新增依赖 jsdom + @types/jsdom;附 6 场景回归测试脚本 scripts/test-remove-days.ts - 首页 header 增加「135编辑器转换」导航入口
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
/**
|
||||
* 微信 CDN 图片代理(仅用于本地预览)。
|
||||
* mmbiz.qpic.cn 有防盗链: 带非微信域名 Referer 会返回占位图。
|
||||
* 服务端 fetch 默认不带 Referer, 可拿到真图。仅允许代理微信图片域名。
|
||||
*/
|
||||
const ALLOWED_HOST_RE = /\.qpic\.cn$/;
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const u = req.nextUrl.searchParams.get("u");
|
||||
if (!u) return new NextResponse("missing u", { status: 400 });
|
||||
let target: URL;
|
||||
try {
|
||||
target = new URL(u);
|
||||
} catch {
|
||||
return new NextResponse("bad url", { status: 400 });
|
||||
}
|
||||
if (target.protocol !== "https:" || !ALLOWED_HOST_RE.test(target.hostname)) {
|
||||
return new NextResponse("host not allowed", { status: 403 });
|
||||
}
|
||||
try {
|
||||
const upstream = await fetch(target.toString(), {
|
||||
headers: { "User-Agent": "Mozilla/5.0", Accept: "image/*" },
|
||||
cache: "no-store",
|
||||
});
|
||||
if (!upstream.ok || !upstream.body) {
|
||||
return new NextResponse("upstream error", { status: 502 });
|
||||
}
|
||||
return new NextResponse(upstream.body, {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": upstream.headers.get("content-type") ?? "image/jpeg",
|
||||
"Cache-Control": "public, max-age=86400",
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
return new NextResponse("fetch failed", { status: 502 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user