Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Clash Verge
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Clash Verge
Commits
cb8c7057
There was an error fetching the commit references. Please try again later.
Commit
cb8c7057
authored
3 years ago
by
GyDi
Browse files
Options
Downloads
Patches
Plain Diff
feat: only put some fields
parent
2b89b5fe
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src-tauri/src/utils/clash.rs
+46
-14
46 additions, 14 deletions
src-tauri/src/utils/clash.rs
with
46 additions
and
14 deletions
src-tauri/src/utils/clash.rs
+
46
−
14
View file @
cb8c7057
...
...
@@ -4,11 +4,12 @@ use crate::{
events
::
emit
::{
clash_start
,
ClashInfoPayload
},
utils
::{
app_home_dir
,
config
::{
read_clash_controller
,
read_profiles
},
config
::{
read_clash_controller
,
read_profiles
,
read_yaml
,
save_yaml
},
},
};
use
reqwest
::
header
::
HeaderMap
;
use
std
::{
collections
::
HashMap
,
env
::
temp_dir
,
fs
};
use
serde_yaml
::{
Mapping
,
Value
};
use
std
::{
collections
::
HashMap
,
env
::
temp_dir
};
use
tauri
::{
api
::
process
::{
Command
,
CommandEvent
},
AppHandle
,
...
...
@@ -78,21 +79,52 @@ pub async fn put_clash_profile(payload: &ClashInfoPayload) -> Result<(), String>
}
};
// temp profile's path
let
temp_path
=
temp_dir
()
.join
(
"clash-verge-runtime.yaml"
);
// generate temp profile
let
file_name
=
match
profile
.file
{
Some
(
file_name
)
=>
file_name
.clone
(),
None
=>
{
return
Err
(
"the profile item should have `file` field"
.to_string
());
}
};
{
let
file_name
=
match
profile
.file
{
Some
(
file_name
)
=>
file_name
.clone
(),
None
=>
{
return
Err
(
format!
(
"profile item should have `file` field"
));
}
};
let
file_path
=
app_home_dir
()
.join
(
"profiles"
)
.join
(
file_name
);
let
temp_path
=
temp_dir
()
.join
(
"clash-verge-runtime.yaml"
);
let
file_path
=
app_home_dir
()
.join
(
"profiles"
)
.join
(
file_name
);
if
!
file_path
.exists
()
{
return
Err
(
format!
(
"profile `{:?}` not exists"
,
file_path
));
}
if
!
file_path
.exists
()
{
return
Err
(
format!
(
"the profile `{:?}` not exists"
,
file_path
));
// Only the following fields are allowed:
// proxies/proxy-providers/proxy-groups/rule-providers/rules
let
config
=
read_yaml
::
<
Mapping
>
(
file_path
.clone
());
let
mut
new_config
=
Mapping
::
new
();
vec!
[
"proxies"
,
"proxy-providers"
,
"proxy-groups"
,
"rule-providers"
,
"rules"
,
]
.iter
()
.map
(|
item
|
Value
::
String
(
item
.to_string
()))
.for_each
(|
key
|
{
if
config
.contains_key
(
&
key
)
{
let
value
=
config
[
&
key
]
.clone
();
new_config
.insert
(
key
,
value
);
}
});
match
save_yaml
(
temp_path
.clone
(),
&
new_config
,
Some
(
"# Clash Verge Temp File"
),
)
{
Err
(
err
)
=>
return
Err
(
err
),
_
=>
{}
};
}
fs
::
copy
(
file_path
,
temp_path
.clone
())
.unwrap
();
let
ctrl
=
payload
.controller
.clone
()
.unwrap
();
let
server
=
format!
(
"http://{}/configs"
,
ctrl
.server
.unwrap
());
...
...
@@ -113,6 +145,6 @@ pub async fn put_clash_profile(payload: &ClashInfoPayload) -> Result<(), String>
let
client
=
reqwest
::
Client
::
new
();
match
client
.put
(
server
)
.headers
(
headers
)
.json
(
&
data
)
.send
()
.await
{
Ok
(
_
)
=>
Ok
(()),
Err
(
err
)
=>
Err
(
format!
(
"request failed
with status
`{}`"
,
err
.to_string
())),
Err
(
err
)
=>
Err
(
format!
(
"request failed `{}`"
,
err
.to_string
())),
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment