Commit 35482adc authored by Grzegorz Bizon's avatar Grzegorz Bizon Committed by Kamil Trzcinski

Change API for artifacts single file download

parent ceedac04
......@@ -60,8 +60,8 @@ type Response struct {
TempPath string
// Archive is the path where the artifacts archive is stored
Archive string `json:"archive"`
// Path is the filename inside the archive to extracted file
Path string `json:"path"`
// Entry is a filename inside the archive point to file that needs to be extracted
Entry string `json:"entry"`
}
// singleJoiningSlash is taken from reverseproxy.go:NewSingleHostReverseProxy
......
......@@ -2,17 +2,17 @@ package artifacts
import (
"../api"
"../upload"
"net/http"
"../helper"
"errors"
"os"
"../upload"
"archive/zip"
"encoding/base64"
"strconv"
"errors"
"io"
"mime"
"net/http"
"os"
"path/filepath"
"io"
"strconv"
)
func UploadArtifacts(myAPI *api.API, h http.Handler) http.Handler {
......@@ -29,12 +29,12 @@ func UploadArtifacts(myAPI *api.API, h http.Handler) http.Handler {
// Artifacts downloader doesn't support ranges when downloading a single file
func DownloadArtifact(myAPI *api.API) http.Handler {
return myAPI.PreAuthorizeHandler(func(w http.ResponseWriter, r *http.Request, a *api.Response) {
if a.Archive == "" || a.Path == "" {
if a.Archive == "" || a.Entry == "" {
helper.Fail500(w, errors.New("DownloadArtifact: Archive or Path is empty"))
return
}
fileNameDecoded, err := base64.StdEncoding.DecodeString(a.Path)
fileNameDecoded, err := base64.StdEncoding.DecodeString(a.Entry)
if err != nil {
helper.Fail500(w, err)
return
......@@ -70,7 +70,7 @@ func DownloadArtifact(myAPI *api.API) http.Handler {
w.Header().Set("Content-Length", strconv.FormatInt(int64(file.UncompressedSize64), 10))
w.Header().Set("Content-Type", contentType)
w.Header().Set("Content-Disposition", "attachment; filename=" + filepath.Base(file.Name))
w.Header().Set("Content-Disposition", "attachment; filename="+filepath.Base(file.Name))
reader, err := file.Open()
if err != nil {
......
......@@ -65,7 +65,7 @@ func (u *Upstream) configureRoutes() {
route{"GET", regexp.MustCompile(projectsAPIPattern + `repository/archive.tar.bz2\z`), git.GetArchive(api)},
// CI Artifacts
route{"GET", regexp.MustCompile(projectPattern + `builds/[0-9]+/file/`), contentEncodingHandler(artifacts.DownloadArtifact(api))},
route{"GET", regexp.MustCompile(projectPattern + `builds/[0-9]+/artifacts/file/`), contentEncodingHandler(artifacts.DownloadArtifact(api))},
route{"POST", regexp.MustCompile(ciAPIPattern + `v1/builds/[0-9]+/artifacts\z`), contentEncodingHandler(artifacts.UploadArtifacts(api, proxy))},
// Explicitly proxy API requests
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment