Merge pull request 'Fix noms de fichiers avec symboles spéciaux' (#71) from fix/filename-symbols into main

Reviewed-on: #71
This commit is contained in:
Victor Lacasse-Beaudoin 2023-07-14 19:45:19 -05:00
commit 438ef2db24
2 changed files with 33 additions and 27 deletions

View file

@ -9,6 +9,7 @@ import (
"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
"git.agecem.com/agecem/agecem-org/config"
"github.com/spf13/viper"
@ -77,7 +78,11 @@ func (a *API) Call(method, route string) ([]byte, error) {
a.Host,
a.Port,
)
request := fmt.Sprintf("%s%s", endpoint, route)
prerequest := fmt.Sprintf("%s%s", endpoint, route)
request, err := url.QueryUnescape(prerequest)
if err != nil {
return nil, err
}
switch method {
case http.MethodGet:
@ -148,7 +153,7 @@ func (a *API) UploadDocument(bucket string, file_header *multipart.FileHeader) (
a.Port,
)
url := fmt.Sprintf("%s/v1/bucket/%s", endpoint, bucket)
current_url := fmt.Sprintf("%s/v1/bucket/%s", endpoint, bucket)
// Create a new multipart writer
body := &bytes.Buffer{}
@ -161,7 +166,12 @@ func (a *API) UploadDocument(bucket string, file_header *multipart.FileHeader) (
}
defer file.Close()
part, err := writer.CreateFormFile("document", file_header.Filename)
filename_processed, err := url.QueryUnescape(file_header.Filename)
if err != nil {
return UploadDocumentResponse{}, fmt.Errorf("UploadDocument#url.QueryUnescape: %s", err)
}
part, err := writer.CreateFormFile("document", filename_processed)
if err != nil {
return UploadDocumentResponse{}, fmt.Errorf("UploadDocument#writer.CreateFormFile: %s", err)
}
@ -177,7 +187,7 @@ func (a *API) UploadDocument(bucket string, file_header *multipart.FileHeader) (
}
// Create a new HTTP request with the multipart body
req, err := http.NewRequest(http.MethodPost, url, body)
req, err := http.NewRequest(http.MethodPost, current_url, body)
if err != nil {
return UploadDocumentResponse{}, fmt.Errorf("UploadDocument#http.NewRequest: %s", err)
}

View file

@ -9,7 +9,6 @@ import (
"encoding/json"
"fmt"
"log"
"regexp"
"embed"
"html/template"
@ -417,14 +416,16 @@ func handleV1DocumentCreate(c echo.Context) error {
}
defer src.Close()
/*
reg, err := regexp.Compile("[^.a-zA-Z0-9_-]+")
if err != nil {
return c.Render(http.StatusInternalServerError, "documentation-html", nil)
}
filename_processed := reg.ReplaceAllString(form_file.Filename, "")
*/
info, err := mediaClient.MinioClient.PutObject(ctx, bucket, filename_processed, src, form_file.Size, minio.PutObjectOptions{
info, err := mediaClient.MinioClient.PutObject(ctx, bucket, form_file.Filename, src, form_file.Size, minio.PutObjectOptions{
ContentType: form_file.Header.Get("Content-Type"),
})
if err != nil {
@ -456,11 +457,6 @@ func handleV1DocumentRead(c echo.Context) error {
}
if !allowed {
/*
return c.JSON(http.StatusBadRequest, map[string]string{
"message": "Bucket is not allowed in server.documents.buckets",
})
*/
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
}
@ -669,12 +665,12 @@ func handleDocumentation(c echo.Context) error {
document_processed := reg.ReplaceAllString(document, "")
documents_processed = append(documents_processed, document_processed)
}
*/
documents_processed := documents
*/
data = append(data, Bucket{
Name: bucket,
Documents: documents_processed,
Documents: documents,
})
}