Skip to content

Commit

Permalink
Few UI fixes (#373)
Browse files Browse the repository at this point in the history
* better handling of cancelation

* add file name to the UploadAsset API trace

* e2e test log files into the default log directory

* add a message when upload ends

* improve the final message

* refactre nonui

* fix: Real time GUI log only shows 4 lines  #299

* Fix #299, #370, #232

* edit readme

* fix lint
  • Loading branch information
simulot committed Jul 13, 2024
1 parent 2dfb29b commit 53889ea
Show file tree
Hide file tree
Showing 12 changed files with 569 additions and 464 deletions.
Binary file added __debug_bin3601520615
Binary file not shown.
23 changes: 21 additions & 2 deletions cmd/upload/e2e_upload_folder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"testing"
"time"

"github.com/joho/godotenv"
"github.com/simulot/immich-go/cmd"
"github.com/simulot/immich-go/helpers/configuration"
"github.com/simulot/immich-go/immich"
)

Expand Down Expand Up @@ -96,7 +98,7 @@ func runCase(t *testing.T, tc testCase) {
}
}

args := []string{"-server=" + host, "-key=" + key, "-log-file=" + tc.name + ".log", "-log-level=INFO", "-no-ui"}
args := []string{"-server=" + host, "-key=" + key, "-log-file=" + filepath.Join(filepath.Dir(configuration.DefaultLogFile()), tc.name+".log"), "-log-level=INFO", "-no-ui"}

if tc.APITrace {
args = append(args, "-api-trace=TRUE")
Expand Down Expand Up @@ -542,7 +544,7 @@ func Test_BannedFiles_(t *testing.T) {
},
resetImmich: true,
expectError: false,
APITrace: false,
APITrace: true,
}
runCase(t, tc)
}
Expand Down Expand Up @@ -598,6 +600,23 @@ func Test_SmallTakeout_Better_p2(t *testing.T) {
runCase(t, tc)
}

func Test_MotionPictures_303_280(t *testing.T) {
initMyEnv(t)

tc := testCase{
name: "Test_MotionPictures_303_280",
args: []string{
"-api-trace",
"-google-photos",
myEnv["IMMICH_TESTFILES"] + "/Motion photo #303 #280/takeout-motion-test.zip",
},
resetImmich: true,
expectError: false,
APITrace: true,
}
runCase(t, tc)
}

// ResetImmich
// ⛔: will remove the content of the server.‼️
// Give the user of the connection to confirm the server instance: debug@example.com
Expand Down
128 changes: 128 additions & 0 deletions cmd/upload/noui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package upload

import (
"context"
"fmt"
"time"

"github.com/simulot/immich-go/helpers/fileevent"
"golang.org/x/sync/errgroup"
)

func (app *UpCmd) runNoUI(ctx context.Context) error {
ctx, cancel := context.WithCancelCause(ctx)
defer cancel(nil)

stopProgress := make(chan any)
var maxImmich, currImmich int
spinner := []rune{' ', ' ', '.', ' ', ' '}
spinIdx := 0

immichUpdate := func(value, total int) {
currImmich, maxImmich = value, total
}

progressString := func() string {
var s string
counts := app.Jnl.GetCounts()
immichPct := 0
if maxImmich > 0 {
immichPct = 100 * currImmich / maxImmich
}
ScannedAssets := counts[fileevent.DiscoveredImage] + counts[fileevent.DiscoveredVideo] - counts[fileevent.DiscoveredDiscarded]
ProcessedAssets := counts[fileevent.Uploaded] +
counts[fileevent.UploadServerError] +
counts[fileevent.UploadNotSelected] +
counts[fileevent.UploadUpgraded] +
counts[fileevent.UploadServerDuplicate] +
counts[fileevent.UploadServerBetter] +
counts[fileevent.DiscoveredDiscarded] +
counts[fileevent.AnalysisLocalDuplicate]

if app.GooglePhotos {
gpPct := 0
upPct := 0
if ScannedAssets > 0 {
gpPct = int(100 * counts[fileevent.AnalysisAssociatedMetadata] / ScannedAssets)
}
if counts[fileevent.AnalysisAssociatedMetadata] > 0 {
upPct = int(100 * ProcessedAssets / counts[fileevent.AnalysisAssociatedMetadata])
}

s = fmt.Sprintf("\rImmich read %d%%, Google Photos Analysis: %d%%, Upload errors: %d, Uploaded %d%% %s", immichPct, gpPct, counts[fileevent.UploadServerError], upPct, string(spinner[spinIdx]))
} else {
s = fmt.Sprintf("\rImmich read %d%%, Processed %d, Upload errors: %d, Uploaded %d %s", immichPct, ProcessedAssets, counts[fileevent.UploadServerError], counts[fileevent.Uploaded], string(spinner[spinIdx]))
}
spinIdx++
if spinIdx == len(spinner) {
spinIdx = 0
}
return s
}
uiGrp := errgroup.Group{}

uiGrp.Go(func() error {
ticker := time.NewTicker(500 * time.Millisecond)
defer func() {
ticker.Stop()
fmt.Println(progressString())
}()
for {
select {
case <-stopProgress:
fmt.Print(progressString())
return nil
case <-ctx.Done():
fmt.Print(progressString())
return ctx.Err()
case <-ticker.C:
fmt.Print(progressString())
}
}
})

uiGrp.Go(func() error {
processGrp := errgroup.Group{}

processGrp.Go(func() error {
// Get immich asset
err := app.getImmichAssets(ctx, immichUpdate)
if err != nil {
cancel(err)
}
return err
})
processGrp.Go(func() error {
return app.getImmichAlbums(ctx)
})
processGrp.Go(func() error {
// Run Prepare
err := app.browser.Prepare(ctx)
if err != nil {
cancel(err)
}
return err
})
err := processGrp.Wait()
if err != nil {
err := context.Cause(ctx)
if err != nil {
cancel(err)
return err
}
}
err = app.uploadLoop(ctx)
if err != nil {
cancel(err)
}
close(stopProgress)
return err
})

err := uiGrp.Wait()
if err != nil {
err = context.Cause(ctx)
}
app.Jnl.Report()
return err
}
Loading

0 comments on commit 53889ea

Please sign in to comment.