Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions app/http/endpoints/api/whitelabel/whitelabelstatusdelete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package api

import (
"net/http"

"github.com/TicketsBot-cloud/common/statusupdates"
"github.com/TicketsBot-cloud/dashboard/app"
"github.com/TicketsBot-cloud/dashboard/database"
"github.com/TicketsBot-cloud/dashboard/redis"
"github.com/TicketsBot-cloud/dashboard/utils"
"github.com/gin-gonic/gin"
)

func WhitelabelStatusDelete(c *gin.Context) {
userId := c.Keys["userid"].(uint64)

// Get bot
bot, err := database.Client.Whitelabel.GetByUserId(c, userId)
if err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, app.NewServerError(err))
return
}

// Ensure bot exists
if bot.BotId == 0 {
c.JSON(404, utils.ErrorStr("No bot found"))
return
}

// Update in database
if err := database.Client.WhitelabelStatuses.Delete(c, bot.BotId); err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, app.NewServerError(err))
return
}

// Send status update to sharder
go statusupdates.Publish(redis.Client.Client, bot.BotId)

c.JSON(200, utils.SuccessResponse)
}
2 changes: 2 additions & 0 deletions app/http/endpoints/api/whitelabel/whitelabelstatuspost.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func WhitelabelStatusPost(c *gin.Context) {
user.ActivityTypePlaying,
user.ActivityTypeListening,
user.ActivityTypeWatching,
user.ActivityTypeCompeting,
user.ActivityTypeCustom,
}

if !utils.Contains(validActivities, data.StatusType) {
Expand Down
1 change: 1 addition & 0 deletions app/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func StartServer(logger *zap.Logger, sm *livechat.SocketManager) {

whitelabelGroup.POST("/", rl(middleware.RateLimitTypeUser, 5, time.Minute), api_whitelabel.WhitelabelPost())
whitelabelGroup.POST("/status", rl(middleware.RateLimitTypeUser, 1, time.Second*5), api_whitelabel.WhitelabelStatusPost)
whitelabelGroup.DELETE("/status", rl(middleware.RateLimitTypeUser, 1, time.Second*5), api_whitelabel.WhitelabelStatusDelete)
}
}

Expand Down
12 changes: 6 additions & 6 deletions frontend/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ export default {

replace({
env: JSON.stringify({
CLIENT_ID: process.env.CLIENT_ID,
REDIRECT_URI: process.env.REDIRECT_URI,
API_URL: process.env.API_URL,
WS_URL: process.env.WS_URL,
INVITE_URL: process.env.INVITE_URL,
})
CLIENT_ID: process.env.CLIENT_ID,
REDIRECT_URI: process.env.REDIRECT_URI,
API_URL: process.env.API_URL,
WS_URL: process.env.WS_URL,
INVITE_URL: process.env.INVITE_URL,
})
}),

// In dev mode, call `npm run start` once
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/views/Whitelabel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<option value="0">Playing</option>
<option value="2">Listening</option>
<option value="3">Watching</option>
<option value="5">Competing</option>
<option value="4">Custom</option>
</Dropdown>

<div class="col-2-3">
Expand All @@ -42,6 +44,11 @@
<Button icon="fas fa-paper-plane" on:click={updateStatus} fullWidth="{true}">
Submit
</Button>
{#if bot.status_type != "0" && bot.status != ""}
<Button icon="fas fa-trash-can" on:click={deleteStatus} danger fullWidth="{true}">
Clear Status
</Button>
{/if}
</div>
</form>
</div>
Expand Down Expand Up @@ -251,6 +258,21 @@
notifySuccess('Updated status successfully')
}

async function deleteStatus() {
const res = await axios.delete(`${API_URL}/user/whitelabel/status`);
if (res.status !== 200 || !res.data.success) {
if (res.status === 429) {
notifyRatelimit()
} else {
notifyError(res.data.error)
}

return;
}

notifySuccess('Deleted status successfully')
}

async function loadBot() {
const res = await axios.get(`${API_URL}/user/whitelabel/`);
if (res.status !== 200) {
Expand Down