mirror of
https://github.com/Luzifer/tex-api.git
synced 2024-11-08 08:10:09 +00:00
Add format
override
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
ab63204ee8
commit
95146f88cb
2 changed files with 28 additions and 7 deletions
|
@ -70,10 +70,11 @@ GET /job/{uuid}/download Download the resulting archive (You may specify an
|
|||
TAR archive or just the raw PDF.)
|
||||
```
|
||||
|
||||
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:
|
||||
Supported query parameters:
|
||||
|
||||
- `format` overrides the `Accept` header detection and choses the output format (`pdf`, `tar`, `zip`) and is accepted on all endpoints
|
||||
- `log-on-error` - If set a PDF download (`Accept` header set to `application/pdf` or `format` is chosen) will return the log instead of the PDF if no PDF is found.
|
||||
- `report-urls` on 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",
|
||||
|
|
28
main.go
28
main.go
|
@ -88,6 +88,23 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func chooseDistribution(r *http.Request) string {
|
||||
if dist := r.URL.Query().Get("format"); dist != "" {
|
||||
return dist
|
||||
}
|
||||
|
||||
switch r.Header.Get("Accept") {
|
||||
case "application/tar", "application/x-tar", "application/x-gtar", "multipart/x-tar", "application/x-compress", "application/x-compressed":
|
||||
return "tar"
|
||||
|
||||
case "application/pdf":
|
||||
return "pdf"
|
||||
|
||||
default:
|
||||
return "zip"
|
||||
}
|
||||
}
|
||||
|
||||
func downloadAssets(res http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
uid, err := uuid.FromString(vars["uid"])
|
||||
|
@ -102,13 +119,13 @@ func downloadAssets(res http.ResponseWriter, r *http.Request) {
|
|||
filename string
|
||||
)
|
||||
|
||||
switch r.Header.Get("Accept") {
|
||||
case "application/tar", "application/x-tar", "application/x-gtar", "multipart/x-tar", "application/x-compress", "application/x-compressed":
|
||||
switch dist := chooseDistribution(r); dist {
|
||||
case "tar":
|
||||
contentType = "application/tar"
|
||||
content, err = buildAssetsTAR(uid)
|
||||
filename = uid.String() + ".tar"
|
||||
|
||||
case "application/pdf":
|
||||
case "pdf":
|
||||
contentType = "application/pdf"
|
||||
filename = uid.String() + ".pdf"
|
||||
content, err = getAssetsFile(uid, ".pdf")
|
||||
|
@ -119,9 +136,12 @@ func downloadAssets(res http.ResponseWriter, r *http.Request) {
|
|||
content, err = getAssetsFile(uid, ".log")
|
||||
}
|
||||
|
||||
default:
|
||||
case "zip":
|
||||
content, err = buildAssetsZIP(uid)
|
||||
filename = uid.String() + ".zip"
|
||||
|
||||
default:
|
||||
err = errors.Errorf("unknown distribution %q", dist)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue