feat: 完成现有小程序接口的全部迁移至新后端

This commit is contained in:
R524809
2026-10-19 13:17:51 +08:00
parent 8827110f2f
commit d30cf25890
148 changed files with 13287 additions and 34 deletions
@@ -0,0 +1,79 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';
import {
publicObjectUrl,
publicResourceUrl,
} from '../src/content/public-resource-url';
import { previewUrl, type PreviewAssetRow } from '../src/content/preview-url';
const config = {
qiniuPublicDomain: 'https://cdn.joeyone.cn',
qiniuKeyPrefix: 'doodle-assets/',
};
test('公开资源:字体相对路径与完整对象 key 生成相同地址,中文按段编码', () => {
const path = 'assets/fonts/ToneOZ-Pinyin-Regular.ttf';
const expected =
'https://cdn.joeyone.cn/doodle-assets/assets/fonts/ToneOZ-Pinyin-Regular.ttf';
assert.equal(publicResourceUrl(config, path), expected);
assert.equal(
publicObjectUrl(config.qiniuPublicDomain, `doodle-assets/${path}`),
expected,
);
assert.equal(
publicResourceUrl({ ...config, qiniuKeyPrefix: '' }, path),
`${config.qiniuPublicDomain}/${path}`,
);
assert.equal(
publicResourceUrl(config, 'user-avatars/中文 图.png'),
`${config.qiniuPublicDomain}/doodle-assets/user-avatars/${encodeURIComponent('中文 图.png')}`,
);
for (const path of [
'',
'/absolute',
'../escape',
'a/../b',
'a//b',
'a\\b',
'a\n',
'a/',
]) {
assert.equal(publicResourceUrl(config, path), null);
assert.equal(publicObjectUrl(config.qiniuPublicDomain, path), null);
}
assert.equal(
publicResourceUrl({ ...config, qiniuPublicDomain: null }, path),
null,
);
});
test('预览图:完整 key 不重复加前缀,pending 或 private 资产仍留空', () => {
const row: PreviewAssetRow = {
assetStatus: 'ready',
assetVisibility: 'public',
assetPurpose: 'preview',
assetOwnerId: null,
assetProvider: 'qiniu',
assetKey: 'doodle-assets/assets/previews/math/example.jpg',
assetExternalUrl: null,
assetMimeType: 'image/jpeg',
};
assert.equal(
previewUrl(row, config.qiniuPublicDomain),
`${config.qiniuPublicDomain}/${row.assetKey}`,
);
assert.equal(
previewUrl(
{ ...row, assetStatus: 'pending' },
config.qiniuPublicDomain,
),
null,
);
assert.equal(
previewUrl(
{ ...row, assetVisibility: 'private' },
config.qiniuPublicDomain,
),
null,
);
});