Skip to content

Commit ea8e734

Browse files
committed
Merge remote-tracking branch 'origin/master' into feat-parallel-env-test
# Conflicts: # composer.lock
2 parents 500c145 + cb16574 commit ea8e734

19 files changed

+142
-76
lines changed

templates/cli/package.json.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
"windows-arm64": "pkg -t node16-win-arm64 -o build/appwrite-cli-win-arm64.exe package.json"
2323
},
2424
"dependencies": {
25-
"axios": "^0.24.0",
25+
"axios": "^0.26.1",
2626
"chalk": "4.1.2",
2727
"cli-table3": "^0.6.1",
28-
"commander": "^8.3.0",
28+
"commander": "^9.0.0",
2929
"form-data": "^4.0.0",
30-
"inquirer": "^8.2.0",
30+
"inquirer": "^8.2.1",
3131
"tar": "^6.1.11"
3232
},
3333
"devDependencies": {

templates/flutter/pubspec.yaml.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ dependencies:
1111
flutter:
1212
sdk: flutter
1313
cookie_jar: ^3.0.1
14-
device_info_plus: ^3.2.1
15-
flutter_web_auth: ^0.4.0
14+
device_info_plus: ^3.2.2
15+
flutter_web_auth: ^0.4.1
1616
http: ^0.13.4
1717
package_info_plus: 1.3.0
18-
path_provider: ^2.0.8
18+
path_provider: ^2.0.9
1919
web_socket_channel: ^2.1.0
2020
2121
dev_dependencies:

templates/node/package.json.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"devDependencies": {},
1414
"dependencies": {
15-
"axios": "^0.25.0",
15+
"axios": "^0.26.1",
1616
"form-data": "^4.0.0"
1717
}
1818
}

templates/swift/Sources/Client.swift.twig

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ open class Client {
4545

4646
public init() {
4747
http = Client.createHTTP()
48-
49-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
50-
addUserAgent()
51-
#endif
48+
addUserAgentHeader()
49+
addOriginHeader()
5250
}
5351

5452
private static func createHTTP(
@@ -233,10 +231,6 @@ open class Client {
233231
convert: (([String: Any]) -> T)? = nil,
234232
completion: ((Result<T, {{ spec.title | caseUcfirst }}Error>) -> Void)? = nil
235233
) {
236-
self.headers.merge(headers) { (_, new) in
237-
new
238-
}
239-
240234
let validParams = params.filter { $0.value != nil }
241235

242236
let queryParameters = method == "GET" && !validParams.isEmpty
@@ -258,7 +252,10 @@ open class Client {
258252
return
259253
}
260254

261-
addHeaders(to: &request)
255+
for (key, value) in self.headers.merging(headers, uniquingKeysWith: { $1 }) {
256+
request.headers.add(name: key, value: value)
257+
}
258+
262259
request.addDomainCookies()
263260

264261
if "GET" == method {
@@ -278,12 +275,6 @@ open class Client {
278275
execute(request, withSink: sink, convert: convert, completion: completion)
279276
}
280277

281-
private func addHeaders(to request: inout HTTPClient.Request) {
282-
for (key, value) in self.headers {
283-
request.headers.add(name: key, value: value)
284-
}
285-
}
286-
287278
private func buildBody(
288279
for request: inout HTTPClient.Request,
289280
with params: [String: Any?]
@@ -534,50 +525,76 @@ open class Client {
534525

535526
request.headers.remove(name: "content-type")
536527
if !chunked {
537-
request.headers.add(name: "Content-Length", value: bodyBuffer.readableBytes.description)
528+
request.headers.add(name: "Content-Length", value: bodyBuffer.readableBytes.description)
538529
}
539530
request.headers.add(name: "Content-Type", value: "multipart/form-data;boundary=\"\(Client.boundary)\"")
540531
request.body = .byteBuffer(bodyBuffer)
541532
}
542533

543-
private func addUserAgent() {
534+
private func addUserAgentHeader() {
544535
let packageInfo = OSPackageInfo.get()
545-
let deviceInfo = OSDeviceInfo()
546-
var device = "";
547-
var operatingSystem = ""
536+
let device = Client.getDevice()
537+
538+
#if !os(Linux) && !os(Windows)
539+
_ = addHeader(
540+
key: "user-agent",
541+
value: "\(packageInfo.packageName)/\(packageInfo.version) \(device)"
542+
)
543+
#endif
544+
}
545+
546+
private func addOriginHeader() {
547+
let packageInfo = OSPackageInfo.get()
548+
let operatingSystem = Client.getOperatingSystem()
549+
_ = addHeader(
550+
key: "origin",
551+
value: "{{ spec.title | caseLower }}-\(operatingSystem)://\(packageInfo.packageName)"
552+
)
553+
}
554+
}
548555

556+
extension Client {
557+
private static func getOperatingSystem() -> String {
549558
#if os(iOS)
550-
let iosinfo = deviceInfo.iOSInfo
551-
device = "\(iosinfo!.modelIdentifier) iOS/\(iosinfo!.systemVersion)";
552-
operatingSystem = "ios"
553-
#elseif os(tvOS)
554-
let iosinfo = deviceInfo.iOSInfo
555-
device = "\(iosinfo!.systemInfo.machine) tvOS/\(iosinfo!.systemVersion)";
556-
operatingSystem = "tvos"
559+
return "ios"
557560
#elseif os(watchOS)
558-
let iosinfo = deviceInfo.iOSInfo
559-
device = "\(iosinfo!.systemInfo.machine) watchOS/\(iosinfo!.systemVersion)";
560-
operatingSystem = "watchos"
561+
return "watchos"
562+
#elseif os(tvOS)
563+
return "tvos"
561564
#elseif os(macOS)
562-
let macinfo = deviceInfo.macOSInfo
563-
device = "(Macintosh; \(macinfo!.model))"
564-
operatingSystem = "macos"
565+
return "macos"
565566
#elseif os(Linux)
566-
let lininfo = deviceInfo.linuxInfo
567-
device = "(Linux; U; \(lininfo!.id) \(lininfo!.version))"
568-
operatingSystem = "linux"
567+
return "linux"
569568
#elseif os(Windows)
570-
let wininfo = deviceInfo.windowsInfo
571-
device = "(Windows NT; \(wininfo!.computerName))"
572-
operatingSystem = "windows"
569+
return "windows"
573570
#endif
571+
}
574572

575-
#if !os(Linux) && !os(Windows)
576-
_ = addHeader(
577-
key: "user-agent",
578-
value: "\(packageInfo.packageName)/\(packageInfo.version) \(device)"
579-
)
573+
private static func getDevice() -> String {
574+
let deviceInfo = OSDeviceInfo()
575+
var device = ""
576+
577+
#if os(iOS)
578+
let info = deviceInfo.iOSInfo
579+
device = "\(info!.modelIdentifier) iOS/\(info!.systemVersion)"
580+
#elseif os(watchOS)
581+
let info = deviceInfo.watchOSInfo
582+
device = "\(info!.systemInfo.machine) watchOS/\(info!.systemVersion)"
583+
#elseif os(tvOS)
584+
let info = deviceInfo.tvOSInfo
585+
device = "\(info!.systemInfo.machine) tvOS/\(info!.systemVersion)"
586+
#elseif os(macOS)
587+
let info = deviceInfo.macOSInfo
588+
device = "(Macintosh; \(info!.model))"
589+
#elseif os(Linux)
590+
let info = deviceInfo.linuxInfo
591+
device = "(Linux; U; \(info!.id) \(info!.version))"
592+
#elseif os(Windows)
593+
let info = deviceInfo.windowsInfo
594+
device = "(Windows NT; \(info!.computerName))"
580595
#endif
596+
597+
return device
581598
}
582599
}
583600

templates/swift/Sources/PackageInfo/Linux/PackageInfo+Linux.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ extension PackageInfo {
66
let version = getVersionJson()
77

88
return PackageInfo(
9-
appName: version["app_name"] as! String,
10-
version: version["version"] as! String,
11-
buildNumber: version["build_number"] as! String,
12-
packageName: "",
13-
buildSignature: ""
9+
appName: version?["appName"] as? String ?? "",
10+
version: version?["version"] as? String ?? "",
11+
buildNumber: version?["buildNumber"] as? String ?? "",
12+
packageName: version?["packageName"] as? String ?? "",
13+
buildSignature: version?["buildSignature"] as? String ?? ""
1414
)
1515
}
1616

17-
private static func getVersionJson() -> [String: Any] {
17+
private static func getVersionJson() -> [String: Any]? {
1818
let exePath = URL(fileURLWithPath: "/proc/self/exe").resolvingSymlinksInPath()
1919
let appPath = exePath.deletingLastPathComponent()
2020
let jsonPath = appPath.appendingPathComponent("version.json")
21-
return try! JSONSerialization
22-
.jsonObject(with: Data(contentsOf: jsonPath)) as! [String: Any]
21+
return try? JSONSerialization.jsonObject(with: Data(contentsOf: jsonPath)) as? [String: Any]
2322
}
2423
}
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import Foundation
22

3-
class WindowsPackageInfo : PackageInfo {
3+
extension PackageInfo {
44

55
public static func getWindowsPackage() -> PackageInfo {
6-
return WindowsPackageInfo(
7-
appName: "",
8-
version: "",
9-
buildNumber: "",
10-
packageName: ""
6+
let version = getVersionJson()
7+
return PackageInfo(
8+
appName: version?["appName"] as? String ?? "",
9+
version: version?["version"] as? String ?? "",
10+
buildNumber: version?["buildNumber"] as? String ?? "",
11+
packageName: version?["packageName"] as? String ?? "",
12+
buildSignature: version?["buildSignature"] as? String ?? ""
1113
)
1214
}
15+
16+
private static func getVersionJson() -> [String: Any]? {
17+
let exePath = URL(fileURLWithPath: "/proc/self/exe").resolvingSymlinksInPath()
18+
let appPath = exePath.deletingLastPathComponent()
19+
let jsonPath = appPath.appendingPathComponent("version.json")
20+
return try? JSONSerialization.jsonObject(with: Data(contentsOf: jsonPath)) as? [String: Any]
21+
}
1322
}

tests/Android11Java11Test.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Android11Java11Test extends Base
2020
...Base::GENERAL_RESPONSES,
2121
...Base::LARGE_FILE_RESPONSES,
2222
...Base::EXCEPTION_RESPONSES,
23-
...Base::REALTIME_RESPONSES
23+
...Base::REALTIME_RESPONSES,
24+
...Base::COOKIE_RESPONSES,
2425
];
2526
}

tests/Android11Java8Test.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Android11Java8Test extends Base
2020
...Base::GENERAL_RESPONSES,
2121
...Base::LARGE_FILE_RESPONSES,
2222
...Base::EXCEPTION_RESPONSES,
23-
...Base::REALTIME_RESPONSES
23+
...Base::REALTIME_RESPONSES,
24+
...Base::COOKIE_RESPONSES,
2425
];
2526
}

tests/Android12Java11Test.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Android12Java11Test extends Base
2020
...Base::GENERAL_RESPONSES,
2121
...Base::LARGE_FILE_RESPONSES,
2222
...Base::EXCEPTION_RESPONSES,
23-
...Base::REALTIME_RESPONSES
23+
...Base::REALTIME_RESPONSES,
24+
...Base::COOKIE_RESPONSES,
2425
];
2526
}

tests/Android12Java8Test.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Android12Java8Test extends Base
2020
...Base::GENERAL_RESPONSES,
2121
...Base::LARGE_FILE_RESPONSES,
2222
...Base::EXCEPTION_RESPONSES,
23-
...Base::REALTIME_RESPONSES
23+
...Base::REALTIME_RESPONSES,
24+
...Base::COOKIE_RESPONSES,
2425
];
2526
}

0 commit comments

Comments
 (0)