Fix noms de fichiers avec symboles spéciaux #71
2 changed files with 33 additions and 27 deletions
18
api/api.go
18
api/api.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"git.agecem.com/agecem/agecem-org/config"
|
"git.agecem.com/agecem/agecem-org/config"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -77,7 +78,11 @@ func (a *API) Call(method, route string) ([]byte, error) {
|
||||||
a.Host,
|
a.Host,
|
||||||
a.Port,
|
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 {
|
switch method {
|
||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
|
@ -148,7 +153,7 @@ func (a *API) UploadDocument(bucket string, file_header *multipart.FileHeader) (
|
||||||
a.Port,
|
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
|
// Create a new multipart writer
|
||||||
body := &bytes.Buffer{}
|
body := &bytes.Buffer{}
|
||||||
|
@ -161,7 +166,12 @@ func (a *API) UploadDocument(bucket string, file_header *multipart.FileHeader) (
|
||||||
}
|
}
|
||||||
defer file.Close()
|
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 {
|
if err != nil {
|
||||||
return UploadDocumentResponse{}, fmt.Errorf("UploadDocument#writer.CreateFormFile: %s", err)
|
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
|
// 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 {
|
if err != nil {
|
||||||
return UploadDocumentResponse{}, fmt.Errorf("UploadDocument#http.NewRequest: %s", err)
|
return UploadDocumentResponse{}, fmt.Errorf("UploadDocument#http.NewRequest: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"regexp"
|
|
||||||
|
|
||||||
"embed"
|
"embed"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
@ -417,14 +416,16 @@ func handleV1DocumentCreate(c echo.Context) error {
|
||||||
}
|
}
|
||||||
defer src.Close()
|
defer src.Close()
|
||||||
|
|
||||||
|
/*
|
||||||
reg, err := regexp.Compile("[^.a-zA-Z0-9_-]+")
|
reg, err := regexp.Compile("[^.a-zA-Z0-9_-]+")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Render(http.StatusInternalServerError, "documentation-html", nil)
|
return c.Render(http.StatusInternalServerError, "documentation-html", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
filename_processed := reg.ReplaceAllString(form_file.Filename, "")
|
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"),
|
ContentType: form_file.Header.Get("Content-Type"),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -456,11 +457,6 @@ func handleV1DocumentRead(c echo.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !allowed {
|
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"})
|
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, "")
|
document_processed := reg.ReplaceAllString(document, "")
|
||||||
documents_processed = append(documents_processed, document_processed)
|
documents_processed = append(documents_processed, document_processed)
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
documents_processed := documents
|
documents_processed := documents
|
||||||
|
*/
|
||||||
|
|
||||||
data = append(data, Bucket{
|
data = append(data, Bucket{
|
||||||
Name: bucket,
|
Name: bucket,
|
||||||
Documents: documents_processed,
|
Documents: documents,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue