fix(immich): v3 API compatibility — use searchAssets for album assets, drop deviceAssetId (#5977)
This commit is contained in:
1 parent
b588672709
commit
a5ec880eec
6 files changed
+52
-39
No files matched your search
@@ -77,11 +77,12 @@ export const releasesRouter = createTRPCRouter({
|
||||
|
||||
return await Promise.all(
|
||||
input.repositories.map(async (repository) => {
|
||||
const repositoryId = repository.id ?? repository.identifier;
|
||||
try {
|
||||
const useToken = allowedRepoIds === null || allowedRepoIds.has(repository.id);
|
||||
const useToken = allowedRepoIds === null || allowedRepoIds.has(repositoryId);
|
||||
const response = await releasesRequestHandler
|
||||
.handler({
|
||||
id: repository.id,
|
||||
id: repositoryId,
|
||||
provider: repository.provider,
|
||||
identifier: repository.identifier,
|
||||
versionRegex: formatVersionFilterRegex(repository.versionFilter),
|
||||
@@ -93,14 +94,14 @@ export const releasesRouter = createTRPCRouter({
|
||||
});
|
||||
|
||||
return {
|
||||
id: repository.id,
|
||||
id: repositoryId,
|
||||
provider: repository.provider,
|
||||
timestamp: response.timestamp,
|
||||
...response.data,
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
id: repository.id,
|
||||
id: repositoryId,
|
||||
provider: repository.provider,
|
||||
timestamp: new Date(),
|
||||
success: false as const,
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
import { getAlbumInfo, getAllAlbums, getMyUser, getServerStatistics, init, searchUsers } from "@immich/sdk";
|
||||
import {
|
||||
getAlbumInfo,
|
||||
getAllAlbums,
|
||||
getMyUser,
|
||||
getServerStatistics,
|
||||
init,
|
||||
searchAssets,
|
||||
searchUsers,
|
||||
} from "@immich/sdk";
|
||||
import type { AssetResponseDto, MetadataSearchDto } from "@immich/sdk";
|
||||
|
||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||
@@ -23,7 +32,6 @@ export interface ImmichAlbum {
|
||||
|
||||
export interface ImmichAsset {
|
||||
id: string;
|
||||
deviceAssetId: string;
|
||||
originalPath: string;
|
||||
thumbhash: string | null;
|
||||
fileModifiedAt: string;
|
||||
@@ -56,12 +64,16 @@ export class ImmichIntegration extends Integration {
|
||||
|
||||
public async getAlbumAsync(albumId: string): Promise<ImmichAlbum> {
|
||||
this.initClient();
|
||||
const album = await getAlbumInfo({ id: albumId }, this.getRequestOptions());
|
||||
const requestOptions = this.getRequestOptions();
|
||||
const [album, albumAssets] = await Promise.all([
|
||||
getAlbumInfo({ id: albumId }, requestOptions),
|
||||
this.searchAlbumAssetsAsync(albumId),
|
||||
]);
|
||||
const imageProxy = new ImageProxy();
|
||||
return {
|
||||
albumName: album.albumName,
|
||||
assets: await Promise.all(
|
||||
album.assets.map(async (asset) => {
|
||||
albumAssets.map(async (asset) => {
|
||||
const publicLink = await imageProxy.createImageAsync(
|
||||
this.url(`/api/assets/${asset.id}/original`).toString(),
|
||||
{
|
||||
@@ -71,7 +83,6 @@ export class ImmichIntegration extends Integration {
|
||||
return {
|
||||
id: asset.id,
|
||||
type: asset.type,
|
||||
deviceAssetId: asset.deviceAssetId,
|
||||
thumbhash: asset.thumbhash,
|
||||
fileCreatedAt: asset.fileCreatedAt,
|
||||
fileModifiedAt: asset.fileModifiedAt,
|
||||
@@ -104,6 +115,24 @@ export class ImmichIntegration extends Integration {
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
private async searchAlbumAssetsAsync(albumId: string): Promise<AssetResponseDto[]> {
|
||||
const requestOptions = this.getRequestOptions();
|
||||
const assets: AssetResponseDto[] = [];
|
||||
let nextPage: string | null = null;
|
||||
|
||||
do {
|
||||
const metadataSearchDto: MetadataSearchDto = { albumIds: [albumId] };
|
||||
if (nextPage !== null) {
|
||||
metadataSearchDto.page = Number(nextPage);
|
||||
}
|
||||
const searchResult = await searchAssets({ metadataSearchDto }, requestOptions);
|
||||
assets.push(...searchResult.assets.items);
|
||||
nextPage = searchResult.assets.nextPage;
|
||||
} while (nextPage !== null);
|
||||
|
||||
return assets;
|
||||
}
|
||||
|
||||
private getRequestOptions(fetchAsync = fetchWithTrustedCertificatesAsync) {
|
||||
return {
|
||||
// Undici and node types are not the same
|
||||
|
||||
@@ -9,7 +9,7 @@ import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||
const logger = createLogger({ module: "releaseProviders" });
|
||||
|
||||
const PROVIDER_TIMEOUT_MS = 10_000;
|
||||
const fetchProvider = (url: URL | RequestInfo, options?: RequestInit & { timeout?: number }) =>
|
||||
const fetchProvider: typeof fetchWithTrustedCertificatesAsync = (url, options) =>
|
||||
fetchWithTrustedCertificatesAsync(url, { timeout: PROVIDER_TIMEOUT_MS, ...options });
|
||||
|
||||
export interface ReleasesRepositoryRequest extends Record<string, unknown> {
|
||||
|
||||
@@ -76,7 +76,6 @@ function shuffle<T>(items: T[]) {
|
||||
interface CarouselProps {
|
||||
assets: {
|
||||
id: string;
|
||||
deviceAssetId: string;
|
||||
originalPath: string;
|
||||
fileModifiedAt: string;
|
||||
publicLink: string;
|
||||
|
||||
Reference in new issue
Block a user