Initial commit: Memind H5 portal with MindSpace, Plaza, and agent jobs.
Track application source and tests; exclude local env, user workspaces, and runtime data via .gitignore. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs/promises';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
import { canPreviewAsset, renderAssetPreviewHtml } from './mindspace-asset-preview.mjs';
|
||||
|
||||
test('canPreviewAsset covers common workspace file types', () => {
|
||||
assert.equal(canPreviewAsset('text/html'), true);
|
||||
assert.equal(canPreviewAsset('application/pdf'), true);
|
||||
assert.equal(
|
||||
canPreviewAsset('application/vnd.openxmlformats-officedocument.wordprocessingml.document'),
|
||||
true,
|
||||
);
|
||||
assert.equal(canPreviewAsset('application/vnd.ms-excel'), false);
|
||||
});
|
||||
|
||||
test('renderAssetPreviewHtml renders csv as table', () => {
|
||||
const html = renderAssetPreviewHtml({
|
||||
asset: {
|
||||
displayName: '导出',
|
||||
filename: 'export.csv',
|
||||
mimeType: 'text/csv',
|
||||
},
|
||||
buffer: Buffer.from('name,value\nfoo,1\nbar,2\n'),
|
||||
downloadUrl: '/api/mindspace/v1/assets/a/download?inline=1',
|
||||
});
|
||||
assert.match(html, /<table>/);
|
||||
assert.match(html, /foo/);
|
||||
assert.match(html, /下载原文件/);
|
||||
});
|
||||
|
||||
test('renderAssetPreviewHtml extracts docx text', async () => {
|
||||
const docPath = path.join(
|
||||
process.cwd(),
|
||||
'MindSpace/john/oa/端午感怀.docx',
|
||||
);
|
||||
let buffer;
|
||||
try {
|
||||
buffer = await fs.readFile(docPath);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
const html = renderAssetPreviewHtml({
|
||||
asset: {
|
||||
displayName: '端午感怀',
|
||||
filename: '端午感怀.docx',
|
||||
mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
},
|
||||
buffer,
|
||||
downloadUrl: '/api/mindspace/v1/assets/a/download?inline=1',
|
||||
});
|
||||
assert.match(html, /端午/);
|
||||
assert.match(html, /docx-preview/);
|
||||
});
|
||||
Reference in New Issue
Block a user