From 97a834ae6af0c5f86fd0096c1260d95da85eb2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sun, 26 May 2024 19:30:13 +0200 Subject: [PATCH] Increase RequestMaxRetry and decrease RequestRetrySleep (also remove CreateChanel struct from 77cfe750) --- scnserver/api/handler/apiChannel.go | 11 +- scnserver/config.go | 4 +- scnserver/db/impl/primary/channels.go | 12 +- scnserver/logic/application.go | 9 +- scnserver/swagger/swagger.json | 296 ++++++++++++++++---------- scnserver/swagger/swagger.yaml | 219 +++++++++++-------- 6 files changed, 321 insertions(+), 230 deletions(-) diff --git a/scnserver/api/handler/apiChannel.go b/scnserver/api/handler/apiChannel.go index a3b644d..479b1be 100644 --- a/scnserver/api/handler/apiChannel.go +++ b/scnserver/api/handler/apiChannel.go @@ -4,7 +4,6 @@ import ( "blackforestbytes.com/simplecloudnotifier/api/apierr" "blackforestbytes.com/simplecloudnotifier/api/ginresp" ct "blackforestbytes.com/simplecloudnotifier/db/cursortoken" - "blackforestbytes.com/simplecloudnotifier/db/impl/primary" "blackforestbytes.com/simplecloudnotifier/models" "database/sql" "errors" @@ -236,15 +235,7 @@ func (h APIHandler) CreateChannel(g *gin.Context) ginresp.HTTPResponse { subscribeKey := h.app.GenerateRandomAuthKey() - cChannel := primary.CreateChanel{ - UserId: u.UserID, - IntName: channelInternalName, - SubscribeKey: subscribeKey, - DisplayName: channelDisplayName, - Description: b.Description, - } - - channel, err := h.database.CreateChannel(ctx, cChannel) + channel, err := h.database.CreateChannel(ctx, u.UserID, channelDisplayName, channelInternalName, subscribeKey, b.Description) if err != nil { return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create channel", err) } diff --git a/scnserver/config.go b/scnserver/config.go index d2df089..1ebe8f6 100644 --- a/scnserver/config.go +++ b/scnserver/config.go @@ -395,8 +395,8 @@ var configProd = func() Config { EnableLogger: true, }, RequestTimeout: 16 * time.Second, - RequestMaxRetry: 8, - RequestRetrySleep: 100 * time.Millisecond, + RequestMaxRetry: 32, + RequestRetrySleep: 32 * time.Millisecond, ReturnRawErrors: false, DummyFirebase: false, FirebaseTokenURI: "https://oauth2.googleapis.com/token", diff --git a/scnserver/db/impl/primary/channels.go b/scnserver/db/impl/primary/channels.go index b333151..a5c44b2 100644 --- a/scnserver/db/impl/primary/channels.go +++ b/scnserver/db/impl/primary/channels.go @@ -66,7 +66,7 @@ type CreateChanel struct { Description *string } -func (db *Database) CreateChannel(ctx db.TxContext, channel CreateChanel) (models.Channel, error) { +func (db *Database) CreateChannel(ctx db.TxContext, userid models.UserID, dispName string, intName string, subscribeKey string, description *string) (models.Channel, error) { tx, err := ctx.GetOrCreateTransaction(db) if err != nil { return models.Channel{}, err @@ -74,11 +74,11 @@ func (db *Database) CreateChannel(ctx db.TxContext, channel CreateChanel) (model entity := models.ChannelDB{ ChannelID: models.NewChannelID(), - OwnerUserID: channel.UserId, - DisplayName: channel.DisplayName, - InternalName: channel.IntName, - SubscribeKey: channel.SubscribeKey, - DescriptionName: channel.Description, + OwnerUserID: userid, + DisplayName: dispName, + InternalName: intName, + SubscribeKey: subscribeKey, + DescriptionName: description, TimestampCreated: time2DB(time.Now()), TimestampLastSent: nil, MessagesSent: 0, diff --git a/scnserver/logic/application.go b/scnserver/logic/application.go index 7c45ab0..cd386d1 100644 --- a/scnserver/logic/application.go +++ b/scnserver/logic/application.go @@ -4,7 +4,6 @@ import ( scn "blackforestbytes.com/simplecloudnotifier" "blackforestbytes.com/simplecloudnotifier/api/apierr" "blackforestbytes.com/simplecloudnotifier/api/ginresp" - "blackforestbytes.com/simplecloudnotifier/db/impl/primary" "blackforestbytes.com/simplecloudnotifier/db/simplectx" "blackforestbytes.com/simplecloudnotifier/google" "blackforestbytes.com/simplecloudnotifier/models" @@ -332,13 +331,7 @@ func (app *Application) GetOrCreateChannel(ctx *AppContext, userid models.UserID subscribeKey := app.GenerateRandomAuthKey() - channel := primary.CreateChanel{ - UserId: userid, - IntName: intChanName, - SubscribeKey: subscribeKey, - DisplayName: displayChanName, - } - newChan, err := app.Database.Primary.CreateChannel(ctx, channel) + newChan, err := app.Database.Primary.CreateChannel(ctx, userid, displayChanName, intChanName, subscribeKey, nil) if err != nil { return models.Channel{}, err } diff --git a/scnserver/swagger/swagger.json b/scnserver/swagger/swagger.json index f9db824..dd5fb8b 100644 --- a/scnserver/swagger/swagger.json +++ b/scnserver/swagger/swagger.json @@ -958,13 +958,13 @@ } }, "/api/v2/messages/{mid}": { - "delete": { - "description": "The user must own the message and request the resource with the ADMIN Key", + "get": { + "description": "The user must either own the message and request the resource with the READ or ADMIN Key\nOr the user must subscribe to the corresponding channel (and be confirmed) and request the resource with the READ or ADMIN Key\nThe returned message is never trimmed", "tags": [ "API-v2" ], - "summary": "Delete a single message", - "operationId": "api-messages-delete", + "summary": "Get a single message (untrimmed)", + "operationId": "api-messages-get", "parameters": [ { "type": "string", @@ -1007,13 +1007,13 @@ } } }, - "patch": { - "description": "The user must either own the message and request the resource with the READ or ADMIN Key\nOr the user must subscribe to the corresponding channel (and be confirmed) and request the resource with the READ or ADMIN Key\nThe returned message is never trimmed", + "delete": { + "description": "The user must own the message and request the resource with the ADMIN Key", "tags": [ "API-v2" ], - "summary": "Get a single message (untrimmed)", - "operationId": "api-messages-get", + "summary": "Delete a single message", + "operationId": "api-messages-delete", "parameters": [ { "type": "string", @@ -2449,6 +2449,104 @@ } } }, + "/external/v1/uptime-kuma": { + "post": { + "description": "All parameter can be set via query-parameter or the json body. Only UserID, UserKey and Title are required", + "tags": [ + "External" + ], + "summary": "Send a new message", + "parameters": [ + { + "type": "string", + "name": "channel", + "in": "query" + }, + { + "type": "string", + "name": "channel_down", + "in": "query" + }, + { + "type": "string", + "name": "channel_up", + "in": "query" + }, + { + "type": "string", + "example": "P3TNH8mvv14fm", + "name": "key", + "in": "query" + }, + { + "type": "integer", + "name": "priority", + "in": "query" + }, + { + "type": "integer", + "name": "priority_down", + "in": "query" + }, + { + "type": "integer", + "name": "priority_up", + "in": "query" + }, + { + "type": "string", + "name": "senderName", + "in": "query" + }, + { + "type": "string", + "example": "7725", + "name": "user_id", + "in": "query" + }, + { + "description": " ", + "name": "post_body", + "in": "body", + "schema": { + "$ref": "#/definitions/handler.UptimeKuma.body" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.UptimeKuma.response" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/ginresp.apiError" + } + }, + "401": { + "description": "The user_id was not found or the user_key is wrong", + "schema": { + "$ref": "#/definitions/ginresp.apiError" + } + }, + "403": { + "description": "The user has exceeded its daily quota - wait 24 hours or upgrade your account", + "schema": { + "$ref": "#/definitions/ginresp.apiError" + } + }, + "500": { + "description": "An internal server error occurred - try again later", + "schema": { + "$ref": "#/definitions/ginresp.apiError" + } + } + } + } + }, "/send": { "post": { "description": "All parameter can be set via query-parameter or the json body. Only UserID, UserKey and Title are required", @@ -2629,72 +2727,120 @@ "parameters": [ { "type": "string", + "example": "test", + "name": "channel", + "in": "query" + }, + { + "type": "string", + "example": "This is a message", "name": "content", "in": "query" }, { "type": "string", + "example": "P3TNH8mvv14fm", + "name": "key", + "in": "query" + }, + { + "type": "string", + "example": "db8b0e6a-a08c-4646", "name": "msg_id", "in": "query" }, { + "enum": [ + 0, + 1, + 2 + ], "type": "integer", + "example": 1, "name": "priority", "in": "query" }, + { + "type": "string", + "example": "example-server", + "name": "sender_name", + "in": "query" + }, { "type": "number", + "example": 1669824037, "name": "timestamp", "in": "query" }, { "type": "string", + "example": "Hello World", "name": "title", "in": "query" }, { - "type": "integer", + "type": "string", + "example": "7725", "name": "user_id", "in": "query" }, { "type": "string", - "name": "user_key", - "in": "query" + "example": "test", + "name": "channel", + "in": "formData" }, { "type": "string", + "example": "This is a message", "name": "content", "in": "formData" }, { "type": "string", + "example": "P3TNH8mvv14fm", + "name": "key", + "in": "formData" + }, + { + "type": "string", + "example": "db8b0e6a-a08c-4646", "name": "msg_id", "in": "formData" }, { + "enum": [ + 0, + 1, + 2 + ], "type": "integer", + "example": 1, "name": "priority", "in": "formData" }, + { + "type": "string", + "example": "example-server", + "name": "sender_name", + "in": "formData" + }, { "type": "number", + "example": 1669824037, "name": "timestamp", "in": "formData" }, { "type": "string", + "example": "Hello World", "name": "title", "in": "formData" }, - { - "type": "integer", - "name": "user_id", - "in": "formData" - }, { "type": "string", - "name": "user_key", + "example": "7725", + "name": "user_id", "in": "formData" } ], @@ -2702,7 +2848,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/handler.SendMessageCompat.response" + "$ref": "#/definitions/handler.SendMessage.response" } }, "400": { @@ -2731,69 +2877,6 @@ } } } - }, - "/webhook/uptime-kuma": { - "post": { - "description": "All parameter can be set via query-parameter or the json body. Only UserID, UserKey and Title are required", - "tags": [ - "External" - ], - "summary": "Send a new message", - "parameters": [ - { - "type": "string", - "example": "P3TNH8mvv14fm", - "name": "key", - "in": "query" - }, - { - "type": "string", - "example": "7725", - "name": "user_id", - "in": "query" - }, - { - "description": " ", - "name": "post_body", - "in": "body", - "schema": { - "$ref": "#/definitions/handler.UptimeKumaWebHook.uptimeKumaWebhookBody" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "object" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/ginresp.apiError" - } - }, - "401": { - "description": "The user_id was not found or the user_key is wrong", - "schema": { - "$ref": "#/definitions/ginresp.apiError" - } - }, - "403": { - "description": "The user has exceeded its daily quota - wait 24 hours or upgrade your account", - "schema": { - "$ref": "#/definitions/ginresp.apiError" - } - }, - "500": { - "description": "An internal server error occurred - try again later", - "schema": { - "$ref": "#/definitions/ginresp.apiError" - } - } - } - } } }, "definitions": { @@ -2964,6 +3047,9 @@ "handler.CreateChannel.body": { "type": "object", "properties": { + "description": { + "type": "string" + }, "name": { "type": "string" }, @@ -3323,41 +3409,6 @@ } } }, - "handler.SendMessageCompat.response": { - "type": "object", - "properties": { - "errhighlight": { - "type": "integer" - }, - "error": { - "$ref": "#/definitions/apierr.APIError" - }, - "is_pro": { - "type": "boolean" - }, - "message": { - "type": "string" - }, - "messagecount": { - "type": "integer" - }, - "quota": { - "type": "integer" - }, - "quota_max": { - "type": "integer" - }, - "scn_msg_id": { - "type": "integer" - }, - "success": { - "type": "boolean" - }, - "suppress_send": { - "type": "boolean" - } - } - }, "handler.Sleep.response": { "type": "object", "properties": { @@ -3449,7 +3500,7 @@ } } }, - "handler.UptimeKumaWebHook.uptimeKumaWebhookBody": { + "handler.UptimeKuma.body": { "type": "object", "properties": { "heartbeat": { @@ -3461,6 +3512,9 @@ "msg": { "type": "string" }, + "status": { + "type": "integer" + }, "time": { "type": "string" }, @@ -3488,6 +3542,14 @@ } } }, + "handler.UptimeKuma.response": { + "type": "object", + "properties": { + "message_id": { + "type": "string" + } + } + }, "handler.pingResponse": { "type": "object", "properties": { diff --git a/scnserver/swagger/swagger.yaml b/scnserver/swagger/swagger.yaml index 13039c3..4325685 100644 --- a/scnserver/swagger/swagger.yaml +++ b/scnserver/swagger/swagger.yaml @@ -139,6 +139,8 @@ definitions: type: object handler.CreateChannel.body: properties: + description: + type: string name: type: string subscribe: @@ -376,29 +378,6 @@ definitions: suppress_send: type: boolean type: object - handler.SendMessageCompat.response: - properties: - errhighlight: - type: integer - error: - $ref: '#/definitions/apierr.APIError' - is_pro: - type: boolean - message: - type: string - messagecount: - type: integer - quota: - type: integer - quota_max: - type: integer - scn_msg_id: - type: integer - success: - type: boolean - suppress_send: - type: boolean - type: object handler.Sleep.response: properties: duration: @@ -458,7 +437,7 @@ definitions: user_id: type: integer type: object - handler.UptimeKumaWebHook.uptimeKumaWebhookBody: + handler.UptimeKuma.body: properties: heartbeat: properties: @@ -466,6 +445,8 @@ definitions: type: string msg: type: string + status: + type: integer time: type: string timezone: @@ -483,6 +464,11 @@ definitions: msg: type: string type: object + handler.UptimeKuma.response: + properties: + message_id: + type: string + type: object handler.pingResponse: properties: info: @@ -1418,7 +1404,7 @@ paths: summary: Delete a single message tags: - API-v2 - patch: + get: description: |- The user must either own the message and request the resource with the READ or ADMIN Key Or the user must subscribe to the corresponding channel (and be confirmed) and request the resource with the READ or ADMIN Key @@ -2414,6 +2400,70 @@ paths: summary: Update a subscription (e.g. confirm) tags: - API-v2 + /external/v1/uptime-kuma: + post: + description: All parameter can be set via query-parameter or the json body. + Only UserID, UserKey and Title are required + parameters: + - in: query + name: channel + type: string + - in: query + name: channel_down + type: string + - in: query + name: channel_up + type: string + - example: P3TNH8mvv14fm + in: query + name: key + type: string + - in: query + name: priority + type: integer + - in: query + name: priority_down + type: integer + - in: query + name: priority_up + type: integer + - in: query + name: senderName + type: string + - example: "7725" + in: query + name: user_id + type: string + - description: ' ' + in: body + name: post_body + schema: + $ref: '#/definitions/handler.UptimeKuma.body' + responses: + "200": + description: OK + schema: + $ref: '#/definitions/handler.UptimeKuma.response' + "400": + description: Bad Request + schema: + $ref: '#/definitions/ginresp.apiError' + "401": + description: The user_id was not found or the user_key is wrong + schema: + $ref: '#/definitions/ginresp.apiError' + "403": + description: The user has exceeded its daily quota - wait 24 hours or upgrade + your account + schema: + $ref: '#/definitions/ginresp.apiError' + "500": + description: An internal server error occurred - try again later + schema: + $ref: '#/definitions/ginresp.apiError' + summary: Send a new message + tags: + - External /send: post: description: All parameter can be set via query-parameter or the json body. @@ -2535,53 +2585,91 @@ paths: description: All parameter can be set via query-parameter or form-data body. Only UserID, UserKey and Title are required parameters: - - in: query + - example: test + in: query + name: channel + type: string + - example: This is a message + in: query name: content type: string - - in: query + - example: P3TNH8mvv14fm + in: query + name: key + type: string + - example: db8b0e6a-a08c-4646 + in: query name: msg_id type: string - - in: query + - enum: + - 0 + - 1 + - 2 + example: 1 + in: query name: priority type: integer - - in: query + - example: example-server + in: query + name: sender_name + type: string + - example: 1669824037 + in: query name: timestamp type: number - - in: query + - example: Hello World + in: query name: title type: string - - in: query + - example: "7725" + in: query name: user_id - type: integer - - in: query - name: user_key type: string - - in: formData + - example: test + in: formData + name: channel + type: string + - example: This is a message + in: formData name: content type: string - - in: formData + - example: P3TNH8mvv14fm + in: formData + name: key + type: string + - example: db8b0e6a-a08c-4646 + in: formData name: msg_id type: string - - in: formData + - enum: + - 0 + - 1 + - 2 + example: 1 + in: formData name: priority type: integer - - in: formData + - example: example-server + in: formData + name: sender_name + type: string + - example: 1669824037 + in: formData name: timestamp type: number - - in: formData + - example: Hello World + in: formData name: title type: string - - in: formData + - example: "7725" + in: formData name: user_id - type: integer - - in: formData - name: user_key type: string responses: "200": description: OK schema: - $ref: '#/definitions/handler.SendMessageCompat.response' + $ref: '#/definitions/handler.SendMessage.response' "400": description: Bad Request schema: @@ -2601,49 +2689,6 @@ paths: summary: Send a new message (compatibility) tags: - External - /webhook/uptime-kuma: - post: - description: All parameter can be set via query-parameter or the json body. - Only UserID, UserKey and Title are required - parameters: - - example: P3TNH8mvv14fm - in: query - name: key - type: string - - example: "7725" - in: query - name: user_id - type: string - - description: ' ' - in: body - name: post_body - schema: - $ref: '#/definitions/handler.UptimeKumaWebHook.uptimeKumaWebhookBody' - responses: - "200": - description: OK - schema: - type: object - "400": - description: Bad Request - schema: - $ref: '#/definitions/ginresp.apiError' - "401": - description: The user_id was not found or the user_key is wrong - schema: - $ref: '#/definitions/ginresp.apiError' - "403": - description: The user has exceeded its daily quota - wait 24 hours or upgrade - your account - schema: - $ref: '#/definitions/ginresp.apiError' - "500": - description: An internal server error occurred - try again later - schema: - $ref: '#/definitions/ginresp.apiError' - summary: Send a new message - tags: - - External swagger: "2.0" tags: - name: External