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