Skip to content

Conversation

@DrissiReda
Copy link

The goal of this PR is to let the user add a list of tags to every uploaded assets.
This is quite useful since it is a pain to set up a separate logic to bulk tag assets for multiple reasons:

  • You cannot search for untagged assets using immich API.
  • Returned list from /search/metadata contains assetIDs but not tags, not even whether it has tags or not like hasMetadata.
  • If we add one request per assetID to check whether the media has the proper tag or not means 1 additional request per asset for the whole library every time we want to update this.

Let me know what you think about this.

If needed I can add the possibility to use tag names instead of IDs and make sure they exist before tagging assets.

README.md Outdated
- `-checksums_file`: Path to the checksums file (default: `checksums.csv`)
- `-download_jpg_from_jxl`: Converts JXL images to JPG on download for compatibility (default: `false`)
- `-download_jpg_from_avif`: Converts AVIF images to JPG on download for compatibility (default: `false`)
- `-tag-ids`: Comma-separated list of tag IDs to add to every asset (default: `""`)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong

req.Header.Set("Content-Type", multipartWriter.FormDataContentType())
// Send the request to the upstream server
resp, err := getHTTPclient().Do(req)
defer resp.Body.Close()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why move this defer? can return without closing body on error

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I thought it better to check for errors before deferring.

return fmt.Errorf("no asset ID found in upstream response")
}
// Tag the asset
if len(tagIDs) > 0 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be checked before

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you suggest? Either way a check has to be put here to see whether this request is needed or not since it should be optional for users to add tags or not.

jobs.go Outdated

// Create tag request
tagURL := fmt.Sprintf("%s/api/tags/assets", upstreamURL)
tagReq, err := http.NewRequestWithContext(ctx, "PUT", tagURL, bytes.NewReader(tagBodyBytes))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why with context?

main.go Outdated

// goreleaser auto updated vars
var version = "dev"
var version = "v0.8.1"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must not modify

main.go Outdated
} else {
log.Printf("no tmp directory set, uploaded files will be saved on disk multiple times, this can shorten your disk lifespan !")
}
// Process tags
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to init

}

// getTagIDs parses tagIDsStr into a list of tag IDs
func getTagIDs() ([]string, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just enforce a strict formatting, user error if they put spaces

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, kept a check to make it easier to debug.

main.go Outdated
flag.StringVar(&checksumsFile, "checksums_file", viper.GetString("checksums_file"), "Path to the checksums file")
flag.BoolVar(&downloadJpgFromJxl, "download_jpg_from_jxl", viper.GetBool("download_jpg_from_jxl"), "Converts JXL images to JPG on download for wider compatibility")
flag.BoolVar(&downloadJpgFromAvif, "download_jpg_from_avif", viper.GetBool("download_jpg_from_avif"), "Converts AVIF images to JPG on download for wider compatibility")
flag.StringVar(&tagIDsStr, "tag-ids", viper.GetString("tag_ids"), "Comma-separated list of tag IDs")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixing - and _

jobs.go Outdated
tagReq.AddCookie(cookie)
}
// Copy other headers that might be relevant for authentication
if apiKey := originalReq.Header.Get("x-api-key"); apiKey != "" {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is helper functions to copy all headers/cookies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants