Skip to content

Commit

Permalink
remove unused API
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed Apr 20, 2024
1 parent a418044 commit c4a669f
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 70 deletions.
9 changes: 0 additions & 9 deletions app/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ func Method(f func(md common.MethodData) common.CodeMessager, privilegesNeeded .
}

func initialCaretaker(c *fasthttp.RequestCtx, f func(md common.MethodData) common.CodeMessager, privilegesNeeded ...int) {
var doggoTags []string

qa := c.Request.URI().QueryArgs()
var token string
var bearerToken bool
Expand Down Expand Up @@ -57,16 +55,9 @@ func initialCaretaker(c *fasthttp.RequestCtx, f func(md common.MethodData) commo
}
if exists {
md.User = tokenReal
doggoTags = append(doggoTags, "authorised")
}
}

// log into datadog that this is an hanayo request
settings := common.GetSettings()
if b2s(c.Request.Header.Peek("H-Key")) == settings.HANAYO_KEY && b2s(c.UserAgent()) == "hanayo" {
doggoTags = append(doggoTags, "hanayo")
}

missingPrivileges := 0
for _, privilege := range privilegesNeeded {
if uint64(md.User.TokenPrivileges)&uint64(privilege) == 0 {
Expand Down
4 changes: 0 additions & 4 deletions app/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ func Start(dbO *sqlx.DB) *fhr.Router {
r.Method("/api/v1/meta/restart", v1.MetaRestartGET, common.PrivilegeAPIMeta)
r.Method("/api/v1/meta/up_since", v1.MetaUpSinceGET, common.PrivilegeAPIMeta)
r.Method("/api/v1/meta/update", v1.MetaUpdateGET, common.PrivilegeAPIMeta)

// User Managing + meta
r.POSTMethod("/api/v1/tokens/fix_privileges", v1.TokenFixPrivilegesPOST,
common.PrivilegeManageUser, common.PrivilegeAPIMeta)
}

// Websocket API
Expand Down
57 changes: 0 additions & 57 deletions app/v1/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
"strconv"
"time"

"github.com/jmoiron/sqlx"
"github.com/osuAkatsuki/akatsuki-api/common"
"golang.org/x/exp/slog"
)

// TokenSelfDeletePOST deletes the token the user is connecting with.
Expand Down Expand Up @@ -159,58 +157,3 @@ func getBearerToken(md common.MethodData) common.CodeMessager {
b.Privileges = md.User.TokenPrivileges
return b
}

// TokenFixPrivilegesPOST fixes the privileges on the token of the given user,
// or of all the users if no user is given.
func TokenFixPrivilegesPOST(md common.MethodData) common.CodeMessager {
id := common.Int(md.Query("id"))
if md.Query("id") == "self" {
id = md.ID()
}
go fixPrivileges(id, md.DB)
return common.SimpleResponse(200, "Privilege fixing started!")
}

func fixPrivileges(user int, db *sqlx.DB) {
var wc string
var params = make([]interface{}, 0, 1)
if user != 0 {
// dirty, but who gives a shit
wc = "WHERE user = ?"
params = append(params, user)
}
rows, err := db.Query(`
SELECT
tokens.id, tokens.privileges, users.privileges
FROM tokens
LEFT JOIN users ON users.id = tokens.user
`+wc, params...)
if err != nil {
slog.Error("Error fetching data", "error", err.Error())
return
}
for rows.Next() {
var (
id int
privsRaw uint64
privs common.Privileges
newPrivs common.Privileges
privilegesRaw uint64
)
err := rows.Scan(&id, &privsRaw, &privilegesRaw)
if err != nil {
slog.Error("Error copying data", "error", err.Error())
continue
}
privileges := common.UserPrivileges(privilegesRaw)
privs = common.Privileges(privsRaw)
newPrivs = privs.CanOnly(privileges)
if newPrivs != privs {
_, err := db.Exec("UPDATE tokens SET privileges = ? WHERE id = ? LIMIT 1", uint64(newPrivs), id)
if err != nil {
slog.Error("Error updating tokens table", "error", err.Error())
continue
}
}
}
}

0 comments on commit c4a669f

Please sign in to comment.