1
0

fix refresh

This commit is contained in:
syui 2024-02-18 23:33:41 +09:00
parent 43f5f73b04
commit e7f62a95a6
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56
5 changed files with 92 additions and 29 deletions

View File

@ -84,23 +84,3 @@ $ cargo install --force cargo-make
$ cargo make build $ 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
```

View File

@ -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
```

View File

@ -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 { pub fn data_refresh(s: &str) -> String {
let s = String::from(s); 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::new().unwrap();
let refresh = Refresh { let refresh = Refresh {
access: refresh.access, access: refresh.access,
@ -509,11 +535,8 @@ pub fn w_cfg(h: &str, res: &str) {
} }
pub fn w_refresh(res: &str) { pub fn w_refresh(res: &str) {
let f = data_file(&"json");
let ff = data_file(&"refresh"); let ff = data_file(&"refresh");
let mut f = fs::File::create(f.clone()).unwrap();
let mut ff = fs::File::create(ff.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 json: Token = serde_json::from_str(&res).unwrap();
let refreshs = Refresh { let refreshs = Refresh {
access: json.accessJwt.to_string(), access: json.accessJwt.to_string(),

View File

@ -303,7 +303,9 @@ fn refresh(_c: &Context) {
if session == "err" { if session == "err" {
let res = refresh::post_request().await; let res = refresh::post_request().await;
println!("{}", res); println!("{}", res);
w_refresh(&res) if res == "err" {
w_refresh(&res)
}
} }
}; };
let res = tokio::runtime::Runtime::new().unwrap().block_on(h); let res = tokio::runtime::Runtime::new().unwrap().block_on(h);

View File

@ -12,10 +12,17 @@ pub async fn post_request() -> String {
.header("Authorization", "Bearer ".to_owned() + &refresh) .header("Authorization", "Bearer ".to_owned() + &refresh)
.send() .send()
.await .await
.unwrap()
.text()
.await
.unwrap(); .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;
}
}
} }