@@ -11,7 +11,8 @@ use zip::{result::ZipError, ZipArchive};
11
11
12
12
/// the following env variables control the build process:
13
13
/// 1. SWAGGER_UI_DOWNLOAD_URL:
14
- /// + the url from where to download the swagger-ui zip file
14
+ /// + the url from where to download the swagger-ui zip file if starts with http:// or https://
15
+ /// + the file path from where to copy the swagger-ui zip file if starts with file://
15
16
/// + default value is SWAGGER_UI_DOWNLOAD_URL_DEFAULT
16
17
/// + for other versions, check https://github.com/swagger-api/swagger-ui/tags
17
18
/// 2. SWAGGER_UI_OVERWRITE_FOLDER
@@ -32,10 +33,18 @@ fn main() {
32
33
let zip_path = [ & target_dir, & zip_filename] . iter ( ) . collect :: < PathBuf > ( ) ;
33
34
34
35
if !zip_path. exists ( ) {
35
- println ! ( "start download to : {:?}" , zip_path) ;
36
- download_file ( & url, zip_path. clone ( ) ) . unwrap ( ) ;
36
+ if url. starts_with ( "http://" ) || url. starts_with ( "https://" ) {
37
+ println ! ( "start download to : {:?}" , zip_path) ;
38
+ download_file ( & url, zip_path. clone ( ) ) . unwrap ( ) ;
39
+ } else if url. starts_with ( "file://" ) {
40
+ let file_path = url. replace ( "file://" , "" ) ;
41
+ println ! ( "start copy to : {:?}" , zip_path) ;
42
+ fs:: copy ( file_path, zip_path. clone ( ) ) . unwrap ( ) ;
43
+ } else {
44
+ panic ! ( "invalid SWAGGER_UI_DOWNLOAD_URL: {} -> must start with http:// | https:// | file://" , url) ;
45
+ }
37
46
} else {
38
- println ! ( "already downloaded: {:?}" , zip_path) ;
47
+ println ! ( "already downloaded or copied : {:?}" , zip_path) ;
39
48
}
40
49
41
50
println ! ( "cargo:rerun-if-changed={:?}" , zip_path. clone( ) ) ;
0 commit comments