Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove "GetJobs" call from API traces #442

Merged
merged 2 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions immich/albums.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type AlbumSimplified struct {

func (ic *ImmichClient) GetAllAlbums(ctx context.Context) ([]AlbumSimplified, error) {
var albums []AlbumSimplified
err := ic.newServerCall(ctx, "GetAllAlbums").do(getRequest("/albums", setAcceptJSON()), responseJSON(&albums))
err := ic.newServerCall(ctx, EndPointGetAllAlbums).do(getRequest("/albums", setAcceptJSON()), responseJSON(&albums))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -77,13 +77,13 @@ func (ic *ImmichClient) GetAlbumInfo(ctx context.Context, id string, withoutAsse
if withoutAssets {
query += "?withoutAssets=true"
}
err := ic.newServerCall(ctx, "GetAlbumInfo").do(getRequest("/albums/"+query, setAcceptJSON()), responseJSON(&album))
err := ic.newServerCall(ctx, EndPointGetAlbumInfo).do(getRequest("/albums/"+query, setAcceptJSON()), responseJSON(&album))
return album, err
}

func (ic *ImmichClient) GetAssetsAlbums(ctx context.Context, id string) ([]AlbumSimplified, error) {
var albums []AlbumSimplified
err := ic.newServerCall(ctx, "GetAllAlbums").do(getRequest("/albums", setAcceptJSON()), responseJSON(&albums))
err := ic.newServerCall(ctx, EndPointGetAlbumInfo).do(getRequest("/albums", setAcceptJSON()), responseJSON(&albums))
if err != nil {
return nil, err
}
Expand All @@ -105,7 +105,7 @@ func (ic *ImmichClient) AddAssetToAlbum(ctx context.Context, albumID string, ass
body := UpdateAlbum{
IDS: assets,
}
err := ic.newServerCall(ctx, "AddAssetToAlbum").do(
err := ic.newServerCall(ctx, EndPointAddAsstToAlbum).do(
putRequest(fmt.Sprintf("/albums/%s/assets", albumID), setAcceptJSON(),
setJSONBody(body)),
responseJSON(&r))
Expand All @@ -122,7 +122,7 @@ func (ic *ImmichClient) CreateAlbum(ctx context.Context, name string, descriptio
AssetIDs: assetsIDs,
}
var r AlbumSimplified
err := ic.newServerCall(ctx, "CreateAlbum").do(
err := ic.newServerCall(ctx, EndPointCreateAlbum).do(
postRequest("/albums", "application/json", setAcceptJSON(), setJSONBody(body)),
responseJSON(&r))
if err != nil {
Expand All @@ -133,12 +133,12 @@ func (ic *ImmichClient) CreateAlbum(ctx context.Context, name string, descriptio

func (ic *ImmichClient) GetAssetAlbums(ctx context.Context, id string) ([]AlbumSimplified, error) {
var r []AlbumSimplified
err := ic.newServerCall(ctx, "GetAssetAlbums").do(
err := ic.newServerCall(ctx, EndPointGetAssetAlbums).do(
getRequest("/albums?assetId="+id, setAcceptJSON()),
responseJSON(&r))
return r, err
}

func (ic *ImmichClient) DeleteAlbum(ctx context.Context, id string) error {
return ic.newServerCall(ctx, "DeleteAlbum").do(deleteRequest("/albums/" + id))
return ic.newServerCall(ctx, EndPointDeleteAlbum).do(deleteRequest("/albums/" + id))
}
24 changes: 20 additions & 4 deletions immich/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ import (
"github.com/simulot/immich-go/helpers/fshelper"
)

const (
EndPointGetJobs = "GetJobs"
EndPointGetAllAlbums = "GetAllAlbums"
EndPointGetAlbumInfo = "GetAlbumInfo"
EndPointAddAsstToAlbum = "AddAssetToAlbum"
EndPointCreateAlbum = "CreateAlbum"
EndPointGetAssetAlbums = "GetAssetAlbums"
EndPointDeleteAlbum = "DeleteAlbum"
EndPointPingServer = "PingServer"
EndPointValidateConnection = "ValidateConnection"
EndPointGetServerStatistics = "GetServerStatistics"
EndPointGetAssetStatistics = "GetAssetStatistics"
EndPointGetSupportedMediaTypes = "GetSupportedMediaTypes"
EndPointGetAllAssets = "GetAllAssets"
)

type TooManyInternalError struct {
error
}
Expand Down Expand Up @@ -121,7 +137,7 @@ var callSequence atomic.Int64
const ctxCallSequenceID = "api-call-sequence"

func (sc *serverCall) request(method string, url string, opts ...serverRequestOption) *http.Request {
if sc.ic.apiTraceWriter != nil {
if sc.ic.apiTraceWriter != nil && sc.endPoint != EndPointGetJobs {
seq := callSequence.Add(1)
sc.ctx = context.WithValue(sc.ctx, ctxCallSequenceID, seq)
}
Expand Down Expand Up @@ -185,7 +201,7 @@ func (sc *serverCall) do(fnRequest requestFunction, opts ...serverResponseOption
return sc.Err(req, nil, nil)
}

if sc.ic.apiTraceWriter != nil /* && req.Header.Get("Content-Type") == "application/json"*/ {
if sc.ic.apiTraceWriter != nil && sc.endPoint != EndPointGetJobs {
_ = sc.joinError(setTraceRequest()(sc, req))
}

Expand Down Expand Up @@ -247,7 +263,7 @@ func setJSONBody(object any) serverRequestOption {
return func(sc *serverCall, req *http.Request) error {
b := bytes.NewBuffer(nil)
enc := json.NewEncoder(b)
if sc.ic.apiTraceWriter != nil {
if sc.ic.apiTraceWriter != nil && sc.endPoint != EndPointGetJobs {
enc.SetIndent("", " ")
}
err := enc.Encode(object)
Expand Down Expand Up @@ -278,7 +294,7 @@ func responseJSON[T any](object *T) serverResponseOption {
return nil
}
err := json.NewDecoder(resp.Body).Decode(object)
if sc.ic.apiTraceWriter != nil {
if sc.ic.apiTraceWriter != nil && sc.endPoint != EndPointGetJobs {
seq := sc.ctx.Value(ctxCallSequenceID)
fmt.Fprintln(sc.ic.apiTraceWriter, time.Now().Format(time.RFC3339), "RESPONSE", seq, sc.endPoint, resp.Request.Method, resp.Request.URL.String())
fmt.Fprintln(sc.ic.apiTraceWriter, " Status:", resp.Status)
Expand Down
10 changes: 5 additions & 5 deletions immich/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func NewImmichClient(endPoint string, key string, options ...clientOption) (*Imm
func (ic *ImmichClient) PingServer(ctx context.Context) error {
r := PingResponse{}
b := bytes.NewBuffer(nil)
err := ic.newServerCall(ctx, "PingServer").do(getRequest("/server-info/ping", setAcceptJSON()), responseCopy(b), responseJSON(&r))
err := ic.newServerCall(ctx, EndPointPingServer).do(getRequest("/server-info/ping", setAcceptJSON()), responseCopy(b), responseJSON(&r))
if err != nil {
return fmt.Errorf("unexpected response to the immich's ping API at this address: %s:\n%s", ic.endPoint+"/server-info/ping", b.String())
}
Expand All @@ -129,7 +129,7 @@ func (ic *ImmichClient) PingServer(ctx context.Context) error {
func (ic *ImmichClient) ValidateConnection(ctx context.Context) (User, error) {
var user User

err := ic.newServerCall(ctx, "ValidateConnection").
err := ic.newServerCall(ctx, EndPointValidateConnection).
do(getRequest("/users/me", setAcceptJSON()), responseJSON(&user))
if err != nil {
return user, err
Expand Down Expand Up @@ -163,7 +163,7 @@ type ServerStatistics struct {
func (ic *ImmichClient) GetServerStatistics(ctx context.Context) (ServerStatistics, error) {
var s ServerStatistics

err := ic.newServerCall(ctx, "GetServerStatistics").do(getRequest("/server-info/statistics", setAcceptJSON()), responseJSON(&s))
err := ic.newServerCall(ctx, EndPointGetServerStatistics).do(getRequest("/server-info/statistics", setAcceptJSON()), responseJSON(&s))
return s, err
}

Expand All @@ -178,7 +178,7 @@ type UserStatistics struct {

func (ic *ImmichClient) GetAssetStatistics(ctx context.Context) (UserStatistics, error) {
var s UserStatistics
err := ic.newServerCall(ctx, "GetAssetStatistics").do(getRequest("/assets/statistics", setAcceptJSON()), responseJSON(&s))
err := ic.newServerCall(ctx, EndPointGetAssetStatistics).do(getRequest("/assets/statistics", setAcceptJSON()), responseJSON(&s))
return s, err
}

Expand All @@ -204,7 +204,7 @@ var DefaultSupportedMedia = SupportedMedia{
func (ic *ImmichClient) GetSupportedMediaTypes(ctx context.Context) (SupportedMedia, error) {
var s map[string][]string

err := ic.newServerCall(ctx, "GetSupportedMediaTypes").do(getRequest("/server-info/media-types", setAcceptJSON()), responseJSON(&s))
err := ic.newServerCall(ctx, EndPointGetSupportedMediaTypes).do(getRequest("/server-info/media-types", setAcceptJSON()), responseJSON(&s))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion immich/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ type Job struct {

func (ic *ImmichClient) GetJobs(ctx context.Context) (map[string]Job, error) {
var resp map[string]Job
err := ic.newServerCall(ctx, "GetJobs").do(getRequest("/jobs", setAcceptJSON()), responseJSON(&resp))
err := ic.newServerCall(ctx, EndPointGetJobs).do(getRequest("/jobs", setAcceptJSON()), responseJSON(&resp))
return resp, err
}
2 changes: 1 addition & 1 deletion immich/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (ic *ImmichClient) callSearchMetadata(ctx context.Context, req *searchMetad
return ctx.Err()
default:
resp := searchMetadataResponse{}
err := ic.newServerCall(ctx, "GetAllAssets").do(postRequest("/search/metadata", "application/json", setJSONBody(&req), setAcceptJSON()), responseJSON(&resp))
err := ic.newServerCall(ctx, EndPointGetAllAssets).do(postRequest("/search/metadata", "application/json", setJSONBody(&req), setAcceptJSON()), responseJSON(&resp))
if err != nil {
return err
}
Expand Down