Fix affichage de réponse à création et /documentation
Retirer caractères spéciaux lors de l'import
This commit is contained in:
parent
5d984ccacb
commit
3dd4dd6e29
2 changed files with 52 additions and 29 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
|
||||
"embed"
|
||||
"html/template"
|
||||
|
@ -388,7 +389,6 @@ func handleV1DocumentCreate(c echo.Context) error {
|
|||
|
||||
form_file, err := c.FormFile("document")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return c.JSON(http.StatusBadRequest, map[string]interface{}{
|
||||
"message": "Error during handleV1DocumentCreate's echo#Context.FormFile",
|
||||
"error": err,
|
||||
|
@ -403,11 +403,6 @@ func handleV1DocumentCreate(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"})
|
||||
}
|
||||
|
||||
|
@ -432,7 +427,14 @@ func handleV1DocumentCreate(c echo.Context) error {
|
|||
}
|
||||
defer src.Close()
|
||||
|
||||
info, err := client.PutObject(ctx, bucket, form_file.Filename, src, form_file.Size, minio.PutObjectOptions{
|
||||
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 := client.PutObject(ctx, bucket, filename_processed, src, form_file.Size, minio.PutObjectOptions{
|
||||
ContentType: form_file.Header.Get("Content-Type"),
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -671,21 +673,39 @@ func handleDocumentation(c echo.Context) error {
|
|||
var data []Bucket
|
||||
|
||||
for _, bucket := range buckets {
|
||||
result, err := client.Call(http.MethodGet, fmt.Sprintf("/v1/bucket/%s", bucket))
|
||||
content, err := client.Call(http.MethodGet, fmt.Sprintf("/v1/bucket/%s", bucket))
|
||||
if err != nil {
|
||||
return c.Render(http.StatusInternalServerError, "documentation-html", nil)
|
||||
}
|
||||
|
||||
var documents []string
|
||||
|
||||
err = json.Unmarshal(result, &documents)
|
||||
err = json.Unmarshal(content, &documents)
|
||||
if err != nil {
|
||||
return c.Render(http.StatusInternalServerError, "documentation-html", nil)
|
||||
}
|
||||
|
||||
// Ce bloc retire tous les caractères spéciaux d'une string
|
||||
// N'est pas présentement activé, car les fichiers sont processed
|
||||
// à la création de toute façon.
|
||||
/*
|
||||
reg, err := regexp.Compile("[^.a-zA-Z0-9_-]+")
|
||||
if err != nil {
|
||||
return c.Render(http.StatusInternalServerError, "documentation-html", nil)
|
||||
}
|
||||
|
||||
var documents_processed []string
|
||||
|
||||
for _, document := range documents {
|
||||
document_processed := reg.ReplaceAllString(document, "")
|
||||
documents_processed = append(documents_processed, document_processed)
|
||||
}
|
||||
*/
|
||||
documents_processed := documents
|
||||
|
||||
data = append(data, Bucket{
|
||||
Name: bucket,
|
||||
Documents: documents,
|
||||
Documents: documents_processed,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -759,17 +779,9 @@ func handleAdminDocumentsUploadPOST(c echo.Context) error {
|
|||
// Format response
|
||||
var message, info, status string
|
||||
|
||||
for key, value := range response {
|
||||
switch key {
|
||||
case "info":
|
||||
info_map, ok := value.(map[string]interface{})
|
||||
if ok {
|
||||
info = fmt.Sprintf("/public/documentation/%s/%s [%.2f]", info_map["bucket"], info_map["key"], info_map["size"])
|
||||
}
|
||||
case "message":
|
||||
status = fmt.Sprint(value)
|
||||
}
|
||||
}
|
||||
info = fmt.Sprintf("[%.0f] /public/documentation/%s/%s", response.Info.Size, response.Info.Bucket, response.Info.Object)
|
||||
|
||||
status = response.Message
|
||||
|
||||
message = fmt.Sprintf("%s - %s", status, info)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue