MCPcopy
hub / github.com/gotify/server / RemoveApplicationImage

Method RemoveApplicationImage

api/application.go:418–441  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

416// schema:
417// $ref: "#/definitions/Error"
418func (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
443func withResolvedImage(app *model.Application) *model.Application {
444 if app.Image == "" {

Calls 7

GetUserIDFunction · 0.92
withIDFunction · 0.85
successOrAbortFunction · 0.85
withResolvedImageFunction · 0.85
ErrorfMethod · 0.80
GetApplicationByIDMethod · 0.65
UpdateApplicationMethod · 0.65