forked from TrueCloudLab/frostfs-http-gw
[#147] Download zip by FilePath attribute
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
48ce84e65f
commit
1c2fec8182
2 changed files with 10 additions and 6 deletions
|
@ -36,6 +36,8 @@ type request struct {
|
||||||
|
|
||||||
var errObjectNotFound = errors.New("object not found")
|
var errObjectNotFound = errors.New("object not found")
|
||||||
|
|
||||||
|
const attributeFilePath = "FilePath"
|
||||||
|
|
||||||
func isValidToken(s string) bool {
|
func isValidToken(s string) bool {
|
||||||
for _, c := range s {
|
for _, c := range s {
|
||||||
if c <= ' ' || c > 127 {
|
if c <= ' ' || c > 127 {
|
||||||
|
@ -374,7 +376,7 @@ func (d *Downloader) DownloadZipped(c *fasthttp.RequestCtx) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resSearch, err := d.search(c, containerID, object.AttributeFileName, prefix, object.MatchCommonPrefix)
|
resSearch, err := d.search(c, containerID, attributeFilePath, prefix, object.MatchCommonPrefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("could not search for objects", zap.Error(err))
|
log.Error("could not search for objects", zap.Error(err))
|
||||||
response.Error(c, "could not search for objects", fasthttp.StatusBadRequest)
|
response.Error(c, "could not search for objects", fasthttp.StatusBadRequest)
|
||||||
|
@ -428,7 +430,7 @@ func (d *Downloader) DownloadZipped(c *fasthttp.RequestCtx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
w, err = zipWriter.CreateHeader(&zip.FileHeader{
|
w, err = zipWriter.CreateHeader(&zip.FileHeader{
|
||||||
Name: getFilename(&resGet.Header),
|
Name: getZipFilePath(&resGet.Header),
|
||||||
Method: compression,
|
Method: compression,
|
||||||
Modified: time.Now(),
|
Modified: time.Now(),
|
||||||
})
|
})
|
||||||
|
@ -474,9 +476,9 @@ func (d *Downloader) DownloadZipped(c *fasthttp.RequestCtx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFilename(obj *object.Object) string {
|
func getZipFilePath(obj *object.Object) string {
|
||||||
for _, attr := range obj.Attributes() {
|
for _, attr := range obj.Attributes() {
|
||||||
if attr.Key() == object.AttributeFileName {
|
if attr.Key() == attributeFilePath {
|
||||||
return attr.Value()
|
return attr.Value()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@ import (
|
||||||
"github.com/testcontainers/testcontainers-go/wait"
|
"github.com/testcontainers/testcontainers-go/wait"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const attributeFilePath = "FilePath"
|
||||||
|
|
||||||
type putResponse struct {
|
type putResponse struct {
|
||||||
CID string `json:"container_id"`
|
CID string `json:"container_id"`
|
||||||
OID string `json:"object_id"`
|
OID string `json:"object_id"`
|
||||||
|
@ -191,8 +193,8 @@ func getByAttr(ctx context.Context, t *testing.T, clientPool *pool.Pool, CID *ci
|
||||||
func getZip(ctx context.Context, t *testing.T, clientPool *pool.Pool, CID *cid.ID) {
|
func getZip(ctx context.Context, t *testing.T, clientPool *pool.Pool, CID *cid.ID) {
|
||||||
names := []string{"zipfolder/dir/name1.txt", "zipfolder/name2.txt"}
|
names := []string{"zipfolder/dir/name1.txt", "zipfolder/name2.txt"}
|
||||||
contents := []string{"content of file1", "content of file2"}
|
contents := []string{"content of file1", "content of file2"}
|
||||||
attributes1 := map[string]string{object.AttributeFileName: names[0]}
|
attributes1 := map[string]string{attributeFilePath: names[0]}
|
||||||
attributes2 := map[string]string{object.AttributeFileName: names[1]}
|
attributes2 := map[string]string{attributeFilePath: names[1]}
|
||||||
|
|
||||||
putObject(ctx, t, clientPool, CID, contents[0], attributes1)
|
putObject(ctx, t, clientPool, CID, contents[0], attributes1)
|
||||||
putObject(ctx, t, clientPool, CID, contents[1], attributes2)
|
putObject(ctx, t, clientPool, CID, contents[1], attributes2)
|
||||||
|
|
Loading…
Reference in a new issue