fix: support svg folder icons across roots
@@ -14,7 +14,7 @@ const FOLDER_ICONS_PATH = path.join(THUMBS_DIR, '.folder-icons.json');
14
14
const LOOP_DELAY_MS = 5000;
15
15
16
16
const IMAGE_EXTS = new Set([
17
'jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'tif', 'tiff', 'avif',
17
'jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'tif', 'tiff', 'avif', 'svg', 'ico',
18
18
]);
19
19
20
20
let loopTimer = null;
@@ -14,7 +14,7 @@ const FOLDER_ICONS_PATH = path.join(THUMBS_DIR, '.folder-icons.json');14
const LOOP_DELAY_MS = 5000;14
const LOOP_DELAY_MS = 5000;15
15
16
const IMAGE_EXTS = new Set([16
const IMAGE_EXTS = new Set([17
'jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'tif', 'tiff', 'avif',17
'jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'tif', 'tiff', 'avif', 'svg', 'ico',18
]);18
]);19
19
20
let loopTimer = null;20
let loopTimer = null;@@ -24,6 +24,17 @@ async function writeTinyPng (target)
24
24
}).png().toFile(target);
25
25
}
26
26
27
function writeTinySvg (target)
28
{
29
const svg = `<?xml version="1.0" encoding="UTF-8"?>
30
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="120" viewBox="0 0 200 120">
31
<rect x="0" y="0" width="200" height="120" fill="#2a7fff"/>
32
<circle cx="60" cy="60" r="32" fill="#ffd166"/>
33
<rect x="105" y="30" width="70" height="60" rx="10" fill="#0f172a"/>
34
</svg>`;
35
fs.writeFileSync(target, svg, 'utf8');
36
}
37
27
38
describe('thumbnail cache worker', () =>
28
39
{
29
40
let tempDir;
@@ -117,4 +128,38 @@ describe('thumbnail cache worker', () =>
117
128
const stored = JSON.parse(fs.readFileSync(iconsPath, 'utf8'));
118
129
expect(stored[path.resolve(sourceRoot)]).toBe(path.join(sourceRoot, 'cover.jpg'));
119
130
});
131
132
test('creates cached thumbnail for svg files', async () =>
133
{
134
const mod = loadModule();
135
const imagePath = path.join(sourceRoot, 'assets', 'logo.svg');
136
fs.mkdirSync(path.dirname(imagePath), { recursive: true });
137
writeTinySvg(imagePath);
138
139
await mod.syncThumbnailCacheOnce();
140
141
const thumbPath = mod.getThumbPathForSourceFile(imagePath);
142
expect(fs.existsSync(thumbPath)).toBe(true);
143
144
const info = await mod.getCachedThumbnailInfo(imagePath);
145
expect(info).toBeTruthy();
146
expect(info.thumbPath).toBe(thumbPath);
147
});
148
149
test('auto-detects first cached image inside /public-style root', async () =>
150
{
151
const mod = loadModule();
152
const publicRoot = path.join(tempDir, 'public-root');
153
fs.mkdirSync(publicRoot, { recursive: true });
154
mockPaths = [publicRoot];
155
156
const nested = path.join(publicRoot, 'icons', 'a.svg');
157
fs.mkdirSync(path.dirname(nested), { recursive: true });
158
writeTinySvg(nested);
159
160
await mod.syncThumbnailCacheOnce();
161
162
const detected = await mod.getFolderIconSourceFile(publicRoot);
163
expect(detected).toBe(nested);
164
});
120
165
});
@@ -24,6 +24,17 @@ async function writeTinyPng (target)24
}).png().toFile(target);24
}).png().toFile(target);25
}25
}26
26
27
function writeTinySvg (target)28
{29
const svg = `<?xml version="1.0" encoding="UTF-8"?>30
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="120" viewBox="0 0 200 120">31
<rect x="0" y="0" width="200" height="120" fill="#2a7fff"/>32
<circle cx="60" cy="60" r="32" fill="#ffd166"/>33
<rect x="105" y="30" width="70" height="60" rx="10" fill="#0f172a"/>34
</svg>`;35
fs.writeFileSync(target, svg, 'utf8');36
}37
27
describe('thumbnail cache worker', () =>38
describe('thumbnail cache worker', () =>28
{39
{29
let tempDir;40
let tempDir;@@ -117,4 +128,38 @@ describe('thumbnail cache worker', () =>117
const stored = JSON.parse(fs.readFileSync(iconsPath, 'utf8'));128
const stored = JSON.parse(fs.readFileSync(iconsPath, 'utf8'));118
expect(stored[path.resolve(sourceRoot)]).toBe(path.join(sourceRoot, 'cover.jpg'));129
expect(stored[path.resolve(sourceRoot)]).toBe(path.join(sourceRoot, 'cover.jpg'));119
});130
});131
132
test('creates cached thumbnail for svg files', async () =>133
{134
const mod = loadModule();135
const imagePath = path.join(sourceRoot, 'assets', 'logo.svg');136
fs.mkdirSync(path.dirname(imagePath), { recursive: true });137
writeTinySvg(imagePath);138
139
await mod.syncThumbnailCacheOnce();140
141
const thumbPath = mod.getThumbPathForSourceFile(imagePath);142
expect(fs.existsSync(thumbPath)).toBe(true);143
144
const info = await mod.getCachedThumbnailInfo(imagePath);145
expect(info).toBeTruthy();146
expect(info.thumbPath).toBe(thumbPath);147
});148
149
test('auto-detects first cached image inside /public-style root', async () =>150
{151
const mod = loadModule();152
const publicRoot = path.join(tempDir, 'public-root');153
fs.mkdirSync(publicRoot, { recursive: true });154
mockPaths = [publicRoot];155
156
const nested = path.join(publicRoot, 'icons', 'a.svg');157
fs.mkdirSync(path.dirname(nested), { recursive: true });158
writeTinySvg(nested);159
160
await mod.syncThumbnailCacheOnce();161
162
const detected = await mod.getFolderIconSourceFile(publicRoot);163
expect(detected).toBe(nested);164
});120
});165
});