Skip to content

Commit c4b667e

Browse files
committed
fixes: Uploading photo with latitude but no longitude gives a bad request #843
add custom JSON marshaling for UpdAssetField to include GPS when either latitude or longitude is not zero.
1 parent e51ee2f commit c4b667e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

immich/asset.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package immich
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"io"
78
"net/url"
@@ -216,6 +217,22 @@ type UpdAssetField struct {
216217
DateTimeOriginal time.Time `json:"dateTimeOriginal,omitempty"`
217218
}
218219

220+
func (u UpdAssetField) MarshalJSON() ([]byte, error) {
221+
type withGPS struct {
222+
IsArchived bool `json:"isArchived,omitempty"`
223+
IsFavorite bool `json:"isFavorite,omitempty"`
224+
Latitude float64 `json:"latitude"`
225+
Longitude float64 `json:"longitude"`
226+
Description string `json:"description,omitempty"`
227+
Rating int `json:"rating,omitempty"`
228+
DateTimeOriginal time.Time `json:"dateTimeOriginal,omitempty"`
229+
}
230+
if u.Latitude != 0 || u.Longitude != 0 {
231+
return json.Marshal(withGPS(u))
232+
}
233+
return json.Marshal(u)
234+
}
235+
219236
func (ic *ImmichClient) UpdateAsset(ctx context.Context, id string, param UpdAssetField) (*Asset, error) {
220237
if ic.dryRun {
221238
return nil, nil

0 commit comments

Comments
 (0)