1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use dotenv;
use reqwest::StatusCode;
use std::process;
use xt_oss::{
oss::entities::website::builder::{
ErrorDocumentBuilder, IndexDocumentBuilder, WebsiteConfigurationBuilder,
},
prelude::*,
};
#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
let options = util::options_from_env();
let client = oss::Client::new(options);
// 构建website配置
let index_document = IndexDocumentBuilder::new()
.with_suffix("index.html")
.with_support_sub_dir(true)
.with_type(0)
.build();
let error_document = ErrorDocumentBuilder::new()
.with_http_status(StatusCode::NOT_FOUND)
.with_key("error.html")
.build();
// let rules = RoutingRulesBuilder::new()
// .with_rule(
// RoutingRuleBuilder::new()
// .with_rule_number(1)
// .with_condition(ConditionBuilder::new().build())
// .with_redirect(RedirectBuilder::new().build())
// .build(),
// )
// .with_rule(
// RoutingRuleBuilder::new()
// .with_rule_number(2)
// .with_condition(ConditionBuilder::new().build())
// .with_redirect(RedirectBuilder::new().build())
// .build(),
// )
// .build();
let config = WebsiteConfigurationBuilder::new()
.with_index_document(index_document)
.with_error_document(error_document)
// .with_routing_rules(rules)
.build();
let result = client
.PutBucketWebsite()
.with_config(config)
.execute()
.await
.unwrap_or_else(|reqwest_error| {
println!("reqwest error: {}", reqwest_error);
process::exit(-1);
});
match result {
Ok(oss_data) => {
println!("{:#?}", oss_data.headers());
}
Err(error_message) => {
println!("{}", error_message.content())
}
}
}