image models: downloads honour HF_ENDPOINT like setup and the MTP fetch (#4369)

This commit is contained in:
Nyarlathoteppppp authored and Niko1221 committed 2026-11-16 16:12:21 +01:00
1 parent a1047b7fdf
commit a421f7dee6
2 files changed
+16 -1

No files matched your search

+1 -1
View File
@@ -42,7 +42,7 @@ export function createImageModels({ dataDir, modelsDir, real = false, changed =
variants: catalog.variants.map(v => ({ ...v, downloadGb: v.bytes / 1e9,
state: runtime.get(v.id)?.state ?? (installed(v) ? 'installed' : 'available'),
progress: runtime.get(v.id)?.progress, error: runtime.get(v.id)?.error,
downloadUrl: `https://huggingface.co/${catalog.repo}/resolve/${catalog.revision}/${v.file}` })),
downloadUrl: `${(process.env.HF_ENDPOINT || '').trim().replace(/\/+$/, '') || 'https://huggingface.co'}/${catalog.repo}/resolve/${catalog.revision}/${v.file}` })),
};
}
const emit = () => changed(library());
+15
View File
@@ -62,6 +62,21 @@ test('real downloads verify exact bytes, GGUF header and hash at a pinned URL',
assert.equal(restarted.library().variants[0].state, 'installed');
assert.equal(restarted.library().applied, 'off');
});
test('real downloads honour HF_ENDPOINT at call time and keep the source page canonical', async t => {
const previous = process.env.HF_ENDPOINT;
t.after(() => { if (previous === undefined) delete process.env.HF_ENDPOINT; else process.env.HF_ENDPOINT = previous; });
for (const endpoint of ['https://hf-mirror.example/', ' https://hf-mirror.example/// ', undefined, ' ', '///']) {
delete process.env.HF_ENDPOINT;
let fetched;
const { service } = fixture(t, { real: true, catalog: smallCatalog, fetcher: async url => { fetched = url; return new Response(data); } });
if (endpoint !== undefined) process.env.HF_ENDPOINT = endpoint;
service.install('q4'); await service.whenIdle();
const base = endpoint?.includes('hf-mirror') ? 'https://hf-mirror.example' : 'https://huggingface.co';
assert.equal(fetched, `${base}/${smallCatalog.repo}/resolve/${smallCatalog.revision}/${smallCatalog.variants[0].file}`);
assert.equal(service.library().variants[0].state, 'installed');
assert.equal(service.library().sourceUrl, `https://huggingface.co/${smallCatalog.repo}`);
}
});
test('failed verification and failed fetch do not leave installed or partial files', async t => {
for (const body of [Buffer.from('bad!test-image-weights'), data.subarray(0, 7)]) {
const { service, modelsDir } = fixture(t, { real: true, catalog: smallCatalog, fetcher: async () => new Response(body) });