Update public-api.js via upload script - 2026-11-09 20:47:26
This commit is contained in:
parent
2fb83e52a9
commit
564a5390f0
|
|
@ -629,8 +629,20 @@ function toPublic(p, templates = [], packSpecs = [], slugMap = null) {
|
||||||
// HTML 模板(系列参数表等):显示在详情图下方
|
// HTML 模板(系列参数表等):显示在详情图下方
|
||||||
const tplHtml = templatesOf(p, templates).flatMap((t) => tplHtmlListFor(t, p).map((h) => ({ id: h.id === 'h_main' ? t.id : `${t.id}~${h.id}`, html: { en: h.html } })));
|
const tplHtml = templatesOf(p, templates).flatMap((t) => tplHtmlListFor(t, p).map((h) => ({ id: h.id === 'h_main' ? t.id : `${t.id}~${h.id}`, html: { en: h.html } })));
|
||||||
if (tplHtml.length) out.templateHtml = tplHtml;
|
if (tplHtml.length) out.templateHtml = tplHtml;
|
||||||
|
// 多语言原版彩页(产品档案里手动上传的 HTML / PDF):网站产品页按页面语言显示,中文版不对外
|
||||||
|
const br = {};
|
||||||
|
for (const lang of BROCHURE_PUBLIC_LANGS) {
|
||||||
|
const b = brochureOf(p, lang);
|
||||||
|
if (b) br[lang] = `${base}/api/public/brochure/${slug}/${lang}/${encodeURIComponent(b.fileName)}`;
|
||||||
|
}
|
||||||
|
if (Object.keys(br).length) out.brochures = br;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
const BROCHURE_PUBLIC_LANGS = ['en', 'es', 'ru', 'fr', 'ar'];
|
||||||
|
const brochureOf = (p, lang) => {
|
||||||
|
const b = p && p.brochures && p.brochures[lang];
|
||||||
|
return b && b.fileName && /\.(html?|pdf)$/i.test(b.fileName) ? b : null;
|
||||||
|
};
|
||||||
|
|
||||||
function checkKey(req, res, next) {
|
function checkKey(req, res, next) {
|
||||||
const want = conf('SITE_BUILD_KEY');
|
const want = conf('SITE_BUILD_KEY');
|
||||||
|
|
@ -701,6 +713,14 @@ module.exports = function mountPublicApi(app, { dataFile, uploadsDir, requireAut
|
||||||
translateProducts(ai, [toPublic(p, readTemplates(dataFile), readKey(dataFile, PACK_KEY), uniqueSlugs(published()))]).then(([x]) => res.json(x), (e) => res.status(500).json({ error: e.message }));
|
translateProducts(ai, [toPublic(p, readTemplates(dataFile), readKey(dataFile, PACK_KEY), uniqueSlugs(published()))]).then(([x]) => res.json(x), (e) => res.status(500).json({ error: e.message }));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 多语言彩页:只允许读取已发布产品在 brochures 里登记的文件
|
||||||
|
app.get('/api/public/brochure/:slug/:lang/:file', checkKey, (req, res) => {
|
||||||
|
const p = findBySlug(req.params.slug);
|
||||||
|
const b = p && BROCHURE_PUBLIC_LANGS.includes(req.params.lang) && brochureOf(p, req.params.lang);
|
||||||
|
if (!b || b.fileName !== path.basename(req.params.file)) return res.status(404).end();
|
||||||
|
res.sendFile(path.resolve(uploadsDir, path.basename(String(p.id)), b.fileName), (err) => { if (err) res.status(404).end(); });
|
||||||
|
});
|
||||||
|
|
||||||
// 产品图片:只允许读取"已发布产品自己的图片",防止借这个接口读到别的文件
|
// 产品图片:只允许读取"已发布产品自己的图片",防止借这个接口读到别的文件
|
||||||
app.get('/api/public/media/:slug/:file', checkKey, (req, res) => {
|
app.get('/api/public/media/:slug/:file', checkKey, (req, res) => {
|
||||||
const p = findBySlug(req.params.slug);
|
const p = findBySlug(req.params.slug);
|
||||||
|
|
@ -816,7 +836,7 @@ module.exports = function mountPublicApi(app, { dataFile, uploadsDir, requireAut
|
||||||
// 网站内容指纹:只看会出现在网站上的东西(已发布产品的对外字段和图片、箱规、网站图片、近期动态)。
|
// 网站内容指纹:只看会出现在网站上的东西(已发布产品的对外字段和图片、箱规、网站图片、近期动态)。
|
||||||
// 改了进价、备注这类只在后台用的字段,指纹不变,不会白白重新构建网站。
|
// 改了进价、备注这类只在后台用的字段,指纹不变,不会白白重新构建网站。
|
||||||
const FP_KEY = '__siteFingerprint';
|
const FP_KEY = '__siteFingerprint';
|
||||||
const PUB_SRC = [...new Set([...Object.values(FIELDS), 'name', 'id', PUBLISH_FLAG, IMAGES_FIELD, DETAIL_FIELD, TEMPLATE_IDS_FIELD, 'productImageFileName', 'webPackId', 'webPack'])];
|
const PUB_SRC = [...new Set([...Object.values(FIELDS), 'name', 'id', PUBLISH_FLAG, IMAGES_FIELD, DETAIL_FIELD, TEMPLATE_IDS_FIELD, 'productImageFileName', 'webPackId', 'webPack', 'brochures'])]; // brochures:多语言彩页,换了也要更新网站
|
||||||
function siteFingerprint(data) {
|
function siteFingerprint(data) {
|
||||||
const prods = listOf(data, PRODUCTS_KEY).filter((p) => p && p[PUBLISH_FLAG]).map((p) => PUB_SRC.map((k) => p[k]));
|
const prods = listOf(data, PRODUCTS_KEY).filter((p) => p && p[PUBLISH_FLAG]).map((p) => PUB_SRC.map((k) => p[k]));
|
||||||
const raw = (k) => { const v = data[k]; return v && v.value !== undefined ? v.value : v; };
|
const raw = (k) => { const v = data[k]; return v && v.value !== undefined ? v.value : v; };
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue