删除原图
This commit is contained in:
@@ -318,12 +318,20 @@ func ImagesItemPatch(w http.ResponseWriter, r *http.Request) {
|
|||||||
// 删除一条图片
|
// 删除一条图片
|
||||||
func ImagesItemDelete(w http.ResponseWriter, r *http.Request) {
|
func ImagesItemDelete(w http.ResponseWriter, r *http.Request) {
|
||||||
image := models.Image{ID: utils.ParamInt(mux.Vars(r)["id"], 0)}
|
image := models.Image{ID: utils.ParamInt(mux.Vars(r)["id"], 0)}
|
||||||
if err := configs.ORMDB().Delete(&image).Error; err != nil {
|
if err := configs.ORMDB().First(&image).Error; err != nil {
|
||||||
log.Println(err)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
w.Write([]byte("图片不存在"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO: 删除本地文件
|
if err := configs.ORMDB().Delete(&image).Error; err != nil {
|
||||||
// 删除所有喜欢此图片的记录(双向解绑, A是user, B是image)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
w.Write([]byte("删除失败"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 删除本地图像文件 image.Path
|
||||||
|
os.Remove(image.Path)
|
||||||
|
|
||||||
|
// 删除所有用户喜欢此图片的记录(双向解绑, A是user, B是image)
|
||||||
models.LikeImage.RemoveB(strconv.Itoa(image.ID))
|
models.LikeImage.RemoveB(strconv.Itoa(image.ID))
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
Reference in New Issue
Block a user