Skip to content

Commit 2bb0b60

Browse files
gorgonzola5000starfruit6000sentriz
authored
feat(wrtagweb): support optional parameter mbid in /op/{operation} (#191)
* make endpoint /op/{operation} accept optional parameter mbid * Update README.md --------- Co-authored-by: starfruit6000 <starfruit6000@tuta.com> Co-authored-by: Senan Kelly <senan@senan.xyz>
1 parent ae2741e commit 2bb0b60

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ flowchart LR
167167

168168
### API
169169

170-
Jobs are added to the queue with an HTTP request like `POST <wrtag.host>/op/<copy|move>` with form value `path=<absolute path to directory>`. The form value can be an `application/x-www-form-urlencoded` form body, or URL query parameter.
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.
171171

172172
Authentication is done via a HTTP Basic authentication password **without a username**. The password is configured with the `web-api-key` config option.
173173

cmd/wrtagweb/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,15 @@ func main() {
308308
return
309309
}
310310
path = filepath.Clean(path)
311+
useMBID := r.FormValue("mbid")
312+
if strings.Contains(useMBID, "/") {
313+
useMBID = filepath.Base(useMBID) // accept release URL
314+
}
311315

312316
ctx := r.Context()
313317

314318
var job Job
315-
if err := sqlb.ScanRow(ctx, db, &job, "insert into jobs (source_path, operation, time) values (?, ?, ?) returning *", path, operationStr, time.Now()); err != nil {
319+
if err := sqlb.ScanRow(ctx, db, &job, "insert into jobs (source_path, operation, use_mbid, time) values (?, ?, ?, ?) returning *", path, operationStr, useMBID, time.Now()); err != nil {
316320
http.Error(w, fmt.Sprintf("error saving job: %v", err), http.StatusInternalServerError)
317321
return
318322
}

0 commit comments

Comments
 (0)