Skip to content

Commit

Permalink
Prevent the Upload of photos that are trashed (Google Photos)
Browse files Browse the repository at this point in the history
Fixes #287
  • Loading branch information
simulot committed Jun 9, 2024
1 parent 0c60659 commit bb9fa66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
3 changes: 0 additions & 3 deletions cmd/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,6 @@ func (app *UpCmd) getImmichAssets(ctx context.Context, updateFn progressUpdate)
return ctx.Err()
default:
received++
if a.IsTrashed {
return nil
}
list = append(list, a)
if updateFn != nil {
updateFn(received, totalOnImmich)
Expand Down
25 changes: 9 additions & 16 deletions immich/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import (
"context"
)

type searchMetadataBody interface {
setPage(p int)
}

type searchMetadataResponse struct {
Assets struct {
Total int `json:"total"`
Expand All @@ -18,17 +14,14 @@ type searchMetadataResponse struct {
}

type searchMetadataGetAllBody struct {
Page int `json:"page"`
WithExif bool `json:"withExif,omitempty"`
IsVisible bool `json:"isVisible,omitempty"`
}

func (sb *searchMetadataGetAllBody) setPage(p int) {
sb.Page = p
Page int `json:"page"`
WithExif bool `json:"withExif,omitempty"`
IsVisible bool `json:"isVisible,omitempty"`
WithDeleted bool `json:"withDeleted,omitempty"`
}

func (ic *ImmichClient) callSearchMetadata(ctx context.Context, req searchMetadataBody, filter func(*Asset) error) error {
req.setPage(1)
func (ic *ImmichClient) callSearchMetadata(ctx context.Context, req *searchMetadataGetAllBody, filter func(*Asset) error) error {
req.Page = 1
for {
select {
case <-ctx.Done():
Expand All @@ -50,15 +43,15 @@ func (ic *ImmichClient) callSearchMetadata(ctx context.Context, req searchMetada
if resp.Assets.NextPage == 0 {
return nil
}
req.setPage(resp.Assets.NextPage)
req.Page = resp.Assets.NextPage
}
}
}

func (ic *ImmichClient) GetAllAssets(ctx context.Context) ([]*Asset, error) {
var assets []*Asset

req := searchMetadataGetAllBody{Page: 1, WithExif: true, IsVisible: true}
req := searchMetadataGetAllBody{Page: 1, WithExif: true, IsVisible: true, WithDeleted: true}
err := ic.callSearchMetadata(ctx, &req, func(asset *Asset) error {
assets = append(assets, asset)
return nil
Expand All @@ -70,6 +63,6 @@ func (ic *ImmichClient) GetAllAssets(ctx context.Context) ([]*Asset, error) {
}

func (ic *ImmichClient) GetAllAssetsWithFilter(ctx context.Context, filter func(*Asset) error) error {
req := searchMetadataGetAllBody{Page: 1, WithExif: true, IsVisible: true}
req := searchMetadataGetAllBody{Page: 1, WithExif: true, IsVisible: true, WithDeleted: true}
return ic.callSearchMetadata(ctx, &req, filter)
}

0 comments on commit bb9fa66

Please sign in to comment.