From eb5aa0a2bec8b2de89b1750c564df89c9b3676f3 Mon Sep 17 00:00:00 2001 From: syui Date: Wed, 11 Jun 2025 18:27:58 +0900 Subject: [PATCH] fix cargo --- .claude/settings.local.json | 3 +- aicard-web-oauth/.env.production | 4 +- aicard-web-oauth/src/App.tsx | 100 ++++++++++++++++++++++++---- run.zsh | 27 +++----- src/ai/editor.rs | 1 + src/ai/translator.rs | 1 + src/atproto/client.rs | 12 ++-- src/atproto/comment_sync.rs | 3 + src/atproto/mod.rs | 6 +- src/atproto/oauth.rs | 4 ++ src/commands/auth.rs | 52 ++++++++++++++- src/commands/stream.rs | 24 ++++--- src/config.rs | 1 + src/doc_generator.rs | 2 + src/mcp/mod.rs | 3 +- src/mcp/server.rs | 5 +- src/mcp/types.rs | 1 - src/oauth.rs | 16 +++-- src/template.rs | 1 + src/translator/markdown_parser.rs | 4 +- src/translator/mod.rs | 4 ++ src/translator/ollama_translator.rs | 4 +- wrangler.toml | 6 +- 23 files changed, 214 insertions(+), 70 deletions(-) diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 3fce09c..6654e42 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -33,7 +33,8 @@ "Bash(./scripts/test-oauth.sh:*)", "Bash(./run.zsh:*)", "Bash(npm run dev:*)", - "Bash(./target/release/ailog:*)" + "Bash(./target/release/ailog:*)", + "Bash(rg:*)" ], "deny": [] } diff --git a/aicard-web-oauth/.env.production b/aicard-web-oauth/.env.production index cdee24b..c471f07 100644 --- a/aicard-web-oauth/.env.production +++ b/aicard-web-oauth/.env.production @@ -6,4 +6,6 @@ VITE_ADMIN_DID=did:plc:uqzpqmrjnptsxezjx4xuh2mn # Optional: Override collection names (if not set, auto-generated from host) # VITE_COLLECTION_COMMENT=ai.syui.log -# VITE_COLLECTION_USER=ai.syui.log.user \ No newline at end of file +# VITE_COLLECTION_USER=ai.syui.log.user +AILOG_COLLECTION_COMMENT=ai.syui.log +AILOG_COLLECTION_USER=ai.syui.log.user diff --git a/aicard-web-oauth/src/App.tsx b/aicard-web-oauth/src/App.tsx index 98c6404..4f009b5 100644 --- a/aicard-web-oauth/src/App.tsx +++ b/aicard-web-oauth/src/App.tsx @@ -402,8 +402,28 @@ function App() { } const data = await response.json(); - const userComments = data.records || []; - console.log(`Found ${userComments.length} comments from ${user.handle}`); + const userRecords = data.records || []; + console.log(`Found ${userRecords.length} comment records from ${user.handle}`); + + // Flatten comments from new array format + const userComments = []; + for (const record of userRecords) { + if (record.value.comments && Array.isArray(record.value.comments)) { + // New format: array of comments + for (const comment of record.value.comments) { + userComments.push({ + ...record, + value: comment, + originalRecord: record // Keep reference to original record + }); + } + } else if (record.value.text) { + // Old format: single comment + userComments.push(record); + } + } + + console.log(`Flattened to ${userComments.length} individual comments from ${user.handle}`); // ページURLでフィルタリング(指定された場合) const filteredComments = pageUrl @@ -496,8 +516,7 @@ function App() { // Use post rkey if on post page, otherwise use timestamp-based rkey const rkey = appConfig.rkey || now.toISOString().replace(/[:.]/g, '-'); - const record = { - $type: appConfig.collections.comment, + const newComment = { text: commentText, url: window.location.href, createdAt: now.toISOString(), @@ -509,6 +528,44 @@ function App() { }, }; + // Check if record with this rkey already exists + let existingComments = []; + try { + const existingResponse = await agent.api.com.atproto.repo.getRecord({ + repo: user.did, + collection: appConfig.collections.comment, + rkey: rkey, + }); + + // Handle both old single comment format and new array format + if (existingResponse.data.value.comments) { + // New format: array of comments + existingComments = existingResponse.data.value.comments; + } else if (existingResponse.data.value.text) { + // Old format: single comment, convert to array + existingComments = [{ + text: existingResponse.data.value.text, + url: existingResponse.data.value.url, + createdAt: existingResponse.data.value.createdAt, + author: existingResponse.data.value.author, + }]; + } + } catch (err) { + // Record doesn't exist yet, that's fine + console.log('No existing record found, creating new one'); + } + + // Add new comment to the array + existingComments.push(newComment); + + // Create the record with comments array + const record = { + $type: appConfig.collections.comment, + comments: existingComments, + url: window.location.href, + createdAt: now.toISOString(), // Latest update time + }; + // Post to ATProto with rkey const response = await agent.api.com.atproto.repo.putRecord({ repo: user.did, @@ -811,7 +868,7 @@ function App() {

{user.displayName || user.handle}

@{user.handle}

-

DID: {user.did}

+

{user.did}

- )} + {/* Show delete button only for current user's comments */} + {user && record.value.author?.did === user.did && ( + + )} +
{record.value.text} @@ -960,6 +1026,16 @@ function App() {
{record.uri}
+ + {/* JSON Display */} + {showJsonFor === record.uri && ( +
+
JSON Record:
+
+                        {JSON.stringify(record, null, 2)}
+                      
+
+ )}
)) )} diff --git a/run.zsh b/run.zsh index 08af257..81f54db 100755 --- a/run.zsh +++ b/run.zsh @@ -1,45 +1,40 @@ #!/bin/zsh -# Simple build script for ai.log -# Usage: ./run.zsh [serve|build|oauth|clean|tunnel|all] - function _env() { d=${0:a:h} ailog=$d/target/release/ailog + port=4173 + case $OSTYPE in + darwin*) + export NVM_DIR="$HOME/.nvm" + [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm + [ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion + ;; + esac } function _server() { _env - lsof -ti:4173 | xargs kill -9 2>/dev/null || true + lsof -ti:$port | xargs kill -9 2>/dev/null || true cd $d/my-blog cargo build --release $ailog build - $ailog serve --port 4173 + $ailog serve --port $port } function _server_public() { _env - #cloudflared tunnel --config $d/aicard-web-oauth/cloudflared-config.yml run cloudflared tunnel --config $d/cloudflared-config.yml run } function _oauth_build() { _env cd $d/aicard-web-oauth - export NVM_DIR="$HOME/.nvm" - [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm - [ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion nvm use 21 npm i - - # Build with production environment variables - export VITE_APP_HOST="https://log.syui.ai" - export VITE_OAUTH_CLIENT_ID="https://log.syui.ai/client-metadata.json" - export VITE_OAUTH_REDIRECT_URI="https://log.syui.ai/oauth/callback" - + source .env.production npm run build cp -rf dist/* $d/my-blog/static/ - #cp -rf dist/index.html $d/my-blog/public/ #npm run preview } diff --git a/src/ai/editor.rs b/src/ai/editor.rs index 7ac320d..8ef7671 100644 --- a/src/ai/editor.rs +++ b/src/ai/editor.rs @@ -28,6 +28,7 @@ Only return the enhanced content without explanations."; self.client.chat(system_prompt, &user_prompt).await } + #[allow(dead_code)] pub async fn suggest_improvements(&self, content: &str) -> Result> { let system_prompt = "You are a content analyzer. Analyze the given content and provide: 1. Suggestions for improving the content diff --git a/src/ai/translator.rs b/src/ai/translator.rs index 2073aa9..a52eea4 100644 --- a/src/ai/translator.rs +++ b/src/ai/translator.rs @@ -21,6 +21,7 @@ impl<'a> Translator<'a> { self.client.chat(&system_prompt, content).await } + #[allow(dead_code)] pub async fn translate_post(&self, title: &str, content: &str, from: &str, to: &str) -> Result<(String, String)> { // Translate title let translated_title = self.translate(title, from, to).await?; diff --git a/src/atproto/client.rs b/src/atproto/client.rs index 60a8ead..38eb0ec 100644 --- a/src/atproto/client.rs +++ b/src/atproto/client.rs @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize}; use reqwest::header::{AUTHORIZATION, CONTENT_TYPE}; #[derive(Debug, Clone)] +#[allow(dead_code)] pub struct AtprotoClient { client: reqwest::Client, handle_resolver: String, @@ -27,8 +28,10 @@ pub struct CommentRecord { #[serde(rename = "$type")] pub record_type: String, pub text: String, - pub createdAt: String, - pub postUri: String, + #[serde(rename = "createdAt")] + pub created_at: String, + #[serde(rename = "postUri")] + pub post_uri: String, pub author: AuthorInfo, } @@ -38,6 +41,7 @@ pub struct AuthorInfo { pub handle: String, } +#[allow(dead_code)] impl AtprotoClient { pub fn new(handle_resolver: String) -> Self { Self { @@ -59,8 +63,8 @@ impl AtprotoClient { let record = CommentRecord { record_type: "app.bsky.feed.post".to_string(), text: text.to_string(), - createdAt: chrono::Utc::now().to_rfc3339(), - postUri: post_uri.to_string(), + created_at: chrono::Utc::now().to_rfc3339(), + post_uri: post_uri.to_string(), author: AuthorInfo { did: did.to_string(), handle: "".to_string(), // Will be resolved by the server diff --git a/src/atproto/comment_sync.rs b/src/atproto/comment_sync.rs index cdcfc35..13515d9 100644 --- a/src/atproto/comment_sync.rs +++ b/src/atproto/comment_sync.rs @@ -20,11 +20,13 @@ pub struct CommentStorage { pub comments: Vec, } +#[allow(dead_code)] pub struct CommentSync { client: AtprotoClient, storage_path: PathBuf, } +#[allow(dead_code)] impl CommentSync { pub fn new(client: AtprotoClient, base_path: PathBuf) -> Self { let storage_path = base_path.join("data/comments.json"); @@ -91,6 +93,7 @@ impl CommentSync { } // Helper to generate comment HTML +#[allow(dead_code)] pub fn render_comments_html(comments: &[Comment]) -> String { let mut html = String::from("
\n"); html.push_str("

コメント

\n"); diff --git a/src/atproto/mod.rs b/src/atproto/mod.rs index 186bf89..8b7ed6f 100644 --- a/src/atproto/mod.rs +++ b/src/atproto/mod.rs @@ -1,7 +1,3 @@ pub mod oauth; pub mod client; -pub mod comment_sync; - -pub use oauth::OAuthHandler; -pub use client::AtprotoClient; -pub use comment_sync::CommentSync; \ No newline at end of file +pub mod comment_sync; \ No newline at end of file diff --git a/src/atproto/oauth.rs b/src/atproto/oauth.rs index d3c4bb0..a3178c9 100644 --- a/src/atproto/oauth.rs +++ b/src/atproto/oauth.rs @@ -21,6 +21,7 @@ pub struct ClientMetadata { } #[derive(Debug, Clone)] +#[allow(dead_code)] pub struct OAuthHandler { config: AtprotoConfig, client: reqwest::Client, @@ -46,6 +47,7 @@ pub struct TokenResponse { pub scope: String, } +#[allow(dead_code)] impl OAuthHandler { pub fn new(config: AtprotoConfig) -> Self { Self { @@ -137,6 +139,7 @@ impl OAuthHandler { } // PKCE helpers +#[allow(dead_code)] pub fn generate_code_verifier() -> String { use rand::Rng; const CHARSET: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"; @@ -150,6 +153,7 @@ pub fn generate_code_verifier() -> String { .collect() } +#[allow(dead_code)] pub fn generate_code_challenge(verifier: &str) -> String { use sha2::{Sha256, Digest}; use base64::{Engine as _, engine::general_purpose}; diff --git a/src/commands/auth.rs b/src/commands/auth.rs index 098e82d..ef0e690 100644 --- a/src/commands/auth.rs +++ b/src/commands/auth.rs @@ -8,6 +8,7 @@ use std::path::PathBuf; pub struct AuthConfig { pub admin: AdminConfig, pub jetstream: JetstreamConfig, + pub collections: CollectionConfig, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -25,6 +26,12 @@ pub struct JetstreamConfig { pub collections: Vec, } +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CollectionConfig { + pub comment: String, + pub user: String, +} + impl Default for AuthConfig { fn default() -> Self { Self { @@ -39,6 +46,10 @@ impl Default for AuthConfig { url: "wss://jetstream2.us-east.bsky.network/subscribe".to_string(), collections: vec!["ai.syui.log".to_string()], }, + collections: CollectionConfig { + comment: "ai.syui.log".to_string(), + user: "ai.syui.log.user".to_string(), + }, } } } @@ -105,6 +116,7 @@ pub async fn init() -> Result<()> { url: "wss://jetstream2.us-east.bsky.network/subscribe".to_string(), collections: vec!["ai.syui.log".to_string()], }, + collections: generate_collection_config(), }; // Save config @@ -208,7 +220,10 @@ pub fn load_config() -> Result { } let config_json = fs::read_to_string(&config_path)?; - let config: AuthConfig = serde_json::from_str(&config_json)?; + let mut config: AuthConfig = serde_json::from_str(&config_json)?; + + // Update collection configuration + update_config_collections(&mut config); Ok(config) } @@ -233,14 +248,18 @@ pub async fn load_config_with_refresh() -> Result { } } + // Update collection configuration + update_config_collections(&mut config); + Ok(config) } async fn test_api_access_with_auth(config: &AuthConfig) -> Result<()> { let client = reqwest::Client::new(); - let url = format!("{}/xrpc/com.atproto.repo.listRecords?repo={}&collection=ai.syui.log&limit=1", + let url = format!("{}/xrpc/com.atproto.repo.listRecords?repo={}&collection={}&limit=1", config.admin.pds, - urlencoding::encode(&config.admin.did)); + urlencoding::encode(&config.admin.did), + urlencoding::encode(&config.collections.comment)); let response = client .get(&url) @@ -290,4 +309,31 @@ fn save_config(config: &AuthConfig) -> Result<()> { let config_json = serde_json::to_string_pretty(config)?; fs::write(&config_path, config_json)?; Ok(()) +} + +// Generate collection names from admin DID or environment +fn generate_collection_config() -> CollectionConfig { + // Check environment variables first + if let (Ok(comment), Ok(user)) = ( + std::env::var("AILOG_COLLECTION_COMMENT"), + std::env::var("AILOG_COLLECTION_USER") + ) { + return CollectionConfig { + comment, + user, + }; + } + + // Default collections + CollectionConfig { + comment: "ai.syui.log".to_string(), + user: "ai.syui.log.user".to_string(), + } +} + +// Update existing config with collection settings +pub fn update_config_collections(config: &mut AuthConfig) { + config.collections = generate_collection_config(); + // Also update jetstream collections to monitor the comment collection + config.jetstream.collections = vec![config.collections.comment.clone()]; } \ No newline at end of file diff --git a/src/commands/stream.rs b/src/commands/stream.rs index df6edcd..897c950 100644 --- a/src/commands/stream.rs +++ b/src/commands/stream.rs @@ -267,7 +267,7 @@ async fn handle_message(text: &str, config: &mut AuthConfig) -> Result<()> { if let (Some(collection), Some(commit), Some(did)) = (&message.collection, &message.commit, &message.did) { - if collection == "ai.syui.log" && commit.operation.as_deref() == Some("create") { + if collection == &config.collections.comment && commit.operation.as_deref() == Some("create") { let unknown_uri = "unknown".to_string(); let uri = commit.uri.as_ref().unwrap_or(&unknown_uri); @@ -358,9 +358,10 @@ async fn update_user_list(config: &mut AuthConfig, did: &str, handle: &str) -> R async fn get_current_user_list(config: &mut AuthConfig) -> Result> { let client = reqwest::Client::new(); - let url = format!("{}/xrpc/com.atproto.repo.listRecords?repo={}&collection=ai.syui.log.user&limit=10", + let url = format!("{}/xrpc/com.atproto.repo.listRecords?repo={}&collection={}&limit=10", config.admin.pds, - urlencoding::encode(&config.admin.did)); + urlencoding::encode(&config.admin.did), + urlencoding::encode(&config.collections.user)); let response = client .get(&url) @@ -416,10 +417,14 @@ async fn post_user_list(config: &mut AuthConfig, users: &[UserRecord], metadata: let client = reqwest::Client::new(); let now = chrono::Utc::now(); - let rkey = now.format("%Y-%m-%dT%H-%M-%S-%3fZ").to_string().replace(".", "-"); + // Extract short ID from DID (did:plc:xxx -> xxx) for rkey + let short_did = config.admin.did + .strip_prefix("did:plc:") + .unwrap_or(&config.admin.did); + let rkey = format!("{}-{}", short_did, now.format("%Y-%m-%dT%H-%M-%S-%3fZ").to_string().replace(".", "-")); let record = UserListRecord { - record_type: "ai.syui.log.user".to_string(), + record_type: config.collections.user.clone(), users: users.to_vec(), created_at: now.to_rfc3339(), updated_by: UserInfo { @@ -433,7 +438,7 @@ async fn post_user_list(config: &mut AuthConfig, users: &[UserRecord], metadata: let request_body = json!({ "repo": config.admin.did, - "collection": "ai.syui.log.user", + "collection": config.collections.user, "rkey": rkey, "record": record }); @@ -674,9 +679,10 @@ async fn poll_comments_periodically(mut config: AuthConfig) -> Result<()> { async fn get_recent_comments(config: &mut AuthConfig) -> Result> { let client = reqwest::Client::new(); - let url = format!("{}/xrpc/com.atproto.repo.listRecords?repo={}&collection=ai.syui.log&limit=20", + let url = format!("{}/xrpc/com.atproto.repo.listRecords?repo={}&collection={}&limit=20", config.admin.pds, - urlencoding::encode(&config.admin.did)); + urlencoding::encode(&config.admin.did), + urlencoding::encode(&config.collections.comment)); if std::env::var("AILOG_DEBUG").is_ok() { println!("{}", format!("🌐 API Request URL: {}", url).yellow()); @@ -757,7 +763,7 @@ pub async fn test_api() -> Result<()> { println!("{}", format!("✅ Successfully retrieved {} comments", comments.len()).green()); if comments.is_empty() { - println!("{}", "ℹ️ No comments found in ai.syui.log collection".blue()); + println!("{}", format!("ℹ️ No comments found in {} collection", config.collections.comment).blue()); println!("💡 Try posting a comment first using the web interface"); } else { println!("{}", "📝 Comment details:".cyan()); diff --git a/src/config.rs b/src/config.rs index 3122af6..d033ca8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -114,6 +114,7 @@ impl Config { } } + #[allow(dead_code)] pub fn save_global(&self) -> Result<()> { let config_dir = Self::global_config_dir(); fs::create_dir_all(&config_dir)?; diff --git a/src/doc_generator.rs b/src/doc_generator.rs index 9956589..d8cac77 100644 --- a/src/doc_generator.rs +++ b/src/doc_generator.rs @@ -3,6 +3,7 @@ use std::path::PathBuf; use crate::analyzer::{ProjectInfo, ApiInfo, ProjectStructure}; use crate::ai::gpt_client::GptClient; +#[allow(dead_code)] pub struct DocGenerator { base_path: PathBuf, ai_enabled: bool, @@ -201,6 +202,7 @@ impl DocGenerator { } #[derive(Debug)] +#[allow(dead_code)] pub struct GitCommit { pub hash: String, pub message: String, diff --git a/src/mcp/mod.rs b/src/mcp/mod.rs index 76574af..1fbb19f 100644 --- a/src/mcp/mod.rs +++ b/src/mcp/mod.rs @@ -2,5 +2,4 @@ pub mod server; pub mod tools; pub mod types; -pub use server::McpServer; -pub use types::*; \ No newline at end of file +pub use server::McpServer; \ No newline at end of file diff --git a/src/mcp/server.rs b/src/mcp/server.rs index 93200e1..47631f9 100644 --- a/src/mcp/server.rs +++ b/src/mcp/server.rs @@ -1,18 +1,17 @@ use anyhow::Result; use axum::{ - extract::{Query, State}, + extract::State, http::StatusCode, response::Json, routing::{get, post}, Router, }; use serde_json::{json, Value}; -use std::collections::HashMap; use std::path::PathBuf; use std::sync::Arc; use tower_http::cors::CorsLayer; -use crate::mcp::types::*; use crate::mcp::tools::BlogTools; +use crate::mcp::types::{McpRequest, McpResponse, McpError, CreatePostRequest, ListPostsRequest, BuildRequest}; #[derive(Clone)] pub struct AppState { diff --git a/src/mcp/types.rs b/src/mcp/types.rs index 4fddecc..bd35c21 100644 --- a/src/mcp/types.rs +++ b/src/mcp/types.rs @@ -1,5 +1,4 @@ use serde::{Deserialize, Serialize}; -use std::collections::HashMap; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct McpRequest { diff --git a/src/oauth.rs b/src/oauth.rs index 10952a5..ac02665 100644 --- a/src/oauth.rs +++ b/src/oauth.rs @@ -1,11 +1,10 @@ use serde::{Deserialize, Serialize}; use tower_sessions::Session; use axum::{ - extract::{Query, State}, - response::{Html, Redirect}, + extract::Query, + response::Html, Json, }; -use std::collections::HashMap; use jsonwebtoken::{encode, decode, Header, Algorithm, Validation, EncodingKey, DecodingKey}; use anyhow::Result; @@ -38,8 +37,9 @@ pub struct Claims { pub iat: usize, } -const JWT_SECRET: &[u8] = b"ailog-oauth-secret-key-2025"; +const _JWT_SECRET: &[u8] = b"ailog-oauth-secret-key-2025"; +#[allow(dead_code)] pub fn create_jwt(oauth_data: &OAuthData) -> Result { let now = chrono::Utc::now().timestamp() as usize; let claims = Claims { @@ -54,22 +54,24 @@ pub fn create_jwt(oauth_data: &OAuthData) -> Result { let token = encode( &Header::default(), &claims, - &EncodingKey::from_secret(JWT_SECRET), + &EncodingKey::from_secret(_JWT_SECRET), )?; Ok(token) } +#[allow(dead_code)] pub fn verify_jwt(token: &str) -> Result { let token_data = decode::( token, - &DecodingKey::from_secret(JWT_SECRET), + &DecodingKey::from_secret(_JWT_SECRET), &Validation::new(Algorithm::HS256), )?; Ok(token_data.claims) } +#[allow(dead_code)] pub async fn oauth_callback_handler( Query(params): Query, session: Session, @@ -179,6 +181,7 @@ pub async fn oauth_callback_handler( Err("No authorization code received".to_string()) } +#[allow(dead_code)] pub async fn oauth_session_handler(session: Session) -> Json { if let Ok(Some(oauth_data)) = session.get::("oauth_data").await { if let Ok(Some(jwt_token)) = session.get::("jwt_token").await { @@ -195,6 +198,7 @@ pub async fn oauth_session_handler(session: Session) -> Json })) } +#[allow(dead_code)] pub async fn oauth_logout_handler(session: Session) -> Json { let _ = session.remove::("oauth_data").await; let _ = session.remove::("jwt_token").await; diff --git a/src/template.rs b/src/template.rs index 17bf582..4cf473f 100644 --- a/src/template.rs +++ b/src/template.rs @@ -16,6 +16,7 @@ impl TemplateEngine { Ok(Self { tera }) } + #[allow(dead_code)] pub fn create_context(&self, config: &Config, posts: &[Post]) -> Result { let mut context = Context::new(); context.insert("config", &config.site); diff --git a/src/translator/markdown_parser.rs b/src/translator/markdown_parser.rs index b765367..d6aa3b9 100644 --- a/src/translator/markdown_parser.rs +++ b/src/translator/markdown_parser.rs @@ -3,7 +3,7 @@ use regex::Regex; use super::MarkdownSection; pub struct MarkdownParser { - code_block_regex: Regex, + _code_block_regex: Regex, header_regex: Regex, link_regex: Regex, image_regex: Regex, @@ -15,7 +15,7 @@ pub struct MarkdownParser { impl MarkdownParser { pub fn new() -> Self { Self { - code_block_regex: Regex::new(r"```([a-zA-Z0-9]*)\n([\s\S]*?)\n```").unwrap(), + _code_block_regex: Regex::new(r"```([a-zA-Z0-9]*)\n([\s\S]*?)\n```").unwrap(), header_regex: Regex::new(r"^(#{1,6})\s+(.+)$").unwrap(), link_regex: Regex::new(r"\[([^\]]+)\]\(([^)]+)\)").unwrap(), image_regex: Regex::new(r"!\[([^\]]*)\]\(([^)]+)\)").unwrap(), diff --git a/src/translator/mod.rs b/src/translator/mod.rs index af24d1a..2643e31 100644 --- a/src/translator/mod.rs +++ b/src/translator/mod.rs @@ -41,11 +41,13 @@ pub enum MarkdownSection { } pub trait Translator { + #[allow(dead_code)] async fn translate(&self, content: &str, config: &TranslationConfig) -> Result; async fn translate_markdown(&self, content: &str, config: &TranslationConfig) -> Result; async fn translate_sections(&self, sections: Vec, config: &TranslationConfig) -> Result>; } +#[allow(dead_code)] pub struct TranslationResult { pub original: String, pub translated: String, @@ -56,6 +58,7 @@ pub struct TranslationResult { } #[derive(Debug, Clone, Default)] +#[allow(dead_code)] pub struct TranslationMetrics { pub character_count: usize, pub word_count: usize, @@ -117,6 +120,7 @@ impl LanguageMapping { self.mappings.get(code) } + #[allow(dead_code)] pub fn get_supported_languages(&self) -> Vec { self.mappings.keys().cloned().collect() } diff --git a/src/translator/ollama_translator.rs b/src/translator/ollama_translator.rs index b58f9f5..25fbc45 100644 --- a/src/translator/ollama_translator.rs +++ b/src/translator/ollama_translator.rs @@ -155,7 +155,7 @@ impl Translator for OllamaTranslator { println!(" 🔤 Processing section {}", index + 1); let translated_section = match §ion { - MarkdownSection::Code(content, lang) => { + MarkdownSection::Code(_content, _lang) => { if config.preserve_code { println!(" ⏭️ Preserving code block"); section // Preserve code blocks @@ -174,7 +174,7 @@ impl Translator for OllamaTranslator { MarkdownSection::Link(translated_text.trim().to_string(), url.clone()) } } - MarkdownSection::Image(alt, url) => { + MarkdownSection::Image(_alt, _url) => { println!(" 🖼️ Preserving image"); section // Preserve images } diff --git a/wrangler.toml b/wrangler.toml index bf40fbc..fbbeb54 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -1,8 +1,8 @@ -name = "ai-log" +name = "ailog" compatibility_date = "2024-01-01" [env.production] -name = "ai-log" +name = "ailog" [build] command = "cargo build --release && ./target/release/ailog build my-blog" @@ -28,4 +28,4 @@ Cache-Control = "public, max-age=31536000, immutable" [[headers]] for = "*.js" [headers.values] -Cache-Control = "public, max-age=31536000, immutable" \ No newline at end of file +Cache-Control = "public, max-age=31536000, immutable"