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
@@ -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
|
||||
|
||||
Reference in new issue
Block a user