Skip to content

Commit

Permalink
update get server api
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Apr 9, 2024
1 parent 8fb1426 commit e038049
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions routes/servers/endpoints/get_server/route.go
Expand Up @@ -59,8 +59,8 @@ Officially recognized targets:
Schema: docs.IdSchema,
},
{
Name: "short",
Description: "Avoid sending large fields. Currently this is only the long description of the bot",
Name: "include",
Description: "What extra fields to include, comma-seperated.\n`long` => server long description",
Required: false,
In: "query",
Schema: docs.IdSchema,
Expand Down Expand Up @@ -196,8 +196,25 @@ func Route(d uapi.RouteData, r *http.Request) uapi.HttpResponse {
server.Vanity = code
server.Banner = assetmanager.BannerInfo(assetmanager.AssetTargetTypeServers, server.ServerID)

if r.URL.Query().Get("short") == "true" {
server.Long = ""
// Handle extra includes
if r.URL.Query().Get("include") != "" {
includesSplit := strings.Split(r.URL.Query().Get("include"), ",")

for _, include := range includesSplit {
switch include {
case "long":
// Fetch long description
var long string
err := state.Pool.QueryRow(d.Context, "SELECT long FROM servers WHERE server_id = $1", server.ServerID).Scan(&long)

if err != nil {
state.Logger.Error("Error while getting bot server description [db fetch]", zap.Error(err), zap.String("id", id), zap.String("target", target), zap.String("serverID", server.ServerID))
return uapi.DefaultResponse(http.StatusInternalServerError)
}

server.Long = long
}
}
}

go func() {
Expand Down
2 changes: 1 addition & 1 deletion types/server.go
Expand Up @@ -38,7 +38,7 @@ type Server struct {
TotalMembers int `db:"total_members" json:"total_members" description:"The server's total member count"`
OnlineMembers int `db:"online_members" json:"online_members" description:"The server's online member count"`
Short string `db:"short" json:"short" description:"The server's short description"`
Long string `db:"long" json:"long" description:"The server's long description in raw format (HTML/markdown etc. based on the servers settings)"`
Long string `db:"-" json:"long" description:"The server's long description in raw format (HTML/markdown etc. based on the servers settings). May not be included in responses (e.g. long is not set in include)" ci:"internal"` // Must be parsed internally
Type string `db:"type" json:"type" description:"The server's type (e.g. pending/approved/certified/denied etc.)"`
State string `db:"state" json:"state" description:"The server's state (public, private, unlisted, defunct)"`
Tags []string `db:"tags" json:"tags" description:"The server's tags"`
Expand Down

0 comments on commit e038049

Please sign in to comment.