rm shellexpand
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run

This commit is contained in:
2025-06-09 01:32:09 +09:00
parent a17d2c9d66
commit a936d9c0ce
2 changed files with 24 additions and 92 deletions

View File

@ -1,17 +1,9 @@
[package]
name = "aibot"
name = "ai"
authors = ["syui"]
version = "0.1.0"
edition = "2021"
description = "ai.bot - Bluesky AT Protocol Bot"
[[bin]]
name = "aibot"
path = "src/main.rs"
[[bin]]
name = "ai"
path = "src/alias.rs"
description = "latest@2024-08-18"
[dependencies]
seahorse = "*"
@ -27,7 +19,3 @@ rustc-serialize = "*"
toml = "*"
iso8601-timestamp = "*"
sysinfo = "*"
[dev-dependencies]
mockito = "1.2"
tokio-test = "0.4"

View File

@ -8,91 +8,35 @@ use std::io::Write;
use std::path::Path;
pub fn data_file(s: &str) -> String {
// 新しい設定ディレクトリ(優先)
let new_config_dir = "/.config/syui/ai/bot/";
let mut new_path = shellexpand::tilde("~").to_string();
new_path.push_str(&new_config_dir);
// 旧設定ディレクトリ(互換性のため)
let old_config_dir = "/.config/ai/";
let mut old_path = shellexpand::tilde("~").to_string();
old_path.push_str(&old_config_dir);
// 新しいディレクトリを作成
let new_dir = Path::new(&new_path);
if !new_dir.is_dir() {
let _ = fs::create_dir_all(new_path.clone());
let file = "/.config/ai/";
let mut f = shellexpand::tilde("~").to_string();
f.push_str(&file);
let path = Path::new(&f);
if path.is_dir() == false {
let _ = fs::create_dir_all(f.clone());
}
let filename = match &*s {
"toml" => "token.toml",
"json" => "token.json",
"refresh" => "refresh.toml",
_ => &format!(".{}", s),
};
let new_file = new_path.clone() + filename;
let old_file = old_path + filename;
// 新しいパスにファイルが存在する場合は新しいパスを使用
if Path::new(&new_file).exists() {
return new_file;
match &*s {
"toml" => f + &"token.toml",
"json" => f + &"token.json",
"refresh" => f + &"refresh.toml",
_ => f + &"." + &s,
}
// 旧パスにファイルが存在し、新しいパスに存在しない場合は移行を試行
if Path::new(&old_file).exists() && !Path::new(&new_file).exists() {
if let Ok(_) = fs::copy(&old_file, &new_file) {
eprintln!("Migrated config file: {} -> {}", old_file, new_file);
return new_file;
}
}
// デフォルトは新しいパス
new_file
}
pub fn log_file(s: &str) -> String {
// 新しい設定ディレクトリ(優先)
let new_log_dir = "/.config/syui/ai/bot/txt/";
let mut new_path = shellexpand::tilde("~").to_string();
new_path.push_str(&new_log_dir);
// 旧設定ディレクトリ(互換性のため)
let old_log_dir = "/.config/ai/txt/";
let mut old_path = shellexpand::tilde("~").to_string();
old_path.push_str(&old_log_dir);
// 新しいディレクトリを作成
let new_dir = Path::new(&new_path);
if !new_dir.is_dir() {
let _ = fs::create_dir_all(new_path.clone());
let file = "/.config/ai/txt/";
let mut f = shellexpand::tilde("~").to_string();
f.push_str(&file);
let path = Path::new(&f);
if path.is_dir() == false {
let _ = fs::create_dir_all(f.clone());
}
let filename = match &*s {
"n1" => "notify_cid.txt",
"n2" => "notify_cid_run.txt",
"c1" => "comment_cid.txt",
_ => s,
};
let new_file = new_path.clone() + filename;
let old_file = old_path + filename;
// 新しいパスにファイルが存在する場合は新しいパスを使用
if Path::new(&new_file).exists() {
return new_file;
match &*s {
"n1" => f + &"notify_cid.txt",
"n2" => f + &"notify_cid_run.txt",
"c1" => f + &"comment_cid.txt",
_ => f + &s,
}
// 旧パスにファイルが存在し、新しいパスに存在しない場合は移行を試行
if Path::new(&old_file).exists() && !Path::new(&new_file).exists() {
if let Ok(_) = fs::copy(&old_file, &new_file) {
eprintln!("Migrated log file: {} -> {}", old_file, new_file);
return new_file;
}
}
// デフォルトは新しいパス
new_file
}
impl Token {