Add /preview/* routes

This commit is contained in:
Mike Schwörer 2024-06-12 00:35:06 +02:00
parent 64709920f7
commit 80b1351bd2
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
9 changed files with 924 additions and 102 deletions

View File

@ -0,0 +1,127 @@
package handler
import (
"blackforestbytes.com/simplecloudnotifier/api/apierr"
"blackforestbytes.com/simplecloudnotifier/api/ginresp"
"blackforestbytes.com/simplecloudnotifier/models"
"database/sql"
"errors"
"github.com/gin-gonic/gin"
"net/http"
)
// GetUserPreview swaggerdoc
//
// @Summary Get a user (similar to api-user-get, but can be called from anyone and only returns a subset of fields)
// @ID api-user-get-preview
// @Tags API-v2
//
// @Param uid path string true "UserID"
//
// @Success 200 {object} models.UserPreviewJSON
// @Failure 400 {object} ginresp.apiError "supplied values/parameters cannot be parsed / are invalid"
// @Failure 401 {object} ginresp.apiError "user is not authorized / has missing permissions"
// @Failure 404 {object} ginresp.apiError "user not found"
// @Failure 500 {object} ginresp.apiError "internal server error"
//
// @Router /api/v2/preview/users/{uid} [GET]
func (h APIHandler) GetUserPreview(g *gin.Context) ginresp.HTTPResponse {
type uri struct {
UserID models.UserID `uri:"uid" binding:"entityid"`
}
var u uri
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
if errResp != nil {
return *errResp
}
defer ctx.Cancel()
user, err := h.database.GetUser(ctx, u.UserID)
if errors.Is(err, sql.ErrNoRows) {
return ginresp.APIError(g, 404, apierr.USER_NOT_FOUND, "User not found", err)
}
if err != nil {
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query user", err)
}
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, user.JSONPreview()))
}
// GetChannelPreview swaggerdoc
//
// @Summary Get a single channel (similar to api-channels-get, but can be called from anyone and only returns a subset of fields)
// @ID api-channels-get-preview
// @Tags API-v2
//
// @Param cid path string true "ChannelID"
//
// @Success 200 {object} models.ChannelPreviewJSON
// @Failure 400 {object} ginresp.apiError "supplied values/parameters cannot be parsed / are invalid"
// @Failure 401 {object} ginresp.apiError "user is not authorized / has missing permissions"
// @Failure 404 {object} ginresp.apiError "channel not found"
// @Failure 500 {object} ginresp.apiError "internal server error"
//
// @Router /api/v2/preview/channels/{cid} [GET]
func (h APIHandler) GetChannelPreview(g *gin.Context) ginresp.HTTPResponse {
type uri struct {
UserID models.UserID `uri:"uid" binding:"entityid"`
ChannelID models.ChannelID `uri:"cid" binding:"entityid"`
}
var u uri
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
if errResp != nil {
return *errResp
}
defer ctx.Cancel()
channel, err := h.database.GetChannelByID(ctx, u.ChannelID)
if errors.Is(err, sql.ErrNoRows) {
return ginresp.APIError(g, 404, apierr.CHANNEL_NOT_FOUND, "Channel not found", err)
}
if err != nil {
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query channel", err)
}
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, channel.JSONPreview()))
}
// GetUserKeyPreview swaggerdoc
//
// @Summary Get a single key (similar to api-tokenkeys-get, but can be called from anyone and only returns a subset of fields)
// @ID api-tokenkeys-get-preview
// @Tags API-v2
//
// @Param kid path string true "TokenKeyID"
//
// @Success 200 {object} models.KeyTokenPreviewJSON
// @Failure 400 {object} ginresp.apiError "supplied values/parameters cannot be parsed / are invalid"
// @Failure 401 {object} ginresp.apiError "user is not authorized / has missing permissions"
// @Failure 404 {object} ginresp.apiError "message not found"
// @Failure 500 {object} ginresp.apiError "internal server error"
//
// @Router /api/v2/preview/keys/{kid} [GET]
func (h APIHandler) GetUserKeyPreview(g *gin.Context) ginresp.HTTPResponse {
type uri struct {
UserID models.UserID `uri:"uid" binding:"entityid"`
KeyID models.KeyTokenID `uri:"kid" binding:"entityid"`
}
var u uri
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
if errResp != nil {
return *errResp
}
defer ctx.Cancel()
keytoken, err := h.database.GetKeyToken(ctx, u.UserID, u.KeyID)
if errors.Is(err, sql.ErrNoRows) {
return ginresp.APIError(g, 404, apierr.KEY_NOT_FOUND, "Key not found", err)
}
if err != nil {
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query client", err)
}
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, keytoken.JSONPreview()))
}

View File

@ -157,6 +157,10 @@ func (r *Router) Init(e *gin.Engine) error {
apiv2.GET("/messages", r.Wrap(r.apiHandler.ListMessages)) apiv2.GET("/messages", r.Wrap(r.apiHandler.ListMessages))
apiv2.GET("/messages/:mid", r.Wrap(r.apiHandler.GetMessage)) apiv2.GET("/messages/:mid", r.Wrap(r.apiHandler.GetMessage))
apiv2.DELETE("/messages/:mid", r.Wrap(r.apiHandler.DeleteMessage)) apiv2.DELETE("/messages/:mid", r.Wrap(r.apiHandler.DeleteMessage))
apiv2.GET("/preview/users/:uid", r.Wrap(r.apiHandler.GetUserPreview))
apiv2.GET("/preview/keys/:kid", r.Wrap(r.apiHandler.GetUserKeyPreview))
apiv2.GET("/preview/channels/:cid", r.Wrap(r.apiHandler.GetChannelPreview))
} }
// ================ Send API (unversioned) ================ // ================ Send API (unversioned) ================

View File

@ -41,6 +41,16 @@ func (c Channel) WithSubscription(sub *Subscription) ChannelWithSubscription {
} }
} }
func (c Channel) JSONPreview() ChannelPreviewJSON {
return ChannelPreviewJSON{
ChannelID: c.ChannelID,
OwnerUserID: c.OwnerUserID,
InternalName: c.InternalName,
DisplayName: c.DisplayName,
DescriptionName: c.DescriptionName,
}
}
type ChannelWithSubscription struct { type ChannelWithSubscription struct {
Channel Channel
Subscription *Subscription Subscription *Subscription
@ -74,6 +84,14 @@ type ChannelWithSubscriptionJSON struct {
Subscription *SubscriptionJSON `json:"subscription"` Subscription *SubscriptionJSON `json:"subscription"`
} }
type ChannelPreviewJSON struct {
ChannelID ChannelID `json:"channel_id"`
OwnerUserID UserID `json:"owner_user_id"`
InternalName string `json:"internal_name"`
DisplayName string `json:"display_name"`
DescriptionName *string `json:"description_name"`
}
type ChannelDB struct { type ChannelDB struct {
ChannelID ChannelID `db:"channel_id"` ChannelID ChannelID `db:"channel_id"`
OwnerUserID UserID `db:"owner_user_id"` OwnerUserID UserID `db:"owner_user_id"`

View File

@ -5,7 +5,7 @@ package models
import "gogs.mikescher.com/BlackForestBytes/goext/langext" import "gogs.mikescher.com/BlackForestBytes/goext/langext"
import "gogs.mikescher.com/BlackForestBytes/goext/enums" import "gogs.mikescher.com/BlackForestBytes/goext/enums"
const ChecksumEnumGenerator = "5b115c5f107801af608630d2c5adce57cd4b050d176c8cd3db5c132020bf153c" // GoExtVersion: 0.0.463 const ChecksumEnumGenerator = "e500346e3f60b3abf78558ec3df128c3be2a1cefa71c4f1feba9293d14eb85d1" // GoExtVersion: 0.0.463
// ================================ ClientType ================================ // ================================ ClientType ================================
// //

View File

@ -15,7 +15,7 @@ import "reflect"
import "regexp" import "regexp"
import "strings" import "strings"
const ChecksumCharsetIDGenerator = "5b115c5f107801af608630d2c5adce57cd4b050d176c8cd3db5c132020bf153c" // GoExtVersion: 0.0.463 const ChecksumCharsetIDGenerator = "e500346e3f60b3abf78558ec3df128c3be2a1cefa71c4f1feba9293d14eb85d1" // GoExtVersion: 0.0.463
const idlen = 24 const idlen = 24

View File

@ -92,6 +92,17 @@ func (k KeyToken) JSON() KeyTokenJSON {
} }
} }
func (k KeyToken) JSONPreview() KeyTokenPreviewJSON {
return KeyTokenPreviewJSON{
KeyTokenID: k.KeyTokenID,
Name: k.Name,
OwnerUserID: k.OwnerUserID,
AllChannels: k.AllChannels,
Channels: k.Channels,
Permissions: k.Permissions.String(),
}
}
type KeyTokenJSON struct { type KeyTokenJSON struct {
KeyTokenID KeyTokenID `json:"keytoken_id"` KeyTokenID KeyTokenID `json:"keytoken_id"`
Name string `json:"name"` Name string `json:"name"`
@ -109,6 +120,15 @@ type KeyTokenWithTokenJSON struct {
Token string `json:"token"` Token string `json:"token"`
} }
type KeyTokenPreviewJSON struct {
KeyTokenID KeyTokenID `json:"keytoken_id"`
Name string `json:"name"`
OwnerUserID UserID `json:"owner_user_id"`
AllChannels bool `json:"all_channels"`
Channels []ChannelID `json:"channels"`
Permissions string `json:"permissions"`
}
func (j KeyTokenJSON) WithToken(tok string) KeyTokenWithTokenJSON { func (j KeyTokenJSON) WithToken(tok string) KeyTokenWithTokenJSON {
return KeyTokenWithTokenJSON{ return KeyTokenWithTokenJSON{
KeyTokenJSON: j, KeyTokenJSON: j,

View File

@ -116,6 +116,13 @@ func (u User) MaxTimestampDiffHours() int {
return 24 return 24
} }
func (u User) JSONPreview() UserPreviewJSON {
return UserPreviewJSON{
UserID: u.UserID,
Username: u.Username,
}
}
type UserJSON struct { type UserJSON struct {
UserID UserID `json:"user_id"` UserID UserID `json:"user_id"`
Username *string `json:"username"` Username *string `json:"username"`
@ -137,6 +144,11 @@ type UserJSON struct {
MaxUserMessageIDLength int `json:"max_user_message_id_length"` MaxUserMessageIDLength int `json:"max_user_message_id_length"`
} }
type UserPreviewJSON struct {
UserID UserID `json:"user_id"`
Username *string `json:"username"`
}
type UserJSONWithClientsAndKeys struct { type UserJSONWithClientsAndKeys struct {
UserJSON UserJSON
Clients []ClientJSON `json:"clients"` Clients []ClientJSON `json:"clients"`

View File

@ -19,37 +19,61 @@
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
"example": "test",
"name": "channel",
"in": "query"
},
{
"type": "string",
"example": "This is a message",
"name": "content", "name": "content",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "query"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id", "name": "msg_id",
"in": "query" "in": "query"
}, },
{ {
"enum": [
0,
1,
2
],
"type": "integer", "type": "integer",
"example": 1,
"name": "priority", "name": "priority",
"in": "query" "in": "query"
}, },
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "query"
},
{ {
"type": "number", "type": "number",
"example": 1669824037,
"name": "timestamp", "name": "timestamp",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"example": "Hello World",
"name": "title", "name": "title",
"in": "query" "in": "query"
}, },
{
"type": "integer",
"name": "user_id",
"in": "query"
},
{ {
"type": "string", "type": "string",
"name": "user_key", "example": "7725",
"name": "user_id",
"in": "query" "in": "query"
}, },
{ {
@ -62,37 +86,61 @@
}, },
{ {
"type": "string", "type": "string",
"example": "test",
"name": "channel",
"in": "formData"
},
{
"type": "string",
"example": "This is a message",
"name": "content", "name": "content",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "formData"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id", "name": "msg_id",
"in": "formData" "in": "formData"
}, },
{ {
"enum": [
0,
1,
2
],
"type": "integer", "type": "integer",
"example": 1,
"name": "priority", "name": "priority",
"in": "formData" "in": "formData"
}, },
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "formData"
},
{ {
"type": "number", "type": "number",
"example": 1669824037,
"name": "timestamp", "name": "timestamp",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "Hello World",
"name": "title", "name": "title",
"in": "formData" "in": "formData"
}, },
{
"type": "integer",
"name": "user_id",
"in": "formData"
},
{ {
"type": "string", "type": "string",
"name": "user_key", "example": "7725",
"name": "user_id",
"in": "formData" "in": "formData"
} }
], ],
@ -1009,6 +1057,156 @@
} }
} }
}, },
"/api/v2/preview/channels/{cid}": {
"get": {
"tags": [
"API-v2"
],
"summary": "Get a single channel (similar to api-channels-get, but can be called from anyone and only returns a subset of fields)",
"operationId": "api-channels-get-preview",
"parameters": [
{
"type": "string",
"description": "ChannelID",
"name": "cid",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.ChannelPreviewJSON"
}
},
"400": {
"description": "supplied values/parameters cannot be parsed / are invalid",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
},
"401": {
"description": "user is not authorized / has missing permissions",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
},
"404": {
"description": "channel not found",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
},
"500": {
"description": "internal server error",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
}
}
}
},
"/api/v2/preview/keys/{kid}": {
"get": {
"tags": [
"API-v2"
],
"summary": "Get a single key (similar to api-tokenkeys-get, but can be called from anyone and only returns a subset of fields)",
"operationId": "api-tokenkeys-get-preview",
"parameters": [
{
"type": "string",
"description": "TokenKeyID",
"name": "kid",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.KeyTokenPreviewJSON"
}
},
"400": {
"description": "supplied values/parameters cannot be parsed / are invalid",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
},
"401": {
"description": "user is not authorized / has missing permissions",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
},
"404": {
"description": "message not found",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
},
"500": {
"description": "internal server error",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
}
}
}
},
"/api/v2/preview/users/{uid}": {
"get": {
"tags": [
"API-v2"
],
"summary": "Get a user (similar to api-user-get, but can be called from anyone and only returns a subset of fields)",
"operationId": "api-user-get-preview",
"parameters": [
{
"type": "string",
"description": "UserID",
"name": "uid",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.UserPreviewJSON"
}
},
"400": {
"description": "supplied values/parameters cannot be parsed / are invalid",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
},
"401": {
"description": "user is not authorized / has missing permissions",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
},
"404": {
"description": "user not found",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
},
"500": {
"description": "internal server error",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
}
}
}
},
"/api/v2/users": { "/api/v2/users": {
"post": { "post": {
"tags": [ "tags": [
@ -2567,37 +2765,61 @@
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
"example": "test",
"name": "channel",
"in": "query"
},
{
"type": "string",
"example": "This is a message",
"name": "content", "name": "content",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "query"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id", "name": "msg_id",
"in": "query" "in": "query"
}, },
{ {
"enum": [
0,
1,
2
],
"type": "integer", "type": "integer",
"example": 1,
"name": "priority", "name": "priority",
"in": "query" "in": "query"
}, },
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "query"
},
{ {
"type": "number", "type": "number",
"example": 1669824037,
"name": "timestamp", "name": "timestamp",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"example": "Hello World",
"name": "title", "name": "title",
"in": "query" "in": "query"
}, },
{
"type": "integer",
"name": "user_id",
"in": "query"
},
{ {
"type": "string", "type": "string",
"name": "user_key", "example": "7725",
"name": "user_id",
"in": "query" "in": "query"
}, },
{ {
@ -2610,37 +2832,61 @@
}, },
{ {
"type": "string", "type": "string",
"example": "test",
"name": "channel",
"in": "formData"
},
{
"type": "string",
"example": "This is a message",
"name": "content", "name": "content",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "formData"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id", "name": "msg_id",
"in": "formData" "in": "formData"
}, },
{ {
"enum": [
0,
1,
2
],
"type": "integer", "type": "integer",
"example": 1,
"name": "priority", "name": "priority",
"in": "formData" "in": "formData"
}, },
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "formData"
},
{ {
"type": "number", "type": "number",
"example": 1669824037,
"name": "timestamp", "name": "timestamp",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "Hello World",
"name": "title", "name": "title",
"in": "formData" "in": "formData"
}, },
{
"type": "integer",
"name": "user_id",
"in": "formData"
},
{ {
"type": "string", "type": "string",
"name": "user_key", "example": "7725",
"name": "user_id",
"in": "formData" "in": "formData"
} }
], ],
@ -2689,72 +2935,120 @@
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
"example": "test",
"name": "channel",
"in": "query"
},
{
"type": "string",
"example": "This is a message",
"name": "content", "name": "content",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "query"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id", "name": "msg_id",
"in": "query" "in": "query"
}, },
{ {
"enum": [
0,
1,
2
],
"type": "integer", "type": "integer",
"example": 1,
"name": "priority", "name": "priority",
"in": "query" "in": "query"
}, },
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "query"
},
{ {
"type": "number", "type": "number",
"example": 1669824037,
"name": "timestamp", "name": "timestamp",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"example": "Hello World",
"name": "title", "name": "title",
"in": "query" "in": "query"
}, },
{ {
"type": "integer", "type": "string",
"example": "7725",
"name": "user_id", "name": "user_id",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"name": "user_key", "example": "test",
"in": "query" "name": "channel",
"in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "This is a message",
"name": "content", "name": "content",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "formData"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id", "name": "msg_id",
"in": "formData" "in": "formData"
}, },
{ {
"enum": [
0,
1,
2
],
"type": "integer", "type": "integer",
"example": 1,
"name": "priority", "name": "priority",
"in": "formData" "in": "formData"
}, },
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "formData"
},
{ {
"type": "number", "type": "number",
"example": 1669824037,
"name": "timestamp", "name": "timestamp",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "Hello World",
"name": "title", "name": "title",
"in": "formData" "in": "formData"
}, },
{
"type": "integer",
"name": "user_id",
"in": "formData"
},
{ {
"type": "string", "type": "string",
"name": "user_key", "example": "7725",
"name": "user_id",
"in": "formData" "in": "formData"
} }
], ],
@ -3251,26 +3545,46 @@
"handler.SendMessage.combined": { "handler.SendMessage.combined": {
"type": "object", "type": "object",
"properties": { "properties": {
"channel": {
"type": "string",
"example": "test"
},
"content": { "content": {
"type": "string" "type": "string",
"example": "This is a message"
},
"key": {
"type": "string",
"example": "P3TNH8mvv14fm"
}, },
"msg_id": { "msg_id": {
"type": "string" "type": "string",
"example": "db8b0e6a-a08c-4646"
}, },
"priority": { "priority": {
"type": "integer" "type": "integer",
"enum": [
0,
1,
2
],
"example": 1
},
"sender_name": {
"type": "string",
"example": "example-server"
}, },
"timestamp": { "timestamp": {
"type": "number" "type": "number",
"example": 1669824037
}, },
"title": { "title": {
"type": "string" "type": "string",
"example": "Hello World"
}, },
"user_id": { "user_id": {
"type": "integer" "type": "string",
}, "example": "7725"
"user_key": {
"type": "string"
} }
} }
}, },
@ -3299,7 +3613,7 @@
"type": "integer" "type": "integer"
}, },
"scn_msg_id": { "scn_msg_id": {
"type": "integer" "type": "string"
}, },
"success": { "success": {
"type": "boolean" "type": "boolean"
@ -3487,6 +3801,26 @@
} }
} }
}, },
"models.ChannelPreviewJSON": {
"type": "object",
"properties": {
"channel_id": {
"type": "string"
},
"description_name": {
"type": "string"
},
"display_name": {
"type": "string"
},
"internal_name": {
"type": "string"
},
"owner_user_id": {
"type": "string"
}
}
},
"models.ChannelWithSubscriptionJSON": { "models.ChannelWithSubscriptionJSON": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3630,6 +3964,32 @@
} }
} }
}, },
"models.KeyTokenPreviewJSON": {
"type": "object",
"properties": {
"all_channels": {
"type": "boolean"
},
"channels": {
"type": "array",
"items": {
"type": "string"
}
},
"keytoken_id": {
"type": "string"
},
"name": {
"type": "string"
},
"owner_user_id": {
"type": "string"
},
"permissions": {
"type": "string"
}
}
},
"models.KeyTokenWithTokenJSON": { "models.KeyTokenWithTokenJSON": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3870,6 +4230,17 @@
"type": "string" "type": "string"
} }
} }
},
"models.UserPreviewJSON": {
"type": "object",
"properties": {
"user_id": {
"type": "string"
},
"username": {
"type": "string"
}
}
} }
}, },
"tags": [ "tags": [

View File

@ -327,19 +327,36 @@ definitions:
type: object type: object
handler.SendMessage.combined: handler.SendMessage.combined:
properties: properties:
channel:
example: test
type: string
content: content:
example: This is a message
type: string
key:
example: P3TNH8mvv14fm
type: string type: string
msg_id: msg_id:
example: db8b0e6a-a08c-4646
type: string type: string
priority: priority:
enum:
- 0
- 1
- 2
example: 1
type: integer type: integer
sender_name:
example: example-server
type: string
timestamp: timestamp:
example: 1669824037
type: number type: number
title: title:
example: Hello World
type: string type: string
user_id: user_id:
type: integer example: "7725"
user_key:
type: string type: string
type: object type: object
handler.SendMessage.response: handler.SendMessage.response:
@ -359,7 +376,7 @@ definitions:
quota_max: quota_max:
type: integer type: integer
scn_msg_id: scn_msg_id:
type: integer type: string
success: success:
type: boolean type: boolean
suppress_send: suppress_send:
@ -480,6 +497,19 @@ definitions:
uri: uri:
type: string type: string
type: object type: object
models.ChannelPreviewJSON:
properties:
channel_id:
type: string
description_name:
type: string
display_name:
type: string
internal_name:
type: string
owner_user_id:
type: string
type: object
models.ChannelWithSubscriptionJSON: models.ChannelWithSubscriptionJSON:
properties: properties:
channel_id: channel_id:
@ -577,6 +607,23 @@ definitions:
timestamp_lastused: timestamp_lastused:
type: string type: string
type: object type: object
models.KeyTokenPreviewJSON:
properties:
all_channels:
type: boolean
channels:
items:
type: string
type: array
keytoken_id:
type: string
name:
type: string
owner_user_id:
type: string
permissions:
type: string
type: object
models.KeyTokenWithTokenJSON: models.KeyTokenWithTokenJSON:
properties: properties:
all_channels: all_channels:
@ -736,6 +783,13 @@ definitions:
username: username:
type: string type: string
type: object type: object
models.UserPreviewJSON:
properties:
user_id:
type: string
username:
type: string
type: object
host: simplecloudnotifier.de host: simplecloudnotifier.de
info: info:
contact: {} contact: {}
@ -748,52 +802,90 @@ paths:
description: All parameter can be set via query-parameter or the json body. description: All parameter can be set via query-parameter or the json body.
Only UserID, UserKey and Title are required Only UserID, UserKey and Title are required
parameters: parameters:
- in: query - example: test
in: query
name: channel
type: string
- example: This is a message
in: query
name: content name: content
type: string type: string
- in: query - example: P3TNH8mvv14fm
in: query
name: key
type: string
- example: db8b0e6a-a08c-4646
in: query
name: msg_id name: msg_id
type: string type: string
- in: query - enum:
- 0
- 1
- 2
example: 1
in: query
name: priority name: priority
type: integer type: integer
- in: query - example: example-server
in: query
name: sender_name
type: string
- example: 1669824037
in: query
name: timestamp name: timestamp
type: number type: number
- in: query - example: Hello World
in: query
name: title name: title
type: string type: string
- in: query - example: "7725"
in: query
name: user_id name: user_id
type: integer
- in: query
name: user_key
type: string type: string
- description: ' ' - description: ' '
in: body in: body
name: post_body name: post_body
schema: schema:
$ref: '#/definitions/handler.SendMessage.combined' $ref: '#/definitions/handler.SendMessage.combined'
- in: formData - example: test
in: formData
name: channel
type: string
- example: This is a message
in: formData
name: content name: content
type: string type: string
- in: formData - example: P3TNH8mvv14fm
in: formData
name: key
type: string
- example: db8b0e6a-a08c-4646
in: formData
name: msg_id name: msg_id
type: string type: string
- in: formData - enum:
- 0
- 1
- 2
example: 1
in: formData
name: priority name: priority
type: integer type: integer
- in: formData - example: example-server
in: formData
name: sender_name
type: string
- example: 1669824037
in: formData
name: timestamp name: timestamp
type: number type: number
- in: formData - example: Hello World
in: formData
name: title name: title
type: string type: string
- in: formData - example: "7725"
in: formData
name: user_id name: user_id
type: integer
- in: formData
name: user_key
type: string type: string
responses: responses:
"200": "200":
@ -1422,6 +1514,108 @@ paths:
summary: Get a single message (untrimmed) summary: Get a single message (untrimmed)
tags: tags:
- API-v2 - API-v2
/api/v2/preview/channels/{cid}:
get:
operationId: api-channels-get-preview
parameters:
- description: ChannelID
in: path
name: cid
required: true
type: string
responses:
"200":
description: OK
schema:
$ref: '#/definitions/models.ChannelPreviewJSON'
"400":
description: supplied values/parameters cannot be parsed / are invalid
schema:
$ref: '#/definitions/ginresp.apiError'
"401":
description: user is not authorized / has missing permissions
schema:
$ref: '#/definitions/ginresp.apiError'
"404":
description: channel not found
schema:
$ref: '#/definitions/ginresp.apiError'
"500":
description: internal server error
schema:
$ref: '#/definitions/ginresp.apiError'
summary: Get a single channel (similar to api-channels-get, but can be called
from anyone and only returns a subset of fields)
tags:
- API-v2
/api/v2/preview/keys/{kid}:
get:
operationId: api-tokenkeys-get-preview
parameters:
- description: TokenKeyID
in: path
name: kid
required: true
type: string
responses:
"200":
description: OK
schema:
$ref: '#/definitions/models.KeyTokenPreviewJSON'
"400":
description: supplied values/parameters cannot be parsed / are invalid
schema:
$ref: '#/definitions/ginresp.apiError'
"401":
description: user is not authorized / has missing permissions
schema:
$ref: '#/definitions/ginresp.apiError'
"404":
description: message not found
schema:
$ref: '#/definitions/ginresp.apiError'
"500":
description: internal server error
schema:
$ref: '#/definitions/ginresp.apiError'
summary: Get a single key (similar to api-tokenkeys-get, but can be called from
anyone and only returns a subset of fields)
tags:
- API-v2
/api/v2/preview/users/{uid}:
get:
operationId: api-user-get-preview
parameters:
- description: UserID
in: path
name: uid
required: true
type: string
responses:
"200":
description: OK
schema:
$ref: '#/definitions/models.UserPreviewJSON'
"400":
description: supplied values/parameters cannot be parsed / are invalid
schema:
$ref: '#/definitions/ginresp.apiError'
"401":
description: user is not authorized / has missing permissions
schema:
$ref: '#/definitions/ginresp.apiError'
"404":
description: user not found
schema:
$ref: '#/definitions/ginresp.apiError'
"500":
description: internal server error
schema:
$ref: '#/definitions/ginresp.apiError'
summary: Get a user (similar to api-user-get, but can be called from anyone
and only returns a subset of fields)
tags:
- API-v2
/api/v2/users: /api/v2/users:
post: post:
operationId: api-user-create operationId: api-user-create
@ -2491,52 +2685,90 @@ paths:
description: All parameter can be set via query-parameter or the json body. description: All parameter can be set via query-parameter or the json body.
Only UserID, UserKey and Title are required Only UserID, UserKey and Title are required
parameters: parameters:
- in: query - example: test
in: query
name: channel
type: string
- example: This is a message
in: query
name: content name: content
type: string type: string
- in: query - example: P3TNH8mvv14fm
in: query
name: key
type: string
- example: db8b0e6a-a08c-4646
in: query
name: msg_id name: msg_id
type: string type: string
- in: query - enum:
- 0
- 1
- 2
example: 1
in: query
name: priority name: priority
type: integer type: integer
- in: query - example: example-server
in: query
name: sender_name
type: string
- example: 1669824037
in: query
name: timestamp name: timestamp
type: number type: number
- in: query - example: Hello World
in: query
name: title name: title
type: string type: string
- in: query - example: "7725"
in: query
name: user_id name: user_id
type: integer
- in: query
name: user_key
type: string type: string
- description: ' ' - description: ' '
in: body in: body
name: post_body name: post_body
schema: schema:
$ref: '#/definitions/handler.SendMessage.combined' $ref: '#/definitions/handler.SendMessage.combined'
- in: formData - example: test
in: formData
name: channel
type: string
- example: This is a message
in: formData
name: content name: content
type: string type: string
- in: formData - example: P3TNH8mvv14fm
in: formData
name: key
type: string
- example: db8b0e6a-a08c-4646
in: formData
name: msg_id name: msg_id
type: string type: string
- in: formData - enum:
- 0
- 1
- 2
example: 1
in: formData
name: priority name: priority
type: integer type: integer
- in: formData - example: example-server
in: formData
name: sender_name
type: string
- example: 1669824037
in: formData
name: timestamp name: timestamp
type: number type: number
- in: formData - example: Hello World
in: formData
name: title name: title
type: string type: string
- in: formData - example: "7725"
in: formData
name: user_id name: user_id
type: integer
- in: formData
name: user_key
type: string type: string
responses: responses:
"200": "200":
@ -2569,47 +2801,85 @@ paths:
description: All parameter can be set via query-parameter or form-data body. description: All parameter can be set via query-parameter or form-data body.
Only UserID, UserKey and Title are required Only UserID, UserKey and Title are required
parameters: parameters:
- in: query - example: test
in: query
name: channel
type: string
- example: This is a message
in: query
name: content name: content
type: string type: string
- in: query - example: P3TNH8mvv14fm
in: query
name: key
type: string
- example: db8b0e6a-a08c-4646
in: query
name: msg_id name: msg_id
type: string type: string
- in: query - enum:
- 0
- 1
- 2
example: 1
in: query
name: priority name: priority
type: integer type: integer
- in: query - example: example-server
in: query
name: sender_name
type: string
- example: 1669824037
in: query
name: timestamp name: timestamp
type: number type: number
- in: query - example: Hello World
in: query
name: title name: title
type: string type: string
- in: query - example: "7725"
in: query
name: user_id name: user_id
type: integer
- in: query
name: user_key
type: string type: string
- in: formData - example: test
in: formData
name: channel
type: string
- example: This is a message
in: formData
name: content name: content
type: string type: string
- in: formData - example: P3TNH8mvv14fm
in: formData
name: key
type: string
- example: db8b0e6a-a08c-4646
in: formData
name: msg_id name: msg_id
type: string type: string
- in: formData - enum:
- 0
- 1
- 2
example: 1
in: formData
name: priority name: priority
type: integer type: integer
- in: formData - example: example-server
in: formData
name: sender_name
type: string
- example: 1669824037
in: formData
name: timestamp name: timestamp
type: number type: number
- in: formData - example: Hello World
in: formData
name: title name: title
type: string type: string
- in: formData - example: "7725"
in: formData
name: user_id name: user_id
type: integer
- in: formData
name: user_key
type: string type: string
responses: responses:
"200": "200":