Skip to content

Commit b377822

Browse files
committed
feat: add user information to client and enhance asset filtering by owner and library ID
fix: Immich's partner's assets make immich-go panicing since v0.24.7 #824
1 parent abacb17 commit b377822

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

app/client.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ type Client struct {
123123
Immich immich.ImmichInterface // Immich client
124124
ClientLog *slog.Logger // Logger
125125
OnServerErrors cliflags.OnServerErrorsFlag // Behavior on server errors
126+
User immich.User // User info corresponding to the API key
126127
}
127128

128129
func (client *Client) Initialize(ctx context.Context, app *Application) error {
@@ -187,14 +188,15 @@ func (client *Client) Open(ctx context.Context) error {
187188
if err != nil {
188189
return err
189190
}
191+
client.User = user
190192

191193
about, err := client.Immich.GetAboutInfo(ctx)
192194
if err != nil {
193195
return err
194196
}
195197
client.ClientLog.Info("Server information:", "version", about.Version)
196198

197-
client.ClientLog.Info(fmt.Sprintf("Connected, user: %s", user.Email))
199+
client.ClientLog.Info(fmt.Sprintf("Connected, user: %s, ID: %s", user.Email, user.ID))
198200
if client.DryRun {
199201
client.ClientLog.Info("Dry-run mode enabled. No changes will be made to the server.")
200202
}

app/cmd/upload/run.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,26 @@ func (upCmd *UpCmd) getImmichAssets(ctx context.Context, updateFn progressUpdate
195195
received := 0
196196

197197
err = upCmd.app.Client().Immich.GetAllAssetsWithFilter(ctx, nil, func(a *immich.Asset) error {
198+
if updateFn != nil {
199+
defer func() {
200+
updateFn(received, totalOnImmich)
201+
}()
202+
}
198203
select {
199204
case <-ctx.Done():
200205
return ctx.Err()
201206
default:
202207
received++
208+
if a.OwnerID != upCmd.app.Client().User.ID {
209+
upCmd.app.Log().Debug("Skipping asset with different owner", "assetOwnerID", a.OwnerID, "clientUserID", upCmd.app.Client().User.ID, "ID", a.ID, "FileName", a.OriginalFileName, "Capture date", a.ExifInfo.DateTimeOriginal, "CheckSum", a.Checksum, "FileSize", a.ExifInfo.FileSizeInByte, "DeviceAssetID", a.DeviceAssetID, "OwnerID", a.OwnerID, "IsTrashed", a.IsTrashed, "IsArchived", a.IsArchived)
210+
return nil
211+
}
212+
if a.LibraryID != "" {
213+
upCmd.app.Log().Debug("Skipping asset with external library", "assetLibraryID", a.LibraryID, "ID", a.ID, "FileName", a.OriginalFileName, "Capture date", a.ExifInfo.DateTimeOriginal, "CheckSum", a.Checksum, "FileSize", a.ExifInfo.FileSizeInByte, "DeviceAssetID", a.DeviceAssetID, "OwnerID", a.OwnerID, "IsTrashed", a.IsTrashed, "IsArchived", a.IsArchived)
214+
return nil
215+
}
203216
upCmd.assetIndex.addImmichAsset(a)
204217
upCmd.app.Log().Debug("Immich asset:", "ID", a.ID, "FileName", a.OriginalFileName, "Capture date", a.ExifInfo.DateTimeOriginal, "CheckSum", a.Checksum, "FileSize", a.ExifInfo.FileSizeInByte, "DeviceAssetID", a.DeviceAssetID, "OwnerID", a.OwnerID, "IsTrashed", a.IsTrashed, "IsArchived", a.IsArchived)
205-
if updateFn != nil {
206-
updateFn(received, totalOnImmich)
207-
}
208218
return nil
209219
}
210220
})

immich/asset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Asset struct {
3636
StackParentID string `json:"stackParentId"`
3737
Albums []AlbumSimplified `json:"-"` // Albums that asset belong to
3838
Tags []TagSimplified `json:"tags"`
39-
// JustUploaded bool `json:"-"` // TO REMOVE
39+
LibraryID string `json:"libraryId,omitempty"`
4040
}
4141

4242
// NewAssetFromImmich creates an assets.Asset from an immich.Asset.

0 commit comments

Comments
 (0)