From ab7cc7d1e0025d701b18a8cafc82de0ebc47f86a Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Fri, 30 Mar 2018 19:29:19 +0200 Subject: [PATCH] Add UploadApplicationImage API to router --- docs/spec.json | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ router/router.go | 44 ++++++++++++++++++++++++++++++++-- 2 files changed, 104 insertions(+), 2 deletions(-) diff --git a/docs/spec.json b/docs/spec.json index 4253dd3..9e76a28 100644 --- a/docs/spec.json +++ b/docs/spec.json @@ -177,6 +177,68 @@ } } }, + "/application/{id}/image": { + "post": { + "security": [ + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "description": "Upload an image for an application", + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "token" + ], + "operationId": "uploadAppImage", + "parameters": [ + { + "type": "file", + "description": "the application image", + "name": "file", + "in": "formData", + "required": true + }, + { + "type": "integer", + "description": "the application id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/Application" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, "/application/{id}/message": { "get": { "security": [ diff --git a/router/router.go b/router/router.go index 3826095..3e2d45f 100644 --- a/router/router.go +++ b/router/router.go @@ -13,6 +13,7 @@ import ( "net/http" + "github.com/gotify/location" "github.com/gotify/server/api/stream" "github.com/gotify/server/config" "github.com/gotify/server/docs" @@ -25,11 +26,11 @@ func Create(db *database.GormDatabase, vInfo *model.VersionInfo, conf *config.Co streamHandler := stream.New(200*time.Second, 15*time.Second) authentication := auth.Auth{DB: db} messageHandler := api.MessageAPI{Notifier: streamHandler, DB: db} - tokenHandler := api.TokenAPI{DB: db} + tokenHandler := api.TokenAPI{DB: db, ImageDir: conf.UploadedImagesDir} userHandler := api.UserAPI{DB: db, PasswordStrength: conf.PassStrength} g := gin.New() - g.Use(gin.Logger(), gin.Recovery(), error.Handler()) + g.Use(gin.Logger(), gin.Recovery(), error.Handler(), location.Default()) g.NoRoute(error.NotFound()) ui.Register(g) @@ -168,6 +169,45 @@ func Create(db *database.GormDatabase, vInfo *model.VersionInfo, conf *config.Co // $ref: "#/definitions/Error" app.POST("", tokenHandler.CreateApplication) + // swagger:operation POST /application/{id}/image token uploadAppImage + // + // Upload an image for an application + // + // --- + // consumes: + // - multipart/form-data + // produces: + // - application/json + // security: + // - clientTokenHeader: [] + // - clientTokenQuery: [] + // - basicAuth: [] + // parameters: + // - name: file + // in: formData + // description: the application image + // required: true + // type: file + // - name: id + // in: path + // description: the application id + // required: true + // type: integer + // responses: + // 200: + // description: Ok + // schema: + // $ref: "#/definitions/Application" + // 401: + // description: Unauthorized + // schema: + // $ref: "#/definitions/Error" + // 403: + // description: Forbidden + // schema: + // $ref: "#/definitions/Error" + app.POST("/:id/image", tokenHandler.UploadApplicationImage) + // swagger:operation DELETE /application/{id} token deleteApp // // Delete an application.