fix refresh
This commit is contained in:
parent
43f5f73b04
commit
a2251c8af3
20
README.md
20
README.md
@ -84,23 +84,3 @@ $ cargo install --force cargo-make
|
||||
$ cargo make build
|
||||
```
|
||||
|
||||
### docker
|
||||
|
||||
```sh
|
||||
$ docker run -it syui/aios ai
|
||||
$ docker run -it -d syui/aios zsh -c "ai login <handle> -p <password> && ai bot"
|
||||
```
|
||||
|
||||
```sh
|
||||
$ cp -rf ~/.config/ai ./.config/
|
||||
|
||||
$ docker compose up
|
||||
```
|
||||
|
||||
### cron
|
||||
|
||||
```sh
|
||||
$ sudo pacman -S fcron
|
||||
$ fcrontab -e
|
||||
* * * * * $HOME/bot/test/ai.zsh c
|
||||
```
|
||||
|
53
docs/wiki.md
53
docs/wiki.md
@ -1 +1,52 @@
|
||||
##
|
||||
### docker
|
||||
|
||||
```sh
|
||||
$ docker run -it syui/aios ai
|
||||
$ docker run -it -d syui/aios zsh -c "ai login <handle> -p <password> && ai bot"
|
||||
```
|
||||
|
||||
```sh
|
||||
$ cp -rf ~/.config/ai ./.config/
|
||||
|
||||
$ docker compose up
|
||||
```
|
||||
|
||||
### cron
|
||||
|
||||
```sh
|
||||
$ sudo pacman -S fcron
|
||||
$ fcrontab -e
|
||||
* * * * * $HOME/bot/test/ai.zsh c
|
||||
```
|
||||
|
||||
### ssh
|
||||
|
||||
```sh
|
||||
$ ssh-keygen -f /.ssh/diffusers.key -t ed25519
|
||||
```
|
||||
|
||||
```sh
|
||||
FROM syui/aios
|
||||
ADD .ssh /root/.ssh
|
||||
```
|
||||
|
||||
```sh
|
||||
Host diffusers
|
||||
HostName localhost
|
||||
User root
|
||||
IdentityFile ~/.ssh/diffusers.key
|
||||
StrictHostKeyChecking no
|
||||
UserKnownHostsFile /dev/null
|
||||
```
|
||||
|
||||
```sh
|
||||
services:
|
||||
aios:
|
||||
#image: syui/aios
|
||||
build:
|
||||
context: .
|
||||
restart: always
|
||||
volumes:
|
||||
- ./.config:/root/.config
|
||||
command: ai bot -a syui.syu.is
|
||||
```
|
||||
|
29
src/data.rs
29
src/data.rs
@ -209,8 +209,34 @@ pub fn data_toml(s: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn c_refresh(access: &str, refresh: &str) {
|
||||
let ff = data_file(&"refresh");
|
||||
let mut ff = fs::File::create(ff.clone()).unwrap();
|
||||
let refreshs = Refresh {
|
||||
access: access.to_string(),
|
||||
refresh: refresh.to_string(),
|
||||
};
|
||||
let toml = toml::to_string(&refreshs).unwrap();
|
||||
ff.write_all(&toml.as_bytes()).unwrap();
|
||||
}
|
||||
|
||||
pub fn data_refresh(s: &str) -> String {
|
||||
let s = String::from(s);
|
||||
|
||||
let data = Data::new().unwrap();
|
||||
let data = Data {
|
||||
host: data.host,
|
||||
handle: data.handle,
|
||||
did: data.did,
|
||||
access: data.access,
|
||||
refresh: data.refresh,
|
||||
};
|
||||
|
||||
let mut _file = match Refresh::new()
|
||||
{
|
||||
Err(_why) => c_refresh(&data.access, &data.refresh),
|
||||
Ok(_) => println!(""),
|
||||
};
|
||||
let refresh = Refresh::new().unwrap();
|
||||
let refresh = Refresh {
|
||||
access: refresh.access,
|
||||
@ -509,11 +535,8 @@ pub fn w_cfg(h: &str, res: &str) {
|
||||
}
|
||||
|
||||
pub fn w_refresh(res: &str) {
|
||||
let f = data_file(&"json");
|
||||
let ff = data_file(&"refresh");
|
||||
let mut f = fs::File::create(f.clone()).unwrap();
|
||||
let mut ff = fs::File::create(ff.clone()).unwrap();
|
||||
f.write_all(&res.as_bytes()).unwrap();
|
||||
let json: Token = serde_json::from_str(&res).unwrap();
|
||||
let refreshs = Refresh {
|
||||
access: json.accessJwt.to_string(),
|
||||
|
@ -303,8 +303,10 @@ fn refresh(_c: &Context) {
|
||||
if session == "err" {
|
||||
let res = refresh::post_request().await;
|
||||
println!("{}", res);
|
||||
if res != "err" {
|
||||
w_refresh(&res)
|
||||
}
|
||||
}
|
||||
};
|
||||
let res = tokio::runtime::Runtime::new().unwrap().block_on(h);
|
||||
return res;
|
||||
|
@ -12,10 +12,17 @@ pub async fn post_request() -> String {
|
||||
.header("Authorization", "Bearer ".to_owned() + &refresh)
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.text()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
return res;
|
||||
let status_ref = res.error_for_status_ref();
|
||||
|
||||
match status_ref {
|
||||
Ok(_) => {
|
||||
return res.text().await.unwrap();
|
||||
}
|
||||
Err(_e) => {
|
||||
let e = "err".to_string();
|
||||
return e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user