Skip to content

Commit 4804e9c

Browse files
authored
Merge branch 'master' into classic-protocol
2 parents 8a8706a + 37d6844 commit 4804e9c

File tree

5 files changed

+184
-157
lines changed

5 files changed

+184
-157
lines changed

api.go

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ func (app *App) HandleAPIError(err error, c *echo.Context) error {
5050
}
5151

5252
if code == http.StatusNotFound {
53-
path_ := (*c).Request().URL.Path
54-
if version, ok := IsDeprecatedAPIPath(path_).Get(); ok {
55-
switch version {
56-
case 1:
57-
message = "Version 1 of this API was deprecated in release 3.0.0."
58-
default:
59-
message = fmt.Sprintf("Version %d of this API is deprecated.", version)
53+
baseRelative, err := app.BaseRelativePath((*c).Request().URL.Path)
54+
if err == nil {
55+
if version, ok := IsDeprecatedAPIPath(baseRelative).Get(); ok {
56+
switch version {
57+
case 1:
58+
message = "Version 1 of this API was deprecated in release 3.0.0."
59+
default:
60+
message = fmt.Sprintf("Version %d of this API is deprecated.", version)
61+
}
6062
}
6163
}
6264
}
@@ -78,25 +80,12 @@ func (app *App) HandleAPIError(err error, c *echo.Context) error {
7880
return (*c).JSON(code, APIError{Message: message})
7981
}
8082

81-
func IsAPIPath(path_ string) bool {
82-
if path_ == "/" {
83-
return false
84-
}
85-
86-
split := strings.Split(path_, "/")
87-
if len(split) >= 3 && split[1] == "drasl" && split[2] == "api" {
88-
return true
89-
}
90-
91-
return false
92-
}
93-
94-
func IsDeprecatedAPIPath(path_ string) mo.Option[int] {
95-
if path_ == "/" {
83+
func IsDeprecatedAPIPath(baseRelative string) mo.Option[int] {
84+
if baseRelative == "/" {
9685
return mo.None[int]()
9786
}
9887

99-
split := strings.Split(path_, "/")
88+
split := strings.Split(baseRelative, "/")
10089
if len(split) >= 3 && split[1] == "drasl" && split[2] == "api" {
10190
re := regexp.MustCompile(`v(\d+)`)
10291
match := re.FindStringSubmatch(split[3])

build_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package main
22

33
// Build constants
44

5-
const VERSION = "3.4.1"
5+
const VERSION = "3.4.2"
66

77
const REPOSITORY_URL = "https://github.com/unmojang/drasl"
88
const SWAGGER_UI_URL = "https://doc.drasl.unmojang.org"

common.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,13 @@ const (
270270
PathTypeAPI
271271
)
272272

273-
func GetPathType(path_ string) PathType {
274-
if path_ == "/" {
273+
func (app *App) GetPathType(baseRelative string) PathType {
274+
if app.Config.EnableWebFrontEnd && baseRelative == "" {
275275
return PathTypeWeb
276276
}
277277

278-
split := strings.Split(path_, "/")
279-
if len(split) >= 2 && split[1] == "web" {
278+
split := strings.Split(baseRelative, "/")
279+
if app.Config.EnableWebFrontEnd && len(split) >= 2 && split[1] == "web" {
280280
return PathTypeWeb
281281
}
282282
if len(split) >= 3 && split[1] == "drasl" && split[2] == "api" {
@@ -1057,4 +1057,10 @@ func (app *App) RunPeriodicTasks() {
10571057
app.cleanupHeartbeatLRU()
10581058
}
10591059
}()
1060+
func (app *App) BaseRelativePath(path_ string) (string, error) {
1061+
if !strings.HasPrefix(path_, app.BasePath) {
1062+
return "", fmt.Errorf("path %s is not under base path %s", path_, app.BasePath)
1063+
}
1064+
baseRelative := strings.TrimPrefix(path_, app.BasePath)
1065+
return strings.TrimSuffix(baseRelative, "/"), nil
10601066
}

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
{
132132
options.services.drasl = {
133133
enable = mkEnableOption (lib.mdDoc ''drasl'');
134-
package = mkPackageOption { drasl = self.defaultPackage.${pkgs.system}; } "drasl" { };
134+
package = mkPackageOption { drasl = self.defaultPackage.${pkgs.stdenv.hostPlatform.system}; } "drasl" { };
135135
settings = mkOption {
136136
type = format.type;
137137
default = { };

0 commit comments

Comments
 (0)