Skip to content

Commit a5bed00

Browse files
committed
implement nologger
1 parent d69c11a commit a5bed00

File tree

17 files changed

+324
-263
lines changed

17 files changed

+324
-263
lines changed

assets/files/localassets.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package files
33
import (
44
"context"
55
"immich-go/assets"
6+
"immich-go/helpers/fshelper"
67
"immich-go/immich/metadata"
8+
"immich-go/logger"
79
"io/fs"
810
"path"
911
"path/filepath"
@@ -14,12 +16,14 @@ import (
1416
type LocalAssetBrowser struct {
1517
fsys fs.FS
1618
albums map[string]string
19+
log logger.Logger
1720
}
1821

19-
func NewLocalFiles(ctx context.Context, fsys fs.FS) (*LocalAssetBrowser, error) {
22+
func NewLocalFiles(ctx context.Context, fsys fs.FS, log logger.Logger) (*LocalAssetBrowser, error) {
2023
return &LocalAssetBrowser{
2124
fsys: fsys,
2225
albums: map[string]string{},
26+
log: log,
2327
}, nil
2428
}
2529

@@ -54,6 +58,11 @@ func (la *LocalAssetBrowser) Browse(ctx context.Context) chan *assets.LocalAsset
5458
return nil
5559
}
5660

61+
ext := path.Ext(name)
62+
if _, err := fshelper.MimeFromExt(strings.ToLower(ext)); err != nil {
63+
return nil
64+
}
65+
la.log.Debug("file '%s'", name)
5766
f := assets.LocalAssetFile{
5867
FSys: la.fsys,
5968
FileName: name,
@@ -76,12 +85,8 @@ func (la *LocalAssetBrowser) Browse(ctx context.Context) chan *assets.LocalAsset
7685
f.DateTaken = time.Now()
7786
}
7887
}
79-
_, err = fs.Stat(la.fsys, name+".xmp")
80-
if err == nil {
81-
f.SideCar = &metadata.SideCar{
82-
FileName: name + ".xmp",
83-
OnFSsys: true,
84-
}
88+
if !la.checkSidecar(&f, name+".xmp") {
89+
la.checkSidecar(&f, strings.TrimSuffix(name, ext)+".xmp")
8590
}
8691
}
8792
fileChan <- &f
@@ -104,6 +109,19 @@ func (la *LocalAssetBrowser) Browse(ctx context.Context) chan *assets.LocalAsset
104109
return fileChan
105110
}
106111

112+
func (la *LocalAssetBrowser) checkSidecar(f *assets.LocalAssetFile, name string) bool {
113+
_, err := fs.Stat(la.fsys, name+".xmp")
114+
if err == nil {
115+
la.log.Debug(" found sidecar: '%s'", name)
116+
f.SideCar = &metadata.SideCar{
117+
FileName: name + ".xmp",
118+
OnFSsys: true,
119+
}
120+
return true
121+
}
122+
return false
123+
}
124+
107125
func (la *LocalAssetBrowser) addAlbum(dir string) {
108126
base := path.Base(dir)
109127
la.albums[dir] = base

assets/files/localassets_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"immich-go/assets/files"
7+
"immich-go/logger"
78
"path"
89
"reflect"
910
"sort"
@@ -73,7 +74,7 @@ func TestLocalAssets(t *testing.T) {
7374
}
7475
ctx := context.Background()
7576

76-
b, err := files.NewLocalFiles(ctx, fsys)
77+
b, err := files.NewLocalFiles(ctx, fsys, logger.NoLogger{})
7778
if err != nil {
7879
t.Error(err)
7980
}

assets/gp/googlephotos.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"immich-go/assets"
77
"immich-go/helpers/fshelper"
8+
"immich-go/logger"
89
"io/fs"
910
"path"
1011
"strings"
@@ -16,6 +17,7 @@ type Takeout struct {
1617
filesByDir map[string][]fileKey // files name mapped by dir
1718
jsonByYear map[jsonKey]*GoogleMetaData // JSON by year of capture and full path
1819
albumsByDir map[string]assets.LocalAlbum // album title mapped by dir
20+
log logger.Logger
1921
}
2022

2123
type fileKey struct {
@@ -31,12 +33,13 @@ type Album struct {
3133
Title string
3234
}
3335

34-
func NewTakeout(ctx context.Context, fsys fs.FS) (*Takeout, error) {
36+
func NewTakeout(ctx context.Context, fsys fs.FS, log logger.Logger) (*Takeout, error) {
3537
to := Takeout{
3638
fsys: fsys,
3739
filesByDir: map[string][]fileKey{},
3840
jsonByYear: map[jsonKey]*GoogleMetaData{},
3941
albumsByDir: map[string]assets.LocalAlbum{},
42+
log: log,
4043
}
4144
err := to.walk(ctx, fsys)
4245

@@ -49,6 +52,7 @@ func (to *Takeout) walk(ctx context.Context, fsys fs.FS) error {
4952
if err != nil {
5053
return err
5154
}
55+
to.log.Debug("walk file '%s'", name)
5256
select {
5357
case <-ctx.Done():
5458
// Check if the context has been cancelled
@@ -116,17 +120,21 @@ func (to *Takeout) Browse(ctx context.Context) chan *assets.LocalAssetFile {
116120
go func() {
117121
defer close(c)
118122
for k, md := range to.jsonByYear {
123+
to.log.Debug("Checking '%s', %d", k.name, k.year)
119124
assets := to.jsonAssets(k, md)
120125
for _, a := range assets {
121126
fk := fileKey{name: path.Base(a.FileName), size: int64(a.FileSize)}
122127
if _, exist := passed[fk]; !exist {
128+
to.log.Debug(" associated with '%s'", fk.name)
123129
passed[fk] = nil
124130
select {
125131
case <-ctx.Done():
126132
return
127133
default:
128134
c <- a
129135
}
136+
} else {
137+
to.log.Debug(" associated with '%s', but already seen", fk.name)
130138
}
131139
}
132140
}

assets/gp/testgp_bigread_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package gp
66
import (
77
"context"
88
"immich-go/helpers/fshelper"
9+
"immich-go/logger"
910
"path/filepath"
1011
"testing"
1112
)
@@ -19,7 +20,7 @@ func TestReadBigTakeout(t *testing.T) {
1920
cnt := 0
2021
fsyss, err := fshelper.ParsePath(m, true)
2122
for _, fsys := range fsyss {
22-
to, err := NewTakeout(context.Background(), fsys)
23+
to, err := NewTakeout(context.Background(), fsys, logger.NoLogger{})
2324
if err != nil {
2425
t.Error(err)
2526
return

assets/gp/testgp_test.go

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

33
import (
44
"context"
5+
"immich-go/logger"
56
"path"
67
"reflect"
78
"testing"
@@ -85,7 +86,7 @@ func TestBrowse(t *testing.T) {
8586
}
8687
ctx := context.Background()
8788

88-
b, err := NewTakeout(ctx, fsys)
89+
b, err := NewTakeout(ctx, fsys, logger.NoLogger{})
8990
if err != nil {
9091
t.Error(err)
9192
}
@@ -160,7 +161,7 @@ func TestAlbums(t *testing.T) {
160161
t.Error(fsys.err)
161162
return
162163
}
163-
b, err := NewTakeout(ctx, fsys)
164+
b, err := NewTakeout(ctx, fsys, logger.NoLogger{})
164165
if err != nil {
165166
t.Error(err)
166167
}

cmdduplicate/duplicate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
type DuplicateCmd struct {
21-
logger *logger.Logger
21+
logger *logger.Log
2222
Immich *immich.ImmichClient // Immich client
2323

2424
AssumeYes bool // When true, doesn't ask to the user
@@ -34,7 +34,7 @@ type duplicateKey struct {
3434
Name string
3535
}
3636

37-
func NewDuplicateCmd(ctx context.Context, ic *immich.ImmichClient, logger *logger.Logger, args []string) (*DuplicateCmd, error) {
37+
func NewDuplicateCmd(ctx context.Context, ic *immich.ImmichClient, logger *logger.Log, args []string) (*DuplicateCmd, error) {
3838
cmd := flag.NewFlagSet("duplicate", flag.ExitOnError)
3939
validRange := immich.DateRange{}
4040
validRange.Set("1850-01-04,2030-01-01")
@@ -57,7 +57,7 @@ func NewDuplicateCmd(ctx context.Context, ic *immich.ImmichClient, logger *logge
5757
return &app, err
5858
}
5959

60-
func DuplicateCommand(ctx context.Context, ic *immich.ImmichClient, log *logger.Logger, args []string) error {
60+
func DuplicateCommand(ctx context.Context, ic *immich.ImmichClient, log *logger.Log, args []string) error {
6161
app, err := NewDuplicateCmd(ctx, ic, log, args)
6262
if err != nil {
6363
return err

cmdmetadata/metadatacmd.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import (
1515

1616
type MetadataCmd struct {
1717
Immich *immich.ImmichClient // Immich client
18-
Log *logger.Logger
18+
Log *logger.Log
1919
DryRun bool
2020
MissingDateDespiteName bool
2121
MissingDate bool
2222
DockerHost string
2323
}
2424

25-
func NewMetadataCmd(ctx context.Context, ic *immich.ImmichClient, logger *logger.Logger, args []string) (*MetadataCmd, error) {
25+
func NewMetadataCmd(ctx context.Context, ic *immich.ImmichClient, logger *logger.Log, args []string) (*MetadataCmd, error) {
2626
var err error
2727
cmd := flag.NewFlagSet("metadata", flag.ExitOnError)
2828
app := MetadataCmd{
@@ -38,7 +38,7 @@ func NewMetadataCmd(ctx context.Context, ic *immich.ImmichClient, logger *logger
3838
return &app, err
3939
}
4040

41-
func MetadataCommand(ctx context.Context, ic *immich.ImmichClient, log *logger.Logger, args []string) error {
41+
func MetadataCommand(ctx context.Context, ic *immich.ImmichClient, log *logger.Log, args []string) error {
4242
app, err := NewMetadataCmd(ctx, ic, log, args)
4343
if err != nil {
4444
return err

cmdstack/cmdstack.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import (
1414

1515
type StackCmd struct {
1616
Immich *immich.ImmichClient // Immich client
17-
logger *logger.Logger
17+
logger *logger.Log
1818

1919
AssumeYes bool
2020
DateRange immich.DateRange // Set capture date range
2121
}
2222

23-
func initSack(xtx context.Context, ic *immich.ImmichClient, log *logger.Logger, args []string) (*StackCmd, error) {
23+
func initSack(xtx context.Context, ic *immich.ImmichClient, log *logger.Log, args []string) (*StackCmd, error) {
2424
cmd := flag.NewFlagSet("stack", flag.ExitOnError)
2525
validRange := immich.DateRange{}
2626

@@ -40,7 +40,7 @@ func initSack(xtx context.Context, ic *immich.ImmichClient, log *logger.Logger,
4040
err := cmd.Parse(args)
4141
return &app, err
4242
}
43-
func NewStackCommand(ctx context.Context, ic *immich.ImmichClient, log *logger.Logger, args []string) error {
43+
func NewStackCommand(ctx context.Context, ic *immich.ImmichClient, log *logger.Log, args []string) error {
4444
app, err := initSack(ctx, ic, log, args)
4545
if err != nil {
4646
return err

cmdtool/cmdalbum/cmdalbum.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"strconv"
1313
)
1414

15-
func AlbumCommand(ctx context.Context, ic *immich.ImmichClient, log *logger.Logger, args []string) error {
15+
func AlbumCommand(ctx context.Context, ic *immich.ImmichClient, log *logger.Log, args []string) error {
1616
if len(args) > 0 {
1717
cmd := args[0]
1818
args = args[1:]
@@ -26,13 +26,13 @@ func AlbumCommand(ctx context.Context, ic *immich.ImmichClient, log *logger.Logg
2626
}
2727

2828
type DeleteAlbumCmd struct {
29-
log *logger.Logger
29+
log *logger.Log
3030
Immich *immich.ImmichClient // Immich client
3131
pattern *regexp.Regexp // album pattern
3232
AssumeYes bool
3333
}
3434

35-
func deleteAlbum(ctx context.Context, ic *immich.ImmichClient, log *logger.Logger, args []string) error {
35+
func deleteAlbum(ctx context.Context, ic *immich.ImmichClient, log *logger.Log, args []string) error {
3636
app := &DeleteAlbumCmd{
3737
log: log,
3838
Immich: ic,

cmdtool/cmdtool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"immich-go/logger"
99
)
1010

11-
func CommandTool(ctx context.Context, ic *immich.ImmichClient, logger *logger.Logger, args []string) error {
11+
func CommandTool(ctx context.Context, ic *immich.ImmichClient, logger *logger.Log, args []string) error {
1212
if len(args) > 0 {
1313
cmd := args[0]
1414
args = args[1:]

0 commit comments

Comments
 (0)