Skip to content

Commit

Permalink
chore: immich API changes
Browse files Browse the repository at this point in the history
updateAsset
updateAssets
  • Loading branch information
simulot committed Dec 8, 2023
1 parent dff58a0 commit 7a445eb
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmdstack/cmdstack.go
Expand Up @@ -85,7 +85,7 @@ func NewStackCommand(ctx context.Context, ic *immich.ImmichClient, log *logger.L
}
}
if yes {
err := app.Immich.UpdateAssets(ctx, s.IDs, false, false, false, cover)
err := app.Immich.StackAssets(ctx, cover, s.IDs)
if err != nil {
log.Warning("Can't stack images: %s", err)
}
Expand Down
8 changes: 8 additions & 0 deletions cmdupload/e2e_upload_folder_test.go
Expand Up @@ -101,6 +101,14 @@ func TestE2eUpload(t *testing.T) {
// resetImmich: true,
expectError: false,
},
{
name: "upload burst PIXEL6",
args: []string{
"../../test-data/burst/PXL6",
},
// resetImmich: true,
expectError: false,
},
}

logger := logger.NoLogger{}
Expand Down
10 changes: 5 additions & 5 deletions cmdupload/upload.go
Expand Up @@ -36,7 +36,8 @@ type iClient interface {
GetAllAlbums(context.Context) ([]immich.AlbumSimplified, error)
AddAssetToAlbum(context.Context, string, []string) ([]immich.UpdateAlbumResult, error)
CreateAlbum(context.Context, string, []string) (immich.AlbumSimplified, error)
UpdateAssets(ctx context.Context, IDs []string, isArchived bool, isFavorite bool, removeParent bool, stackParentId string) error
UpdateAssets(ctx context.Context, IDs []string, isArchived bool, isFavorite bool, latitude float64, longitude float64, removeParent bool, stackParentId string) error
StackAssets(ctx context.Context, cover string, IDs []string) error
}

type UpCmd struct {
Expand Down Expand Up @@ -252,10 +253,11 @@ assetLoop:
for _, s := range stacks {
log.OK(" Stacking %s...", strings.Join(s.Names, ", "))
if !app.DryRun {
err = app.client.UpdateAssets(ctx, s.IDs, false, false, false, s.CoverID)
err = app.client.StackAssets(ctx, s.CoverID, s.IDs)
if err != nil {
log.Warning("Can't stack images: %s", err)
}

}
}
}
Expand Down Expand Up @@ -475,9 +477,7 @@ func (app *UpCmd) UploadAsset(ctx context.Context, a *browser.LocalAssetFile) {
} else {
switch {
case app.GooglePhotos:
for _, al := range a.Albums {
albums = append(albums, al)
}
albums = append(albums, a.Albums...)
if app.PartnerAlbum != "" && a.FromPartner {
albums = append(albums, browser.LocalAlbum{Path: app.PartnerAlbum, Name: app.PartnerAlbum})
}
Expand Down
6 changes: 5 additions & 1 deletion cmdupload/upload_test.go
Expand Up @@ -36,7 +36,11 @@ func (c *stubIC) AddAssetToAlbum(context.Context, string, []string) ([]immich.Up
func (c *stubIC) CreateAlbum(context.Context, string, []string) (immich.AlbumSimplified, error) {
return immich.AlbumSimplified{}, nil
}
func (c *stubIC) UpdateAssets(ctx context.Context, IDs []string, isArchived bool, isFavorite bool, removeParent bool, stackParentId string) error {
func (c *stubIC) UpdateAssets(ctx context.Context, IDs []string, isArchived bool, isFavorite bool, latitude float64, longitude float64, removeParent bool, stackParentId string) error {
return nil
}

func (c *stubIC) StackAssets(ctx context.Context, cover string, IDs []string) error {
return nil
}

Expand Down
41 changes: 39 additions & 2 deletions immich/asset.go
Expand Up @@ -192,11 +192,16 @@ func (ic *ImmichClient) GetAssetByID(ctx context.Context, id string) (*Asset, er
return &r, err
}

func (ic *ImmichClient) UpdateAssets(ctx context.Context, IDs []string, isArchived bool, isFavorite bool, removeParent bool, stackParentId string) error {
func (ic *ImmichClient) UpdateAssets(ctx context.Context, IDs []string,
isArchived bool, isFavorite bool,
latitude float64, longitude float64,
removeParent bool, stackParentId string) error {
type updAssets struct {
IDs []string `json:"ids"`
IsArchived bool `json:"isArchived"`
IsFavorite bool `json:"isFavorite"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
RemoveParent bool `json:"removeParent"`
StackParentId string `json:"stackParentId,omitempty"`
}
Expand All @@ -205,8 +210,40 @@ func (ic *ImmichClient) UpdateAssets(ctx context.Context, IDs []string, isArchiv
IDs: IDs,
IsArchived: isArchived,
IsFavorite: isFavorite,
Latitude: latitude,
Longitude: longitude,
RemoveParent: removeParent,
StackParentId: stackParentId,
}
return ic.newServerCall(ctx, "updAssets").do(put("/asset", setJSONBody(param)))
return ic.newServerCall(ctx, "updateAssets").do(put("/asset", setJSONBody(param)))
}

func (ic *ImmichClient) UpdateAsset(ctx context.Context, ID string,
dateTimeOriginal time.Time, description string, isArchived bool, isFavorite bool,
latitude float64, longitude float64) (*Asset, error) {

type updAsset struct {
IsArchived bool `json:"isArchived"`
IsFavorite bool `json:"isFavorite"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
}
param := updAsset{
IsArchived: isArchived,
IsFavorite: isFavorite,
Latitude: latitude,
Longitude: longitude,
}
r := Asset{}
err := ic.newServerCall(ctx, "updateAsset").do(put("/asset/"+ID, setJSONBody(param)), responseJSON(&r))
return &r, err
}

func (ic *ImmichClient) StackAssets(ctx context.Context, coverID string, IDs []string) error {
cover, err := ic.GetAssetByID(ctx, coverID)
if err != nil {
return err
}

return ic.UpdateAssets(ctx, IDs, cover.IsArchived, cover.IsFavorite, cover.ExifInfo.Latitude, cover.ExifInfo.Longitude, false, coverID)
}
2 changes: 1 addition & 1 deletion immich/immich.go
Expand Up @@ -132,7 +132,7 @@ type ExifInfo struct {
// City string `json:"city"`
// State string `json:"state"`
// Country string `json:"country"`
// Description string `json:"description"`
Description string `json:"description"`
}

type ImmichTime struct {
Expand Down

0 comments on commit 7a445eb

Please sign in to comment.