1
0
Fork 0
mirror of https://github.com/Luzifer/tex-api.git synced 2024-11-09 08:40:02 +00:00

Add URL reporting parameter

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-09-06 22:35:07 +02:00
parent 9c91061cf1
commit ab63204ee8
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5
2 changed files with 23 additions and 0 deletions

View file

@ -71,3 +71,13 @@ GET /job/{uuid}/download Download the resulting archive (You may specify an
``` ```
All routes accept the `log-on-error` parameter: If set a PDF download (`Accept` header set to `application/pdf`) will return the log instead of the PDF if no PDF is found. All routes accept the `log-on-error` parameter: If set a PDF download (`Accept` header set to `application/pdf`) will return the log instead of the PDF if no PDF is found.
Providing `report-urls` parameter to the `POST /jobs` endpoint will not redirect to the wait endpoint but report a JSON object containing the URL paths:
```json
{
"download": "/job/fb5ee7b8-679a-4bf2-951b-acabaf43b43e/download",
"status": "/job/fb5ee7b8-679a-4bf2-951b-acabaf43b43e",
"wait": "/job/fb5ee7b8-679a-4bf2-951b-acabaf43b43e/wait"
}
```

View file

@ -3,6 +3,7 @@ package main
import ( import (
"archive/zip" "archive/zip"
"bytes" "bytes"
"encoding/json"
"io" "io"
"math" "math"
"net/http" "net/http"
@ -133,6 +134,18 @@ func startNewJob(res http.ResponseWriter, r *http.Request) {
u := urlMust(router.Get("waitForJob").URL("uid", jobUUID.String())) u := urlMust(router.Get("waitForJob").URL("uid", jobUUID.String()))
u.RawQuery = r.URL.Query().Encode() u.RawQuery = r.URL.Query().Encode()
if r.URL.Query().Has("report-urls") {
if err := json.NewEncoder(res).Encode(map[string]string{
"download": urlMust(router.Get("downloadAssets").URL("uid", jobUUID.String())).String(),
"status": urlMust(router.Get("getJobStatus").URL("uid", jobUUID.String())).String(),
"wait": urlMust(router.Get("waitForJob").URL("uid", jobUUID.String())).String(),
}); err != nil {
serverErrorf(res, err, "encoding url response")
}
return
}
http.Redirect(res, r, u.String(), http.StatusFound) http.Redirect(res, r, u.String(), http.StatusFound)
} }