fix(common-tools): 资料下载改挂站点 /static/ 静态位
/materials/ 是不在发布白名单里的新目录,deploy_app_web.py 只上传 index.html+assets+/static/ 清单 ⇒ 上线即 404。改走既有 /static/(nginx 已配), 发布清单在 ops 仓 deploy_app_web.py 同步登记 4 个文件。
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
* 定价利润换算页 · 常用链接与资料下载
|
||||
*
|
||||
* 链接清单源自桌面版 shufu_calc_app.py 的 PAGE_LINKS / 资料页(2026-10-23 实测可达),
|
||||
* 下载文件随前端 public/materials/ 一并部署(源自「数富资料下载_独立版_v1.0.0」;
|
||||
* 目录名避开 .gitignore 的 downloads/ 规则)。
|
||||
* 下载文件源自「数富资料下载_独立版_v1.0.0」,源文件在 public/materials/,
|
||||
* 发布时由 scripts/deploy_app_web.py 的 EXPECTED_STATIC 白名单上传到站点 /static/。
|
||||
*/
|
||||
|
||||
export type CommonLink = {
|
||||
@@ -37,5 +37,7 @@ export const PRICING_DOWNLOADS: ReadonlyArray<DownloadItem> = [
|
||||
]
|
||||
|
||||
export function downloadHref(file: string): string {
|
||||
return `/materials/${encodeURI(file)}`
|
||||
// 走既有 /static/ 静态位(nginx 已配,deploy_app_web.py 的 EXPECTED_STATIC 白名单同步登记);
|
||||
// /materials/ 这类新目录不在发布清单里,上线即 404。
|
||||
return `/static/${encodeURI(file)}`
|
||||
}
|
||||
|
||||
@@ -90,14 +90,14 @@ describe('定价利润换算页', () => {
|
||||
expect(page.findAll('.result-value')[3]?.text()).toBe('3.7500')
|
||||
})
|
||||
|
||||
it('资料下载四个锚点落在 /materials/ 且 href 无裸空格;常用链接均为 http(s)', async () => {
|
||||
it('资料下载四个锚点落在 /static/ 且 href 无裸空格;常用链接均为 http(s)', async () => {
|
||||
const page = mountPage(PricingCalcPage)
|
||||
const downloadHrefs = page
|
||||
.findAll('a[download]')
|
||||
.map((a) => a.attributes('href') ?? '')
|
||||
expect(downloadHrefs).toHaveLength(4)
|
||||
for (const href of downloadHrefs) {
|
||||
expect(href.startsWith('/materials/')).toBe(true)
|
||||
expect(href.startsWith('/static/')).toBe(true)
|
||||
expect(href.includes(' ')).toBe(false)
|
||||
}
|
||||
const linkHrefs = page
|
||||
|
||||
@@ -13,11 +13,11 @@ import {
|
||||
const here = dirname(fileURLToPath(import.meta.url))
|
||||
const ROOT = resolve(here, '..')
|
||||
|
||||
test('downloadHref:落在 /materials/ 下,空格与非 ASCII 都按 encodeURI 转义', () => {
|
||||
assert.equal(downloadHref('百分30利润表格.xlsx'), `/materials/${encodeURI('百分30利润表格.xlsx')}`)
|
||||
test('downloadHref:落在 /static/ 下,空格与非 ASCII 都按 encodeURI 转义', () => {
|
||||
assert.equal(downloadHref('百分30利润表格.xlsx'), `/static/${encodeURI('百分30利润表格.xlsx')}`)
|
||||
assert.equal(
|
||||
downloadHref('设置最低价ASIN 批量文档格式.xlsx'),
|
||||
'/materials/%E8%AE%BE%E7%BD%AE%E6%9C%80%E4%BD%8E%E4%BB%B7ASIN%20%E6%89%B9%E9%87%8F%E6%96%87%E6%A1%A3%E6%A0%BC%E5%BC%8F.xlsx',
|
||||
'/static/%E8%AE%BE%E7%BD%AE%E6%9C%80%E4%BD%8E%E4%BB%B7ASIN%20%E6%89%B9%E9%87%8F%E6%96%87%E6%A1%A3%E6%A0%BC%E5%BC%8F.xlsx',
|
||||
)
|
||||
// 不允许出现裸空格(浏览器会容忍,但 href 里必须是编码后的形态)
|
||||
for (const item of PRICING_DOWNLOADS) {
|
||||
|
||||
Reference in New Issue
Block a user