inline very thin function
This commit is contained in:
parent
4116eaf829
commit
f9fb1fb23c
51
src/main.rs
51
src/main.rs
@ -311,21 +311,6 @@ async fn check_or_create_script_poicy(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn do_policy(
|
||||
api:&submissions_api::external::Context,
|
||||
script_ids:&std::collections::HashMap<&str,submissions_api::types::ScriptID>,
|
||||
source:&str,
|
||||
to_script_id:submissions_api::types::ScriptID,
|
||||
policy:submissions_api::types::Policy,
|
||||
)->Result<(),GOCError>{
|
||||
let hash=hash_format(hash_source(source));
|
||||
check_or_create_script_poicy(api,hash.as_str(),submissions_api::types::CreateScriptPolicyRequest{
|
||||
FromScriptID:script_ids[source],
|
||||
ToScriptID:to_script_id,
|
||||
Policy:policy,
|
||||
}).await
|
||||
}
|
||||
|
||||
struct UploadConfig{
|
||||
session_id:String,
|
||||
api_url:String,
|
||||
@ -377,36 +362,42 @@ async fn upload_scripts(config:UploadConfig)->Result<(),ScriptUploadError>{
|
||||
// replace
|
||||
let replace_fut=futures::stream::iter(replace_map.iter().map(Ok))
|
||||
.try_for_each_concurrent(Some(REMOTE_CONCURRENCY),|(source,id)|async{
|
||||
do_policy(
|
||||
check_or_create_script_poicy(
|
||||
api,
|
||||
&script_ids,
|
||||
source,
|
||||
script_ids[allowed_map[id].as_str()],
|
||||
submissions_api::types::Policy::Replace
|
||||
hash_format(hash_source(source)).as_str(),
|
||||
submissions_api::types::CreateScriptPolicyRequest{
|
||||
FromScriptID:script_ids[source.as_str()],
|
||||
ToScriptID:script_ids[allowed_map[id].as_str()],
|
||||
Policy:submissions_api::types::Policy::Replace,
|
||||
}
|
||||
).await.map_err(ScriptUploadError::GOCPolicyReplace)
|
||||
});
|
||||
|
||||
// allowed
|
||||
let allowed_fut=futures::stream::iter(allowed_set.iter().map(Ok))
|
||||
.try_for_each_concurrent(Some(REMOTE_CONCURRENCY),|source|async{
|
||||
do_policy(
|
||||
check_or_create_script_poicy(
|
||||
api,
|
||||
&script_ids,
|
||||
source,
|
||||
script_ids[source.as_str()],
|
||||
submissions_api::types::Policy::Allowed
|
||||
hash_format(hash_source(source)).as_str(),
|
||||
submissions_api::types::CreateScriptPolicyRequest{
|
||||
FromScriptID:script_ids[source.as_str()],
|
||||
ToScriptID:script_ids[source.as_str()],
|
||||
Policy:submissions_api::types::Policy::Allowed,
|
||||
}
|
||||
).await.map_err(ScriptUploadError::GOCPolicyAllowed)
|
||||
});
|
||||
|
||||
// blocked
|
||||
let blocked_fut=futures::stream::iter(blocked_set.iter().map(Ok))
|
||||
.try_for_each_concurrent(Some(REMOTE_CONCURRENCY),|source|async{
|
||||
do_policy(
|
||||
check_or_create_script_poicy(
|
||||
api,
|
||||
&script_ids,
|
||||
source,
|
||||
script_ids[source.as_str()],
|
||||
submissions_api::types::Policy::Blocked
|
||||
hash_format(hash_source(source)).as_str(),
|
||||
submissions_api::types::CreateScriptPolicyRequest{
|
||||
FromScriptID:script_ids[source.as_str()],
|
||||
ToScriptID:script_ids[source.as_str()],
|
||||
Policy:submissions_api::types::Policy::Blocked,
|
||||
}
|
||||
).await.map_err(ScriptUploadError::GOCPolicyBlocked)
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user