feat(images): default frontend assets to image service
This commit is contained in:
@@ -9,13 +9,13 @@ import {
|
||||
} from '../src/utils/generalIcon.ts';
|
||||
|
||||
void describe('generalIcon', () => {
|
||||
void it('routes user icons through the gateway and encodes the complete filename', () => {
|
||||
void it('preserves server-issued user icon path segments while encoding traversal segments', () => {
|
||||
assert.equal(
|
||||
resolveGeneralIconUrl(
|
||||
{ picture: '계정 icon/../1.jpg', imageServer: 1 },
|
||||
{ userIconBaseUrl: '/gateway/api/user-icons/' }
|
||||
),
|
||||
'/gateway/api/user-icons/%EA%B3%84%EC%A0%95%20icon%2F..%2F1.jpg'
|
||||
'/gateway/api/user-icons/%EA%B3%84%EC%A0%95%20icon/%2E%2E/1.jpg'
|
||||
);
|
||||
});
|
||||
|
||||
@@ -30,31 +30,34 @@ void describe('generalIcon', () => {
|
||||
);
|
||||
assert.equal(
|
||||
resolveGeneralIconUrl({ picture: '장수/관우 1.png', imageServer: 0 }),
|
||||
'/image/icons/%EC%9E%A5%EC%88%98/%EA%B4%80%EC%9A%B0%201.png'
|
||||
'https://sam-image.hided.net/icons/%EC%9E%A5%EC%88%98/%EA%B4%80%EC%9A%B0%201.png'
|
||||
);
|
||||
assert.equal(
|
||||
resolveGeneralIconUrl({ picture: '../secret.png', imageServer: 0 }),
|
||||
'/image/icons/%2E%2E/secret.png'
|
||||
'https://sam-image.hided.net/icons/%2E%2E/secret.png'
|
||||
);
|
||||
});
|
||||
|
||||
void it('uses a deterministic default and safe layered fallback for CSS backgrounds', () => {
|
||||
assert.equal(resolveGeneralIconUrl({ picture: null, imageServer: 0 }), '/image/icons/default.jpg');
|
||||
assert.equal(
|
||||
resolveGeneralIconUrl({ picture: null, imageServer: 0 }),
|
||||
'https://sam-image.hided.net/icons/default.jpg'
|
||||
);
|
||||
assert.equal(
|
||||
resolveGeneralIconBackgroundImage(
|
||||
{ picture: 'custom.jpg', imageServer: 1 },
|
||||
{ userIconBaseUrl: '/gateway/api/user-icons' }
|
||||
),
|
||||
'url("/gateway/api/user-icons/custom.jpg"), url("/image/icons/default.jpg")'
|
||||
'url("/gateway/api/user-icons/custom.jpg"), url("https://sam-image.hided.net/icons/default.jpg")'
|
||||
);
|
||||
});
|
||||
|
||||
void it('translates legacy message d_pic references without changing absolute or external icons', () => {
|
||||
assert.equal(
|
||||
resolveMessageGeneralIconUrl('d_pic/user name.jpg', '/gateway/api/user-icons/'),
|
||||
'/gateway/api/user-icons/user%20name.jpg'
|
||||
resolveMessageGeneralIconUrl('d_pic/users/core2026/user name.jpg', '/gateway/api/user-icons/'),
|
||||
'/gateway/api/user-icons/users/core2026/user%20name.jpg'
|
||||
);
|
||||
assert.equal(resolveMessageGeneralIconUrl('/image/icons/22.jpg'), '/image/icons/22.jpg');
|
||||
assert.equal(resolveMessageGeneralIconUrl('/image/icons/22.jpg'), 'https://sam-image.hided.net/icons/22.jpg');
|
||||
assert.equal(resolveMessageGeneralIconUrl('https://cdn.example/icon.jpg'), 'https://cdn.example/icon.jpg');
|
||||
assert.equal(resolveMessageGeneralIconUrl(''), DEFAULT_GENERAL_ICON_URL);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, it } from 'node:test';
|
||||
|
||||
import {
|
||||
configuredGameAssetUrl,
|
||||
configuredImagePublicUrl,
|
||||
configuredSharedIconPublicUrl,
|
||||
configuredUserIconPublicUrl,
|
||||
externalizeLegacyImageUrl,
|
||||
} from '../src/utils/imageAssets.ts';
|
||||
|
||||
void describe('imageAssets', () => {
|
||||
void it('uses the dedicated image host when no frontend override is provided', () => {
|
||||
assert.equal(configuredImagePublicUrl(), 'https://sam-image.hided.net');
|
||||
assert.equal(configuredGameAssetUrl(), 'https://sam-image.hided.net/game');
|
||||
assert.equal(configuredSharedIconPublicUrl(), 'https://sam-image.hided.net/icons');
|
||||
assert.equal(configuredUserIconPublicUrl(), 'https://sam-image.hided.net/icons');
|
||||
});
|
||||
|
||||
void it('maps legacy local image paths to the dedicated image host', () => {
|
||||
assert.equal(
|
||||
externalizeLegacyImageUrl('/image/icons/default.jpg'),
|
||||
'https://sam-image.hided.net/icons/default.jpg'
|
||||
);
|
||||
assert.equal(
|
||||
externalizeLegacyImageUrl('/image/general/장수/유비.png'),
|
||||
'https://sam-image.hided.net/icons/장수/유비.png'
|
||||
);
|
||||
assert.equal(externalizeLegacyImageUrl('/gateway/logo.png'), '/gateway/logo.png');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user