Skip to content

Commit

Permalink
add depreciated API routes to let servers know
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintWish committed Sep 28, 2024
1 parent c79e62f commit e30313e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ func Run(args []string) (error) {
ServerUnixHash: a.Hashes.ServerUnix,
ScriptsHash: a.Hashes.Scripts,
})

// API version 2
router.Route(static.APIVersion, func(r chi.Router) {
r.Use(mw.BasicAuth)

Expand Down Expand Up @@ -189,6 +191,24 @@ func Run(args []string) (error) {
}
})

router.Route(static.OldAPIVersion, func(r chi.Router) {
r.Route("/", func(r chi.Router) {
r.Get("/sc/{hash}", con.DepreciatedAPIVersion)
r.Get("/ban/{steamid:[0-9]+}", con.DepreciatedAPIVersion)
r.Get("/map/{name}/{hash}", con.DepreciatedAPIVersion)
r.Get("/ping", con.DepreciatedAPIVersion)

r.Route("/character", func(r chi.Router) {
r.Get("/{steamid:[0-9]+}/{slot:[0-9]}", con.DepreciatedAPIVersion)
r.Get("/export/{steamid:[0-9]+}/{slot:[0-9]}", con.DepreciatedAPIVersion)

r.Post("/", con.DepreciatedAPIVersion)
r.Put("/{uid}", con.DepreciatedAPIVersion)
r.Delete("/{uid}", con.DepreciatedAPIVersion)
})
})
})

/////////////////////////
//Auto certificate
/////////////////////////
Expand Down
5 changes: 5 additions & 0 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,9 @@ func (c *Controller) GetServerVerify(w http.ResponseWriter, r *http.Request) {

c.logger.Warn("Failed server verfication", "IP", r.RemoteAddr)
response.Result(w, false)
}

// DEPRECIATED
func (c *Controller) DepreciatedAPIVersion(w http.ResponseWriter, r *http.Request) {
response.DepreciatedError(w)
}
1 change: 1 addition & 0 deletions internal/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

const (
APIVersion = "/api/v2" // we're on v2 now, v1 used SQLite for database backend.
OldAPIVersion = "/api/v1" // this version was v1.x.x version of the FN server before the rewrite.
)

var (
Expand Down
11 changes: 11 additions & 0 deletions pkg/response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,15 @@ func GenericError(w http.ResponseWriter) {
w: w,
}
resp.SendJson()
}

func DepreciatedError(w http.ResponseWriter) {
resp := Response{
Status: false,
Code: http.StatusUpgradeRequired,
Error: "Server is out of date!",
Data: nil,
w: w,
}
resp.SendJson()
}

0 comments on commit e30313e

Please sign in to comment.