Match Windows version discovery response and route forms
This commit is contained in:
1 parent
05e31e7f11
commit
81e074b7c3
2 files changed
+12
-4
No files matched your search
@@ -13,7 +13,7 @@ private struct VersionList: Encodable {
|
||||
let errorCode = 0
|
||||
let serverName = "EzWebServer"
|
||||
let currentVersionName = "3.0.6"
|
||||
let currentStageVersionName = "0"
|
||||
let currentStageVersionName = 0
|
||||
let versions: [APIVersion]
|
||||
}
|
||||
|
||||
@@ -203,7 +203,13 @@ final class LocalServer {
|
||||
"3.0.0", "3.0.1", "3.0.2", "3.0.3", "3.0.4", "3.0.5", "3.0.6"
|
||||
].map { APIVersion(name: $0, url: apiURL, supportStatus: "supported") }
|
||||
let listing = VersionList(versions: versions)
|
||||
let path = target.path.lowercased().trimmingCharacters(in: CharacterSet(charactersIn: "/"))
|
||||
let versionPath = Array(lower.dropFirst(apiPrefix))
|
||||
let versionNameInPath = versionPath.count == 4 &&
|
||||
versionPath.starts(with: ["info", "versionsbyname", "name"]) &&
|
||||
(lower.starts(with: ["api", "v1"]) || apiPrefix == 3) ? segments.last : nil
|
||||
let path = versionNameInPath == nil
|
||||
? target.path.lowercased().trimmingCharacters(in: CharacterSet(charactersIn: "/"))
|
||||
: "api/v1/info/versionsbyname"
|
||||
switch path {
|
||||
case "", "health":
|
||||
send(["service": "EzServer Mac", "status": "ok"], on: connection)
|
||||
@@ -222,7 +228,9 @@ final class LocalServer {
|
||||
case "api/v1/info/versions", "api/index.php/v1/info/versions":
|
||||
send(listing, on: connection)
|
||||
case "api/v1/info/versionsbyname", "api/index.php/v1/info/versionsbyname":
|
||||
let name = target.queryItems?.first(where: { $0.name == "name" })?.value ?? ""
|
||||
let name = versionNameInPath
|
||||
?? target.queryItems?.first(where: { $0.name == "name" })?.value
|
||||
?? ""
|
||||
let match = versions.first { $0.name == name } ?? APIVersion(name: name, url: "", supportStatus: "unknown")
|
||||
send(VersionMatch(clientVersion: match, serverVersion: versions[versions.count - 1]), on: connection)
|
||||
default:
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ if ($path === '/') {
|
||||
|
||||
$patientLookup = getenv('EZSERVER_SQLITE')
|
||||
&& preg_match('~\A/api(?:/index\.php)?/v1/e2ds/patientsbychartno/?\z~i', $path ?? '');
|
||||
if (!$patientLookup && !preg_match('~\A/api(?:/index\.php)?(?:/v1/(?:auth/ping|info/(?:versions|versionsbyname)))?/?\z~i', $path ?? '')) {
|
||||
if (!$patientLookup && !preg_match('~\A/api(?:/index\.php)?(?:/v1/(?:auth/ping|info/(?:versions|versionsbyname(?:/name/[^/]+)?)))?/?\z~i', $path ?? '')) {
|
||||
failRequest(404, 'Route is unavailable in the macOS preview');
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user