Implémenter suppression de documents
`DELETE /v1/bucket/:bucket/:document`
This commit is contained in:
parent
9b823d971c
commit
1d095d965f
1 changed files with 51 additions and 2 deletions
|
@ -374,8 +374,57 @@ func handleV1DocumentUpdate(c echo.Context) error {
|
|||
|
||||
// handleV1DocumentDelete permet de supprimer un object
|
||||
func handleV1DocumentDelete(c echo.Context) error {
|
||||
return c.JSON(http.StatusNotImplemented, map[string]string{
|
||||
"message": "Not Implemented",
|
||||
documents_endpoint := viper.GetString("server.documents.endpoint")
|
||||
documents_access_key_id := viper.GetString("server.documents.access_key_id")
|
||||
documents_secret_access_key := viper.GetString("server.documents.secret_access_key")
|
||||
documents_use_ssl := viper.GetBool("server.documents.use_ssl")
|
||||
|
||||
bucket := c.Param("bucket")
|
||||
document := c.Param("document")
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
defer cancel()
|
||||
|
||||
// Initialize minio client object
|
||||
client, err := minio.New(documents_endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(documents_access_key_id, documents_secret_access_key, ""),
|
||||
Secure: documents_use_ssl,
|
||||
})
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||
"message": "Error during minio#New",
|
||||
})
|
||||
}
|
||||
|
||||
bucket_exists, err := client.BucketExists(ctx, bucket)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, "Error during minio#BucketExists")
|
||||
}
|
||||
|
||||
if !bucket_exists {
|
||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
||||
}
|
||||
|
||||
document_info, err := client.StatObject(ctx, bucket, document, minio.StatObjectOptions{})
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||
"message": "Error during minio#StatObject",
|
||||
})
|
||||
}
|
||||
|
||||
//TODO Add error validation
|
||||
_ = document_info
|
||||
|
||||
err = client.RemoveObject(ctx, bucket, document, minio.RemoveObjectOptions{})
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||
"message": "Error during minio#RemoveObject",
|
||||
})
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, map[string]string{
|
||||
"message": "Bucket deleted",
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue