Skip to content

Commit

Permalink
Updated dependencies and removed usage of json-iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRockettek committed May 12, 2024
1 parent 1302a56 commit 17b8b25
Show file tree
Hide file tree
Showing 24 changed files with 430 additions and 1,234 deletions.
253 changes: 182 additions & 71 deletions go.work.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions welcomer-backend/backend/routes_borderwall.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package backend

import (
"database/sql"
"encoding/json"
"net"
"net/http"
"strconv"
Expand All @@ -16,7 +17,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/gofrs/uuid"
"github.com/jackc/pgtype"
jsoniter "github.com/json-iterator/go"
)

const (
Expand Down Expand Up @@ -247,7 +247,7 @@ func setBorderwall(ctx *gin.Context) {
return
}

data, err := jsoniter.Marshal(welcomer.CustomEventInvokeBorderwallCompletionStructure{
data, err := json.Marshal(welcomer.CustomEventInvokeBorderwallCompletionStructure{
Member: discord.GuildMember{
User: &discord.User{
ID: user.ID,
Expand Down
23 changes: 12 additions & 11 deletions welcomer-backend/backend/routes_guild_settings_welcomer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
_ "embed"
"encoding/json"
"errors"
"fmt"
"image/jpeg"
Expand All @@ -19,7 +20,7 @@ import (
"github.com/WelcomerTeam/Welcomer/welcomer-core/database"
"github.com/gin-gonic/gin"
"github.com/gofrs/uuid"
jsoniter "github.com/json-iterator/go"
"github.com/savsgio/gotils/strconv"
gotils_strconv "github.com/savsgio/gotils/strconv"
)

Expand Down Expand Up @@ -94,17 +95,17 @@ func setGuildSettingsWelcomer(ctx *gin.Context) {
requireGuildElevation(ctx, func(ctx *gin.Context) {
partial := &GuildSettingsWelcomer{}

var file *multipart.FileHeader
var fileValue *multipart.FileHeader
var err error

switch ctx.ContentType() {
case gin.MIMEMultipartPOSTForm:
multipart, err := ctx.MultipartForm()
if err == nil {
file = multipart.File["file"][0]
json := multipart.Value["json"][0]
fileValue = multipart.File["file"][0]
jsonValue := multipart.Value["json"][0]

err = jsoniter.UnmarshalFromString(json, &partial)
err = json.Unmarshal(strconv.S2B(jsonValue), &partial)
if err != nil {
ctx.JSON(http.StatusBadRequest, BaseResponse{
Ok: false,
Expand Down Expand Up @@ -158,7 +159,7 @@ func setGuildSettingsWelcomer(ctx *gin.Context) {
welcomerText, welcomerImages, welcomerDMs := PartialToGuildSettingsWelcomerSettings(int64(guildID), partial)

if welcomerImages.BackgroundName == core.CustomBackgroundPrefix+"upload" {
if file != nil {
if fileValue != nil {
hasWelcomerPro, hasCustomBackgrounds, err := getGuildMembership(guildID)
if err != nil {
backend.Logger.Warn().Err(err).Int("guildID", int(guildID)).Msg("Exception getting welcomer membership")
Expand All @@ -173,7 +174,7 @@ func setGuildSettingsWelcomer(ctx *gin.Context) {
return
}

if file.Size > MaxBackgroundSize {
if fileValue.Size > MaxBackgroundSize {
ctx.JSON(http.StatusRequestEntityTooLarge, BaseResponse{
Ok: false,
Error: ErrBackgroundTooLarge.Error(),
Expand All @@ -182,7 +183,7 @@ func setGuildSettingsWelcomer(ctx *gin.Context) {
return
}

fileOpen, err := file.Open()
fileOpen, err := fileValue.Open()
if err != nil {
ctx.JSON(http.StatusInternalServerError, BaseResponse{
Ok: false,
Expand Down Expand Up @@ -221,7 +222,7 @@ func setGuildSettingsWelcomer(ctx *gin.Context) {
case MIMEGIF, MIMEPNG, MIMEJPEG:
switch {
case mimeType == MIMEGIF && hasWelcomerPro:
res, err = welcomerCustomBackgroundsUploadGIF(ctx, guildID, file, fileOpen)
res, err = welcomerCustomBackgroundsUploadGIF(ctx, guildID, fileValue, fileOpen)
case mimeType == MIMEPNG, mimeType == MIMEGIF && !hasWelcomerPro:
// We will still accept GIFs if they do not have Welcomer Pro, however
// they will be converted to PNG. This saves having to extract the first
Expand All @@ -243,7 +244,7 @@ func setGuildSettingsWelcomer(ctx *gin.Context) {
if err != nil {
backend.Logger.Error().Err(err).
Int64("guild_id", int64(guildID)).
Int64("filesize", file.Size).
Int64("filesize", fileValue.Size).
Str("mimetype", mimeType).
Msg("Failed to upload custom welcomer background")

Expand Down Expand Up @@ -293,7 +294,7 @@ func setGuildSettingsWelcomer(ctx *gin.Context) {
default:
backend.Logger.Info().
Int64("guild_id", int64(guildID)).
Int64("filesize", file.Size).
Int64("filesize", fileValue.Size).
Str("mimetype", mimeType).
Msg("Rejected custom welcomer background")

Expand Down
32 changes: 12 additions & 20 deletions welcomer-backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@ go 1.22
toolchain go1.22.0

require (
github.com/WelcomerTeam/Discord v0.0.0-20240310114051-2a2497c4bbb8
github.com/WelcomerTeam/Discord v0.0.0-20240512183153-c1cea3c12cb0
github.com/WelcomerTeam/Recoder v0.0.0-20221011234038-88363954a5e1
github.com/WelcomerTeam/Sandwich v0.0.0-20240218015658-e9336f7e2117
github.com/WelcomerTeam/Sandwich-Daemon v0.0.0-20240326184703-4a3f5b2612a6
github.com/WelcomerTeam/Sandwich v0.0.0-20240512190355-7bf51cdfead1
github.com/WelcomerTeam/Sandwich-Daemon v0.0.0-20240512185213-73615e5ec7cd
github.com/WelcomerTeam/Welcomer/welcomer-core v0.0.0
github.com/gin-contrib/cache v1.2.0
github.com/gin-contrib/cache v1.3.0
github.com/gin-contrib/gzip v1.0.1
github.com/gin-contrib/logger v1.1.2
github.com/gin-contrib/sessions v1.0.1
github.com/gin-contrib/size v1.0.1
github.com/gin-gonic/gin v1.9.1
github.com/gin-gonic/gin v1.10.0
github.com/gofrs/uuid v4.4.0+incompatible
github.com/jackc/pgtype v1.14.3
github.com/jackc/pgx/v4 v4.18.3
github.com/joho/godotenv v1.5.1
github.com/json-iterator/go v1.1.12
github.com/plutov/paypal/v4 v4.7.1
github.com/rs/zerolog v1.32.0
github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511
Expand All @@ -33,15 +32,13 @@ require (
require (
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect
github.com/WelcomerTeam/Mustachvulate v1.2.1-0.20231218130351-adad26f1e96e // indirect
github.com/WelcomerTeam/Subway v0.0.0-20240217004726-dfb58483e6ea // indirect
github.com/WelcomerTeam/Subway v0.0.0-20240512192535-eedc5ea26d74 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874 // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davidmytton/url-verifier v1.0.1 // indirect
Expand All @@ -53,8 +50,6 @@ require (
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/gomodule/redigo v2.0.0+incompatible // indirect
github.com/gorilla/context v1.1.2 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
Expand All @@ -67,9 +62,9 @@ require (
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
github.com/jackc/puddle v1.3.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/knz/go-libedit v1.10.1 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -80,11 +75,10 @@ require (
github.com/nats-io/nats.go v1.34.1 // indirect
github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/nats-io/stan.go v0.10.4 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.14.0 // indirect
Expand All @@ -96,14 +90,12 @@ require (
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/ultimate-guitar/go-imagequant v0.0.0-20201216103743-29e607cca148 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240429193739-8cf5692501f6 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 // indirect
google.golang.org/protobuf v1.34.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240509183442-62759503f434 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
Loading

0 comments on commit 17b8b25

Please sign in to comment.