mirror of
https://github.com/immich-app/immich.git
synced 2025-12-20 09:15:35 +03:00
feat(server): replace axios dependency by fetch (#7018)
* feat: replace axios dependency by fetch * pr feedback
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
import { GitHubRelease, IServerInfoRepository } from '@app/domain';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import axios from 'axios';
|
||||
|
||||
@Injectable()
|
||||
export class ServerInfoRepository implements IServerInfoRepository {
|
||||
getGitHubRelease(): Promise<GitHubRelease> {
|
||||
return axios
|
||||
.get<GitHubRelease>('https://api.github.com/repos/immich-app/immich/releases/latest')
|
||||
.then((response) => response.data);
|
||||
async getGitHubRelease(): Promise<GitHubRelease> {
|
||||
try {
|
||||
const response = await fetch('https://api.github.com/repos/immich-app/immich/releases/latest');
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`GitHub API request failed with status ${response.status}: ${await response.text()}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to fetch GitHub release: ${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { ISystemConfigRepository } from '@app/domain';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import axios from 'axios';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { In, Repository } from 'typeorm';
|
||||
import { SystemConfigEntity } from '../entities';
|
||||
@@ -13,7 +12,17 @@ export class SystemConfigRepository implements ISystemConfigRepository {
|
||||
private repository: Repository<SystemConfigEntity>,
|
||||
) {}
|
||||
async fetchStyle(url: string) {
|
||||
return axios.get(url).then((response) => response.data);
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch data from ${url} with status ${response.status}: ${await response.text()}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to fetch data from ${url}: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
@GenerateSql()
|
||||
|
||||
Reference in New Issue
Block a user