| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- const assert = require('node:assert/strict')
- const fs = require('node:fs')
- const path = require('node:path')
- const {
- DEFAULT_ASSET_BASE_URL,
- DEFAULT_PROFILE_IMAGE_BASE_URL,
- getAssetBaseUrl,
- getProfileImageUrl,
- htmlUrl,
- imageUrl
- } = require('../utils/assetUrl')
- assert.equal(DEFAULT_ASSET_BASE_URL, 'https://transcend.ringzle.com/web/assets')
- assert.equal(getAssetBaseUrl({}), DEFAULT_ASSET_BASE_URL)
- assert.equal(
- getAssetBaseUrl({ VUE_APP_ASSET_BASE_URL: 'https://test.example/assets/' }),
- 'https://test.example/assets'
- )
- assert.equal(
- imageUrl('fm_logo.png', { VUE_APP_ASSET_BASE_URL: 'https://test.example/assets/' }),
- 'https://test.example/assets/images/fm_logo.png'
- )
- assert.equal(
- getProfileImageUrl('2025/06/16/avatar.png'),
- 'https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/16/avatar.png'
- )
- assert.equal(
- getProfileImageUrl('2025/06/16/avatar.png', { VUE_APP_PROFILE_IMAGE_BASE_URL: 'https://test.example/profile/' }),
- 'https://test.example/profile/2025/06/16/avatar.png'
- )
- assert.equal(
- htmlUrl('PERILL常见问题与支持.html'),
- 'https://transcend.ringzle.com/web/assets/html/PERILL%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98%E4%B8%8E%E6%94%AF%E6%8C%81.html'
- )
- assert.equal(
- imageUrl('fm_logo.png'),
- 'https://transcend.ringzle.com/web/assets/images/fm_logo.png'
- )
- assert.equal(
- imageUrl('/fm_logo.png'),
- 'https://transcend.ringzle.com/web/assets/images/fm_logo.png'
- )
- assert.equal(
- imageUrl('中文图片.png'),
- 'https://transcend.ringzle.com/web/assets/images/%E4%B8%AD%E6%96%87%E5%9B%BE%E7%89%87.png'
- )
- const sourceRoots = ['components', 'pages', 'pagesHome', 'pagesMy', 'pagesPublish']
- const sourceFiles = sourceRoots.flatMap(root => {
- const files = []
- const visit = current => {
- for (const entry of fs.readdirSync(path.join(__dirname, '..', current), { withFileTypes: true })) {
- const relative = path.join(current, entry.name)
- if (entry.isDirectory() && !entry.name.includes('lime-echart')) visit(relative)
- else if (/\.(vue|js|scss|css)$/.test(entry.name)) files.push(relative)
- }
- }
- visit(root)
- return files
- })
- for (const file of sourceFiles) {
- const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8')
- assert.equal(source.includes('https://transcend.ringzle.com/web/assets/images/'), false, file)
- }
- console.log('asset URL rules: PASS')
|