feat: move version checks to our own infrastructure (#27450)

This commit is contained in:
Zack Pollard
2026-04-02 23:32:26 +01:00
committed by GitHub
parent adb6b39eec
commit db0f86c749
61 changed files with 104 additions and 72 deletions
+18
View File
@@ -0,0 +1,18 @@
import { serverVersion } from 'src/constants';
import { configureUserAgent } from 'src/utils/fetch';
describe('fetch', () => {
it('should set the default user-agent header', async () => {
const spy = vi.fn().mockResolvedValue(new Response());
const original = globalThis.fetch;
globalThis.fetch = spy;
configureUserAgent();
await globalThis.fetch('http://test.local');
const headers: Headers = spy.mock.calls[0][1].headers;
expect(headers.get('User-Agent')).toBe(`immich-server/${serverVersion}`);
globalThis.fetch = original;
});
});
+12
View File
@@ -0,0 +1,12 @@
import { serverVersion } from 'src/constants';
export function configureUserAgent() {
const originalFetch = globalThis.fetch;
globalThis.fetch = (input, init) => {
const headers = new Headers(init?.headers);
if (!headers.has('User-Agent')) {
headers.set('User-Agent', `immich-server/${serverVersion}`);
}
return originalFetch(input, { ...init, headers });
};
}