Skip to content

Commit a248405

Browse files
Add install helper to map manifest url without query params
1 parent 00eb829 commit a248405

File tree

2 files changed

+211
-3
lines changed

2 files changed

+211
-3
lines changed

Package.resolved

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
{
2+
"pins" : [
3+
{
4+
"identity" : "async-http-client",
5+
"kind" : "remoteSourceControl",
6+
"location" : "https://github.com/swift-server/async-http-client.git",
7+
"state" : {
8+
"revision" : "78db67e5bf4a8543075787f228e8920097319281",
9+
"version" : "1.18.0"
10+
}
11+
},
12+
{
13+
"identity" : "async-kit",
14+
"kind" : "remoteSourceControl",
15+
"location" : "https://github.com/vapor/async-kit.git",
16+
"state" : {
17+
"revision" : "a61da00d404ec91d12766f1b9aac7d90777b484d",
18+
"version" : "1.17.0"
19+
}
20+
},
21+
{
22+
"identity" : "console-kit",
23+
"kind" : "remoteSourceControl",
24+
"location" : "https://github.com/vapor/console-kit.git",
25+
"state" : {
26+
"revision" : "447f1046fb4e9df40973fe426ecb24a6f0e8d3b4",
27+
"version" : "4.6.0"
28+
}
29+
},
30+
{
31+
"identity" : "multipart-kit",
32+
"kind" : "remoteSourceControl",
33+
"location" : "https://github.com/vapor/multipart-kit.git",
34+
"state" : {
35+
"revision" : "1adfd69df2da08f7931d4281b257475e32c96734",
36+
"version" : "4.5.4"
37+
}
38+
},
39+
{
40+
"identity" : "routing-kit",
41+
"kind" : "remoteSourceControl",
42+
"location" : "https://github.com/vapor/routing-kit.git",
43+
"state" : {
44+
"revision" : "611bc45c5dfb1f54b84d99b89d1f72191fb6b71b",
45+
"version" : "4.7.2"
46+
}
47+
},
48+
{
49+
"identity" : "swift-algorithms",
50+
"kind" : "remoteSourceControl",
51+
"location" : "https://github.com/apple/swift-algorithms.git",
52+
"state" : {
53+
"revision" : "b14b7f4c528c942f121c8b860b9410b2bf57825e",
54+
"version" : "1.0.0"
55+
}
56+
},
57+
{
58+
"identity" : "swift-atomics",
59+
"kind" : "remoteSourceControl",
60+
"location" : "https://github.com/apple/swift-atomics.git",
61+
"state" : {
62+
"revision" : "6c89474e62719ddcc1e9614989fff2f68208fe10",
63+
"version" : "1.1.0"
64+
}
65+
},
66+
{
67+
"identity" : "swift-backtrace",
68+
"kind" : "remoteSourceControl",
69+
"location" : "https://github.com/swift-server/swift-backtrace.git",
70+
"state" : {
71+
"revision" : "f25620d5d05e2f1ba27154b40cafea2b67566956",
72+
"version" : "1.3.3"
73+
}
74+
},
75+
{
76+
"identity" : "swift-collections",
77+
"kind" : "remoteSourceControl",
78+
"location" : "https://github.com/apple/swift-collections.git",
79+
"state" : {
80+
"revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2",
81+
"version" : "1.0.4"
82+
}
83+
},
84+
{
85+
"identity" : "swift-crypto",
86+
"kind" : "remoteSourceControl",
87+
"location" : "https://github.com/apple/swift-crypto.git",
88+
"state" : {
89+
"revision" : "33a20e650c33f6d72d822d558333f2085effa3dc",
90+
"version" : "2.5.0"
91+
}
92+
},
93+
{
94+
"identity" : "swift-log",
95+
"kind" : "remoteSourceControl",
96+
"location" : "https://github.com/apple/swift-log.git",
97+
"state" : {
98+
"revision" : "32e8d724467f8fe623624570367e3d50c5638e46",
99+
"version" : "1.5.2"
100+
}
101+
},
102+
{
103+
"identity" : "swift-metrics",
104+
"kind" : "remoteSourceControl",
105+
"location" : "https://github.com/apple/swift-metrics.git",
106+
"state" : {
107+
"revision" : "971ba26378ab69c43737ee7ba967a896cb74c0d1",
108+
"version" : "2.4.1"
109+
}
110+
},
111+
{
112+
"identity" : "swift-nio",
113+
"kind" : "remoteSourceControl",
114+
"location" : "https://github.com/apple/swift-nio.git",
115+
"state" : {
116+
"revision" : "324bc65a28323660fad8a36a7a37f0c2c78eeb9a",
117+
"version" : "2.55.0"
118+
}
119+
},
120+
{
121+
"identity" : "swift-nio-extras",
122+
"kind" : "remoteSourceControl",
123+
"location" : "https://github.com/apple/swift-nio-extras.git",
124+
"state" : {
125+
"revision" : "0e0d0aab665ff1a0659ce75ac003081f2b1c8997",
126+
"version" : "1.19.0"
127+
}
128+
},
129+
{
130+
"identity" : "swift-nio-http2",
131+
"kind" : "remoteSourceControl",
132+
"location" : "https://github.com/apple/swift-nio-http2.git",
133+
"state" : {
134+
"revision" : "a8ccf13fa62775277a5d56844878c828bbb3be1a",
135+
"version" : "1.27.0"
136+
}
137+
},
138+
{
139+
"identity" : "swift-nio-ssl",
140+
"kind" : "remoteSourceControl",
141+
"location" : "https://github.com/apple/swift-nio-ssl.git",
142+
"state" : {
143+
"revision" : "e866a626e105042a6a72a870c88b4c531ba05f83",
144+
"version" : "2.24.0"
145+
}
146+
},
147+
{
148+
"identity" : "swift-nio-transport-services",
149+
"kind" : "remoteSourceControl",
150+
"location" : "https://github.com/apple/swift-nio-transport-services.git",
151+
"state" : {
152+
"revision" : "41f4098903878418537020075a4d8a6e20a0b182",
153+
"version" : "1.17.0"
154+
}
155+
},
156+
{
157+
"identity" : "swift-numerics",
158+
"kind" : "remoteSourceControl",
159+
"location" : "https://github.com/apple/swift-numerics",
160+
"state" : {
161+
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
162+
"version" : "1.0.2"
163+
}
164+
},
165+
{
166+
"identity" : "vapor",
167+
"kind" : "remoteSourceControl",
168+
"location" : "https://github.com/vapor/vapor.git",
169+
"state" : {
170+
"revision" : "1baf62327cc55f55a0767c3a9414dec8ebfdff96",
171+
"version" : "4.77.1"
172+
}
173+
},
174+
{
175+
"identity" : "websocket-kit",
176+
"kind" : "remoteSourceControl",
177+
"location" : "https://github.com/vapor/websocket-kit.git",
178+
"state" : {
179+
"revision" : "53fe0639a98903858d0196b699720decb42aee7b",
180+
"version" : "2.14.0"
181+
}
182+
}
183+
],
184+
"version" : 2
185+
}

Sources/App/routes.swift

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,33 @@ import Vapor
22

33
func routes(_ app: Application) throws {
44
app.get { req async in
5-
"It works!"
5+
"AppBox Install Service Helper"
66
}
77

8-
app.get("hello") { req async -> String in
9-
"Hello, world!"
8+
app.get("install", "**") { req async throws -> ClientResponse in
9+
let pathComponents = req.url.path.components(separatedBy: "/")
10+
var manifestURLString = "https://dl.dropboxusercontent.com"
11+
var manifestURLQueryItems = [URLQueryItem]()
12+
for pathComponent in pathComponents {
13+
if pathComponent.isEmpty || pathComponent == "install" {
14+
continue
15+
} else if pathComponent.hasPrefix("queryparam-") {
16+
let queryParam = pathComponent.replacingOccurrences(of: "queryparam-", with: "").components(separatedBy: "-value-")
17+
guard queryParam.count == 2 else {
18+
continue
19+
}
20+
manifestURLQueryItems.append(.init(name: queryParam[0], value: queryParam[1]))
21+
} else {
22+
manifestURLString.append("/\(pathComponent)")
23+
}
24+
}
25+
var manifestURLComponents = URLComponents(string: manifestURLString)
26+
manifestURLComponents?.queryItems = manifestURLQueryItems
27+
28+
guard let manifestURL = manifestURLComponents?.url else {
29+
throw Abort(.badRequest, reason: "Invalid URL.")
30+
}
31+
32+
return try await req.client.get(.init(stringLiteral: manifestURL.absoluteString))
1033
}
1134
}

0 commit comments

Comments
 (0)