RemoveApplicationImage deletes an image of an application. swagger:operation DELETE /application/{id}/image application removeAppImage Deletes an image of an application. --- consumes: [application/json] produces: [application/json] parameters: - name: id in: path description: the appli
(ctx *gin.Context)
| 416 | // schema: |
| 417 | // $ref: "#/definitions/Error" |
| 418 | func (a *ApplicationAPI) RemoveApplicationImage(ctx *gin.Context) { |
| 419 | withID(ctx, "id", func(id uint) { |
| 420 | app, err := a.DB.GetApplicationByID(id) |
| 421 | if success := successOrAbort(ctx, 500, err); !success { |
| 422 | return |
| 423 | } |
| 424 | if app != nil && app.UserID == auth.GetUserID(ctx) { |
| 425 | if app.Image == "" { |
| 426 | ctx.AbortWithError(400, fmt.Errorf("app with id %d does not have a customized image", id)) |
| 427 | return |
| 428 | } |
| 429 | |
| 430 | image := app.Image |
| 431 | app.Image = "" |
| 432 | if success := successOrAbort(ctx, 500, a.DB.UpdateApplication(app)); !success { |
| 433 | return |
| 434 | } |
| 435 | os.Remove(a.ImageDir + image) |
| 436 | ctx.JSON(200, withResolvedImage(app)) |
| 437 | } else { |
| 438 | ctx.AbortWithError(404, fmt.Errorf("app with id %d doesn't exists", id)) |
| 439 | } |
| 440 | }) |
| 441 | } |
| 442 | |
| 443 | func withResolvedImage(app *model.Application) *model.Application { |
| 444 | if app.Image == "" { |