fix refresh
This commit is contained in:
parent
43f5f73b04
commit
3d040baeb7
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
|
||||
```
|
||||
|
37
src/data.rs
37
src/data.rs
@ -84,6 +84,7 @@ pub struct Token {
|
||||
#[allow(non_snake_case)]
|
||||
pub struct Data {
|
||||
pub host: String,
|
||||
pub password: String,
|
||||
pub did: String,
|
||||
pub handle: String,
|
||||
pub access: String,
|
||||
@ -129,6 +130,7 @@ pub fn url(s: &str) -> String {
|
||||
let data = Data::new().unwrap();
|
||||
let data = Data {
|
||||
host: data.host,
|
||||
password: data.password,
|
||||
handle: data.handle,
|
||||
did: data.did,
|
||||
access: data.access,
|
||||
@ -194,6 +196,7 @@ pub fn data_toml(s: &str) -> String {
|
||||
let data = Data::new().unwrap();
|
||||
let data = Data {
|
||||
host: data.host,
|
||||
password: data.password,
|
||||
handle: data.handle,
|
||||
did: data.did,
|
||||
access: data.access,
|
||||
@ -201,6 +204,7 @@ pub fn data_toml(s: &str) -> String {
|
||||
};
|
||||
match &*s {
|
||||
"host" => data.handle,
|
||||
"password" => data.password,
|
||||
"handle" => data.handle,
|
||||
"did" => data.did,
|
||||
"access" => data.access,
|
||||
@ -209,8 +213,35 @@ 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,
|
||||
password: data.password,
|
||||
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,
|
||||
@ -490,7 +521,7 @@ pub fn c_char(i: String) -> String {
|
||||
return s;
|
||||
}
|
||||
|
||||
pub fn w_cfg(h: &str, res: &str) {
|
||||
pub fn w_cfg(h: &str, res: &str, password: &str) {
|
||||
let f = data_file(&"json");
|
||||
let ff = data_file(&"toml");
|
||||
let mut f = fs::File::create(f.clone()).unwrap();
|
||||
@ -499,6 +530,7 @@ pub fn w_cfg(h: &str, res: &str) {
|
||||
let json: Token = serde_json::from_str(&res).unwrap();
|
||||
let datas = Data {
|
||||
host: h.to_string(),
|
||||
password: password.to_string(),
|
||||
did: json.did.to_string(),
|
||||
handle: json.handle.to_string(),
|
||||
access: json.accessJwt.to_string(),
|
||||
@ -509,11 +541,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(),
|
||||
|
16
src/main.rs
16
src/main.rs
@ -282,13 +282,13 @@ fn token(c: &Context) {
|
||||
if let Ok(p) = c.string_flag("password") {
|
||||
if let Ok(s) = c.string_flag("server") {
|
||||
let res = token::post_request(m.to_string(), p.to_string(), s.to_string()).await;
|
||||
w_cfg(&s, &res);
|
||||
w_cfg(&s, &res, &p);
|
||||
w_refresh(&res);
|
||||
} else {
|
||||
let res =
|
||||
token::post_request(m.to_string(), p.to_string(), "bsky.social".to_string())
|
||||
.await;
|
||||
w_cfg(&"bsky.social", &res);
|
||||
w_cfg(&"bsky.social", &res, &p);
|
||||
w_refresh(&res);
|
||||
}
|
||||
}
|
||||
@ -303,7 +303,17 @@ fn refresh(_c: &Context) {
|
||||
if session == "err" {
|
||||
let res = refresh::post_request().await;
|
||||
println!("{}", res);
|
||||
w_refresh(&res)
|
||||
if res == "err" {
|
||||
let m = data_toml(&"handle");
|
||||
let p = data_toml(&"password");
|
||||
let s = data_toml(&"host");
|
||||
println!("handle:{}, pass:{}, host:{}", m, p, s);
|
||||
let res = token::post_request(m.to_string(), p.to_string(), s.to_string()).await;
|
||||
w_cfg(&s, &res, &p);
|
||||
println!("res:{}", res);
|
||||
} else {
|
||||
w_refresh(&res);
|
||||
}
|
||||
}
|
||||
};
|
||||
let res = tokio::runtime::Runtime::new().unwrap().block_on(h);
|
||||
|
@ -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