Skip to content

Commit 7db028e

Browse files
gorgonzola5000starfruit6000
andauthored
feat(wrtagweb): support optional parameter confirm in /op/{operation} (#192)
* make endpoint /op/{operation} accept optional parameter confirm * update readme --------- Co-authored-by: starfruit6000 <starfruit6000@tuta.com>
1 parent a987111 commit 7db028e

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,46 @@ flowchart LR
167167

168168
### API
169169

170-
Jobs are added to the queue with an HTTP request like `POST <wrtag.host>/op/<copy|move|reflink>` with form value `path=<absolute path to directory>`. Optional form value `mbid=<musicbrainz release URL>` can be supplied if you know your release. Both of the form values can be `application/x-www-form-urlencoded` form bodies, or URL query parameters.
170+
Jobs are added to the queue with an HTTP request like `POST <wrtag.host>/op/<copy|move|reflink>` with form value `path=<absolute path to directory>`. Optional form value `mbid=<musicbrainz release URL>` can be supplied if you know your release as well as `confirm` if you really know your release. All of the form values can be sent in the HTML form body along with the `Content-Type` set to `application/x-www-form-urlencoded`, or as URL query parameters.
171171

172172
The external API requires HTTP Basic authentication with `-web-api-key` as the password (no username). The web UI authentication is controlled by `-web-auth`: either `disabled`, or `basic-auth-from-api-key` (the default) which uses the same API key.
173173

174174
> [!WARNING]
175175
> HTTP Basic Authentication is only as secure as the transport layer it runs on. Make sure `wrtagweb` is secured using TLS behind your reverse proxy.
176176
177177
<details>
178-
<summary><b>Example with <i>cURL</i></b></summary>
178+
<summary><b>Examples with <i>cURL</i></b></summary>
179179

180-
```console
180+
```bash
181+
# Copy release from path, attempt to match and tag.
182+
# Requires manual confirmation through the web UI if the match score is insufficient.
183+
curl \
184+
--request POST \
185+
--data-urlencode "path=/path/to/the/release" \
186+
"https://:my-api-key@wrtag.hostname/op/copy"
187+
188+
# Reflink release from path to the destination directory, find the best match, and tag it.
189+
# Bypasses the match score check.
190+
curl \
191+
--request POST \
192+
--data-urlencode "path=/path/to/the/release" \
193+
--data-urlencode "confirm=true" \
194+
"https://:my-api-key@wrtag.hostname/op/reflink"
195+
196+
# Move release from path using a specific MBID.
197+
# Requires manual confirmation if the file match score is insufficient.
198+
curl \
199+
--request POST \
200+
--data-urlencode "path=/path/to/the/release" \
201+
--data-urlencode "mbid=https://musicbrainz.org/release/d800f372-9673-4edf-8046-8baf79134257" \
202+
"https://:my-api-key@wrtag.hostname/op/move"
203+
204+
# Copy release from path and force-tag with the supplied MBID.
181205
curl \
182206
--request POST \
183207
--data-urlencode "path=/path/to/the/release" \
208+
--data-urlencode "mbid=https://musicbrainz.org/release/d800f372-9673-4edf-8046-8baf79134257" \
209+
--data-urlencode "confirm=true" \
184210
"https://:my-api-key@wrtag.hostname/op/copy"
185211
```
186212

cmd/wrtagweb/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,12 @@ func main() {
330330
if strings.Contains(useMBID, "/") {
331331
useMBID = path.Base(useMBID) // accept release URL
332332
}
333+
confirm, _ := strconv.ParseBool(r.FormValue("confirm"))
333334

334335
ctx := r.Context()
335336

336337
var job Job
337-
if err := sqlb.ScanRow(ctx, db, &job, "insert into jobs (source_path, operation, use_mbid, time) values (?, ?, ?, ?) returning *", pth, operationStr, useMBID, time.Now()); err != nil {
338+
if err := sqlb.ScanRow(ctx, db, &job, "insert into jobs (source_path, operation, use_mbid, confirm, time) values (?, ?, ?, ?, ?) returning *", pth, operationStr, useMBID, confirm, time.Now()); err != nil {
338339
http.Error(w, fmt.Sprintf("error saving job: %v", err), http.StatusInternalServerError)
339340
return
340341
}

0 commit comments

Comments
 (0)