Skip to content

Commit

Permalink
Fix #52: Duplicate command fails with 504 timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
simulot committed Nov 2, 2023
1 parent 2b695ff commit 59f9630
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 19 deletions.
8 changes: 7 additions & 1 deletion docs/releases.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Release notes

## Release next
## Release 0.7.0

### Fix #52: Duplicate command fails with 504 timeout
A new option enable the possibility of calling directly the immich-server once it's port is published.

`-api URL` URL of the Immich api endpoint (http://container_ip:3301)<br>


### Fix #50: Duplicate detection fails when timezone of both images differs
Imported duplicated images with same name, but different timezone wasn't seen as duplicates.
Expand Down
3 changes: 2 additions & 1 deletion immich/call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ func TestCall(t *testing.T) {
server := httptest.NewServer(&tst.server)
defer server.Close()
ctx := context.Background()
ic, err := NewImmichClient(server.URL, "1234", "tester", true)
ic, err := NewImmichClient(server.URL, "1234")
if err != nil {
t.Fail()
return
}
ic.EnableAppTrace(true)
r := map[string]string{}
err = ic.newServerCall(ctx, tst.name).do(tst.requestFn, responseJSON(&r))
if tst.expectedErr && err == nil {
Expand Down
25 changes: 23 additions & 2 deletions immich/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"os"
"time"
)

Expand All @@ -23,16 +24,36 @@ type ImmichClient struct {
ApiTrace bool
}

func (ic *ImmichClient) SetEndPoint(endPoint string) *ImmichClient {
ic.endPoint = endPoint
return ic
}

func (ic *ImmichClient) SetDeviceUUID(deviceUUID string) *ImmichClient {
ic.DeviceUUID = deviceUUID
return ic
}

func (ic *ImmichClient) EnableAppTrace(state bool) *ImmichClient {
ic.ApiTrace = state
return ic
}

// Create a new ImmichClient
func NewImmichClient(endPoint, key, deviceUUID string, apiTrace bool) (*ImmichClient, error) {
func NewImmichClient(endPoint string, key string) (*ImmichClient, error) {
var err error
deviceUUID, err := os.Hostname()
if err != nil {
return nil, err
}

ic := ImmichClient{
endPoint: endPoint + "/api",
key: key,
client: &http.Client{},
DeviceUUID: deviceUUID,
Retries: 1,
RetriesDelay: time.Second * 1,
ApiTrace: apiTrace,
}
return &ic, nil
}
Expand Down
43 changes: 28 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,18 @@ func main() {
}

type Application struct {
EndPoint string // Immich server address (http://<your-ip>:2283/api or https://<your-domain>/api)
Key string // API Key
DeviceUUID string // Set a device UUID
Immich *immich.ImmichClient // Immich client
Logger *logger.Logger // Program's logger
ApiTrace bool

NoLogColors bool // Disable log colors
LogLevel string
Debug bool
Server string // Immich server address (http://<your-ip>:2283/api or https://<your-domain>/api)
API string // Immich api endpoint (http://container_ip:3301)
Key string // API Key
DeviceUUID string // Set a device UUID
ApiTrace bool // Enable API call traces
NoLogColors bool // Disable log colors
LogLevel string // Idicate the log level
Debug bool // Enable the debug mode

Immich *immich.ImmichClient // Immich client
Logger *logger.Logger // Program's logger

}

func Run(ctx context.Context, log *logger.Logger) (*logger.Logger, error) {
Expand All @@ -72,16 +74,21 @@ func Run(ctx context.Context, log *logger.Logger) (*logger.Logger, error) {
}

app := Application{}
flag.StringVar(&app.EndPoint, "server", "", "Immich server address (http://<your-ip>:2283 or https://<your-domain>)")
flag.StringVar(&app.Server, "server", "", "Immich server address (http://<your-ip>:2283 or https://<your-domain>)")
flag.StringVar(&app.API, "api", "", "Immich api endpoint (http://container_ip:3301)")
flag.StringVar(&app.Key, "key", "", "API Key")
flag.StringVar(&app.DeviceUUID, "device-uuid", deviceID, "Set a device UUID")
flag.BoolVar(&app.NoLogColors, "no-colors-log", false, "Disable colors on logs")
flag.StringVar(&app.LogLevel, "log-level", "ok", "Log level (Error|Warning|OK|Info), default OK")
flag.BoolVar(&app.ApiTrace, "api-trace", false, "enable api call traces")
flag.BoolVar(&app.Debug, "debug", false, "enable debug messages")
flag.Parse()
if len(app.EndPoint) == 0 {
err = errors.Join(err, errors.New("missing -server"))

switch {
case len(app.Server) == 0 && len(app.API) == 0:
err = errors.Join(err, errors.New("missing -server, Immich server address (http://<your-ip>:2283 or https://<your-domain>)"))
case len(app.Server) > 0 && len(app.API) > 0:
err = errors.Join(err, errors.New("give either the -server or the -api option"))
}
if len(app.Key) == 0 {
err = errors.Join(err, errors.New("missing -key"))
Expand All @@ -93,7 +100,7 @@ func Run(ctx context.Context, log *logger.Logger) (*logger.Logger, error) {
}

if len(flag.Args()) == 0 {
err = errors.Join(err, errors.New("missing command"))
err = errors.Join(err, errors.New("missing command upload|duplicate|stack"))
}

app.Logger = logger.NewLogger(logLevel, app.NoLogColors, app.Debug)
Expand All @@ -102,10 +109,16 @@ func Run(ctx context.Context, log *logger.Logger) (*logger.Logger, error) {
return app.Logger, err
}

app.Immich, err = immich.NewImmichClient(app.EndPoint, app.Key, app.DeviceUUID, app.ApiTrace)
app.Immich, err = immich.NewImmichClient(app.Server, app.Key)
if err != nil {
return app.Logger, err
}
if app.API != "" {
app.Immich.SetEndPoint(app.API)
}
if app.ApiTrace {
app.Immich.EnableAppTrace(true)
}

err = app.Immich.PingServer(ctx)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ immich-go -server URL -key KEY -general_options COMMAND -command_options... {fil
```

`-server URL` URL of the Immich service, example http://<your-ip>:2283 or https://your-domain<br>
`-api URL` URL of the Immich api endpoint (http://container_ip:3301)<br>

`-key KEY` A key generated by the user. Uploaded photos will belong to the key's owner.<br>
`-no-colors-log` Remove color codes from logs.<br>
`-log-level` Adjust the log verbosity as follow: (Default OK)
Expand Down

0 comments on commit 59f9630

Please sign in to comment.