mirror of
https://github.com/immich-app/immich.git
synced 2026-06-05 14:25:16 -04:00
feat: move version checks to our own infrastructure (#27450)
This commit is contained in:
@@ -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;
|
||||
});
|
||||
});
|
||||
@@ -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 });
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user