@@ -9,9 +9,7 @@ use crate::{
9
9
use anyhow:: Result ;
10
10
use axum:: {
11
11
extract:: { Extension , Path } ,
12
- http:: header:: ACCESS_CONTROL_ALLOW_ORIGIN ,
13
12
response:: IntoResponse ,
14
- Json ,
15
13
} ;
16
14
use chrono:: { DateTime , Utc } ;
17
15
use serde:: Serialize ;
@@ -79,40 +77,6 @@ pub(crate) async fn build_list_handler(
79
77
. into_response ( ) )
80
78
}
81
79
82
- pub ( crate ) async fn build_list_json_handler (
83
- Path ( ( name, req_version) ) : Path < ( String , String ) > ,
84
- Extension ( pool) : Extension < Pool > ,
85
- ) -> AxumResult < impl IntoResponse > {
86
- let version = match match_version_axum ( & pool, & name, Some ( & req_version) )
87
- . await ?
88
- . exact_name_only ( ) ?
89
- {
90
- MatchSemver :: Exact ( ( version, _) ) | MatchSemver :: Latest ( ( version, _) ) => version,
91
- MatchSemver :: Semver ( ( version, _) ) => {
92
- return Ok ( super :: axum_cached_redirect (
93
- & format ! ( "/crate/{name}/{version}/builds.json" ) ,
94
- CachePolicy :: ForeverInCdn ,
95
- ) ?
96
- . into_response ( ) ) ;
97
- }
98
- } ;
99
-
100
- let builds = spawn_blocking ( {
101
- move || {
102
- let mut conn = pool. get ( ) ?;
103
- get_builds ( & mut conn, & name, & version)
104
- }
105
- } )
106
- . await ?;
107
-
108
- Ok ( (
109
- Extension ( CachePolicy :: NoStoreMustRevalidate ) ,
110
- [ ( ACCESS_CONTROL_ALLOW_ORIGIN , "*" ) ] ,
111
- Json ( builds) ,
112
- )
113
- . into_response ( ) )
114
- }
115
-
116
80
fn get_builds ( conn : & mut postgres:: Client , name : & str , version : & str ) -> Result < Vec < Build > > {
117
81
Ok ( conn
118
82
. query (
@@ -150,7 +114,7 @@ mod tests {
150
114
test:: { assert_cache_control, wrapper, FakeBuild } ,
151
115
web:: cache:: CachePolicy ,
152
116
} ;
153
- use chrono:: { DateTime , Duration , Utc } ;
117
+ use chrono:: Duration ;
154
118
use kuchikiki:: traits:: TendrilSink ;
155
119
use reqwest:: StatusCode ;
156
120
@@ -195,88 +159,6 @@ mod tests {
195
159
} ) ;
196
160
}
197
161
198
- #[ test]
199
- fn build_list_json ( ) {
200
- wrapper ( |env| {
201
- env. fake_release ( )
202
- . name ( "foo" )
203
- . version ( "0.1.0" )
204
- . builds ( vec ! [
205
- FakeBuild :: default ( )
206
- . rustc_version( "rustc (blabla 2019-01-01)" )
207
- . docsrs_version( "docs.rs 1.0.0" ) ,
208
- FakeBuild :: default ( )
209
- . successful( false )
210
- . rustc_version( "rustc (blabla 2020-01-01)" )
211
- . docsrs_version( "docs.rs 2.0.0" ) ,
212
- FakeBuild :: default ( )
213
- . rustc_version( "rustc (blabla 2021-01-01)" )
214
- . docsrs_version( "docs.rs 3.0.0" ) ,
215
- ] )
216
- . create ( ) ?;
217
-
218
- let response = env. frontend ( ) . get ( "/crate/foo/0.1.0/builds.json" ) . send ( ) ?;
219
- assert_cache_control ( & response, CachePolicy :: NoStoreMustRevalidate , & env. config ( ) ) ;
220
- let value: serde_json:: Value = serde_json:: from_str ( & response. text ( ) ?) ?;
221
-
222
- assert_eq ! ( value. pointer( "/0/build_status" ) , Some ( & true . into( ) ) ) ;
223
- assert_eq ! (
224
- value. pointer( "/0/docsrs_version" ) ,
225
- Some ( & "docs.rs 3.0.0" . into( ) )
226
- ) ;
227
- assert_eq ! (
228
- value. pointer( "/0/rustc_version" ) ,
229
- Some ( & "rustc (blabla 2021-01-01)" . into( ) )
230
- ) ;
231
- assert ! ( value. pointer( "/0/id" ) . unwrap( ) . is_i64( ) ) ;
232
- assert ! ( serde_json:: from_value:: <DateTime <Utc >>(
233
- value. pointer( "/0/build_time" ) . unwrap( ) . clone( )
234
- )
235
- . is_ok( ) ) ;
236
-
237
- assert_eq ! ( value. pointer( "/1/build_status" ) , Some ( & false . into( ) ) ) ;
238
- assert_eq ! (
239
- value. pointer( "/1/docsrs_version" ) ,
240
- Some ( & "docs.rs 2.0.0" . into( ) )
241
- ) ;
242
- assert_eq ! (
243
- value. pointer( "/1/rustc_version" ) ,
244
- Some ( & "rustc (blabla 2020-01-01)" . into( ) )
245
- ) ;
246
- assert ! ( value. pointer( "/1/id" ) . unwrap( ) . is_i64( ) ) ;
247
- assert ! ( serde_json:: from_value:: <DateTime <Utc >>(
248
- value. pointer( "/1/build_time" ) . unwrap( ) . clone( )
249
- )
250
- . is_ok( ) ) ;
251
-
252
- assert_eq ! ( value. pointer( "/2/build_status" ) , Some ( & true . into( ) ) ) ;
253
- assert_eq ! (
254
- value. pointer( "/2/docsrs_version" ) ,
255
- Some ( & "docs.rs 1.0.0" . into( ) )
256
- ) ;
257
- assert_eq ! (
258
- value. pointer( "/2/rustc_version" ) ,
259
- Some ( & "rustc (blabla 2019-01-01)" . into( ) )
260
- ) ;
261
- assert ! ( value. pointer( "/2/id" ) . unwrap( ) . is_i64( ) ) ;
262
- assert ! ( serde_json:: from_value:: <DateTime <Utc >>(
263
- value. pointer( "/2/build_time" ) . unwrap( ) . clone( )
264
- )
265
- . is_ok( ) ) ;
266
-
267
- assert ! (
268
- value. pointer( "/1/build_time" ) . unwrap( ) . as_str( ) . unwrap( )
269
- < value. pointer( "/0/build_time" ) . unwrap( ) . as_str( ) . unwrap( )
270
- ) ;
271
- assert ! (
272
- value. pointer( "/2/build_time" ) . unwrap( ) . as_str( ) . unwrap( )
273
- < value. pointer( "/1/build_time" ) . unwrap( ) . as_str( ) . unwrap( )
274
- ) ;
275
-
276
- Ok ( ( ) )
277
- } ) ;
278
- }
279
-
280
162
#[ test]
281
163
fn limits ( ) {
282
164
wrapper ( |env| {
@@ -355,15 +237,6 @@ mod tests {
355
237
assert ! ( body. contains( "<a href=\" /crate/aquarelle/latest/source/\" " ) ) ;
356
238
assert ! ( body. contains( "<a href=\" /crate/aquarelle/latest\" " ) ) ;
357
239
358
- let resp_json = env
359
- . frontend ( )
360
- . get ( "/crate/aquarelle/latest/builds.json" )
361
- . send ( ) ?;
362
- assert ! ( resp_json
363
- . url( )
364
- . as_str( )
365
- . ends_with( "/crate/aquarelle/latest/builds.json" ) ) ;
366
-
367
240
Ok ( ( ) )
368
241
} ) ;
369
242
}
0 commit comments