66ca0b3bec
支持全部页面分页/多选/删除/分享,删除时可选移除广场帖并清理工作区附件;修复并发同步重复创建页面,并补齐预览下载链接重写与 iframe 下载权限。 Co-authored-by: Cursor <cursoragent@cursor.com>
62 lines
2.4 KiB
JavaScript
62 lines
2.4 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { downloadLinkInternals } from './mindspace-html-download-links.mjs';
|
|
|
|
const {
|
|
isRelativeDownloadReference,
|
|
resolveWorkspaceRelativeFilePath,
|
|
buildWorkspaceDownloadLinkIndex,
|
|
resolveDownloadTargetUrl,
|
|
rewriteRelativeDownloadLinks,
|
|
} = downloadLinkInternals;
|
|
|
|
test('isRelativeDownloadReference accepts sibling docx links only', () => {
|
|
assert.equal(isRelativeDownloadReference('半导体行业趋势分析报告.docx'), true);
|
|
assert.equal(isRelativeDownloadReference('public/report.docx'), true);
|
|
assert.equal(isRelativeDownloadReference('/MindSpace/u/public/a.docx'), false);
|
|
assert.equal(isRelativeDownloadReference('https://example.com/a.pdf'), false);
|
|
assert.equal(isRelativeDownloadReference('#summary'), false);
|
|
});
|
|
|
|
test('resolveWorkspaceRelativeFilePath resolves from public html directory', () => {
|
|
assert.equal(
|
|
resolveWorkspaceRelativeFilePath('public/index.html', '半导体行业趋势分析报告.docx'),
|
|
'public/半导体行业趋势分析报告.docx',
|
|
);
|
|
assert.equal(
|
|
resolveWorkspaceRelativeFilePath('public/report.html', 'assets/data.csv'),
|
|
'public/assets/data.csv',
|
|
);
|
|
});
|
|
|
|
test('resolveDownloadTargetUrl prefers asset download API in preview mode', () => {
|
|
const linkIndex = buildWorkspaceDownloadLinkIndex([
|
|
{ id: 'asset-1', original_filename: 'public/半导体行业趋势分析报告.docx' },
|
|
]);
|
|
const url = resolveDownloadTargetUrl({
|
|
relativeRef: '半导体行业趋势分析报告.docx',
|
|
htmlRelativePath: 'public/index.html',
|
|
linkIndex,
|
|
preferAssetDownload: true,
|
|
});
|
|
assert.equal(url, '/api/mindspace/v1/assets/asset-1/download');
|
|
});
|
|
|
|
test('rewriteRelativeDownloadLinks rewrites href and src download attributes', () => {
|
|
const html = [
|
|
'<a href="半导体行业趋势分析报告.docx" download>下载</a>',
|
|
'<a href="#summary">摘要</a>',
|
|
].join('');
|
|
const linkIndex = buildWorkspaceDownloadLinkIndex([
|
|
{ id: 'asset-1', original_filename: '半导体行业趋势分析报告.docx' },
|
|
]);
|
|
const { html: rewritten, count } = rewriteRelativeDownloadLinks(html, {
|
|
htmlRelativePath: 'public/index.html',
|
|
linkIndex,
|
|
preferAssetDownload: true,
|
|
});
|
|
assert.equal(count, 1);
|
|
assert.match(rewritten, /href="\/api\/mindspace\/v1\/assets\/asset-1\/download"/);
|
|
assert.match(rewritten, /href="#summary"/);
|
|
});
|