Skip to content

Commit

Permalink
fix Takout zip is unsupported file type #357 (#415)
Browse files Browse the repository at this point in the history
* fix Duplicated assets already uploaded are not counted as Duplicates #414

* fix Takout zip is unsupported file type #357
  • Loading branch information
simulot authored Jul 31, 2024
1 parent ca96b75 commit ff81fd0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion browser/gp/googlephotos.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (to *Takeout) passOneFsWalk(ctx context.Context, w fs.FS) error {
dirCatalog.matchedFiles = map[string]*assetFile{}
}
if _, ok := dirCatalog.unMatchedFiles[base]; ok {
// to.log.Record(ctx, fileevent.AnalysisLocalDuplicate, nil, name)
to.log.Record(ctx, fileevent.AnalysisLocalDuplicate, nil, name)
return nil
}

Expand Down
13 changes: 5 additions & 8 deletions cmd/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func (app *UpCmd) handleAsset(ctx context.Context, a *browser.LocalAssetFile) er
return nil
}
if !app.BrowserConfig.SelectExtensions.Include(ext) {
app.Jnl.Record(ctx, fileevent.UploadNotSelected, a.FileName, "reason", "extension not in selection list")
app.Jnl.Record(ctx, fileevent.UploadNotSelected, a, a.FileName, "reason", "extension not in selection list")
return nil
}

Expand Down Expand Up @@ -465,8 +465,8 @@ func (app *UpCmd) handleAsset(ctx context.Context, a *browser.LocalAssetFile) er
app.manageAssetAlbum(ctx, ID, a, advice)

case SmallerOnServer: // Upload, manage albums and delete the server's asset
app.Jnl.Record(ctx, fileevent.UploadUpgraded, a, a.FileName)
// add the superior asset into albums of the original asset
app.Jnl.Record(ctx, fileevent.UploadUpgraded, a, a.FileName, "reason", advice.Message)
// add the superior asset into albums of the original asset.
ID, err := app.UploadAsset(ctx, a)
if err != nil {
return nil
Expand All @@ -481,17 +481,14 @@ func (app *UpCmd) handleAsset(ctx context.Context, a *browser.LocalAssetFile) er
case SameOnServer: // manage albums
// Set add the server asset into albums determined locally
if !advice.ServerAsset.JustUploaded {
app.Jnl.Record(ctx, fileevent.UploadServerDuplicate, a, a.FileName)
app.Jnl.Record(ctx, fileevent.UploadServerDuplicate, a, a.FileName, "reason", advice.Message)
} else {
app.Jnl.Record(ctx, fileevent.AnalysisLocalDuplicate, a, a.FileName)
if a.LivePhoto != nil {
app.Jnl.Record(ctx, fileevent.AnalysisLocalDuplicate, a, a.LivePhoto.FileName)
}
}
app.manageAssetAlbum(ctx, advice.ServerAsset.ID, a, advice)

case BetterOnServer: // and manage albums
app.Jnl.Record(ctx, fileevent.UploadServerBetter, a, a.FileName)
app.Jnl.Record(ctx, fileevent.UploadServerBetter, a, a.FileName, "reason", advice.Message)
app.manageAssetAlbum(ctx, advice.ServerAsset.ID, a, advice)
}

Expand Down
3 changes: 2 additions & 1 deletion docs/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
- [ ] [#393](https://github.com/simulot/immich-go/issues/393)
- Creation date incorrect
- [ ] [#397](https://github.com/simulot/immich-go/issues/397)

- Various
- [ ] [#357](https://github.com/simulot/immich-go/issues/357)

4 changes: 4 additions & 0 deletions helpers/fileevent/fileevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sync"
"sync/atomic"

"github.com/simulot/immich-go/browser"
"github.com/simulot/immich-go/helpers/gen"
)

Expand Down Expand Up @@ -124,6 +125,9 @@ func (r *Recorder) Record(ctx context.Context, code Code, object any, file strin
}
r.log.Log(ctx, level, code.String(), args...)
}
if a, ok := object.(*browser.LocalAssetFile); ok && a.LivePhoto != nil {
r.Record(ctx, code, a.LivePhoto, a.LivePhoto.FileName, args...)
}
}

func (r *Recorder) SetLogger(l *slog.Logger) {
Expand Down
36 changes: 18 additions & 18 deletions helpers/fshelper/parseArgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@ func ParsePath(args []string) ([]fs.FS, error) {

for _, a := range args {
a = filepath.ToSlash(a)
lowA := strings.ToLower(a)
switch {
case strings.HasSuffix(lowA, ".tgz") || strings.HasSuffix(lowA, ".tar.gz"):
errs = errors.Join(fmt.Errorf("immich-go cant use tgz archives: %s", filepath.Base(a)))
case strings.HasSuffix(lowA, ".zip"):
files, err := expandNames(a)
if err != nil {
errs = errors.Join(errs, fmt.Errorf("%s: %w", a, err))
break
}
for _, f := range files {
files, err := expandNames(a)
if err != nil {
return nil, err
}

for _, f := range files {
lowF := strings.ToLower(f)
switch {
case strings.HasSuffix(lowF, ".tgz") || strings.HasSuffix(lowF, ".tar.gz"):
errs = errors.Join(fmt.Errorf("immich-go cant use tgz archives: %s", filepath.Base(a)))
case strings.HasSuffix(lowF, ".zip"):
fsys, err := zip.OpenReader(f)
if err != nil {
errs = errors.Join(errs, fmt.Errorf("%s: %w", a, err))
continue
}
fsyss = append(fsyss, fsys)
default:
fsys, err := NewGlobWalkFS(f)
if err != nil {
errs = errors.Join(errs, err)
continue
}
fsyss = append(fsyss, fsys)
}
default:
fsys, err := NewGlobWalkFS(a)
if err != nil {
errs = errors.Join(errs, err)
continue
}
fsyss = append(fsyss, fsys)
}
}
if errs != nil {
Expand Down

0 comments on commit ff81fd0

Please sign in to comment.