This commit is contained in:
@ -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": []
|
||||
}
|
||||
|
@ -7,3 +7,5 @@ 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
|
||||
AILOG_COLLECTION_COMMENT=ai.syui.log
|
||||
AILOG_COLLECTION_USER=ai.syui.log.user
|
||||
|
@ -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() {
|
||||
<div className="user-details">
|
||||
<h3>{user.displayName || user.handle}</h3>
|
||||
<p className="user-handle">@{user.handle}</p>
|
||||
<p className="user-did">DID: {user.did}</p>
|
||||
<p className="user-did">{user.did}</p>
|
||||
</div>
|
||||
</div>
|
||||
<button onClick={handleLogout} className="logout-button">
|
||||
@ -943,16 +1000,25 @@ function App() {
|
||||
<span className="comment-date">
|
||||
{new Date(record.value.createdAt).toLocaleString()}
|
||||
</span>
|
||||
{/* Show delete button only for current user's comments */}
|
||||
{user && record.value.author?.did === user.did && (
|
||||
<div className="comment-actions">
|
||||
<button
|
||||
onClick={() => handleDeleteComment(record.uri)}
|
||||
className="delete-button"
|
||||
title="Delete comment"
|
||||
onClick={() => toggleJsonDisplay(record.uri)}
|
||||
className="json-button"
|
||||
title="Show/Hide JSON"
|
||||
>
|
||||
🗑️
|
||||
{showJsonFor === record.uri ? '📄' : '📄'}
|
||||
</button>
|
||||
)}
|
||||
{/* Show delete button only for current user's comments */}
|
||||
{user && record.value.author?.did === user.did && (
|
||||
<button
|
||||
onClick={() => handleDeleteComment(record.uri)}
|
||||
className="delete-button"
|
||||
title="Delete comment"
|
||||
>
|
||||
🗑️
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="comment-content">
|
||||
{record.value.text}
|
||||
@ -960,6 +1026,16 @@ function App() {
|
||||
<div className="comment-meta">
|
||||
<small>{record.uri}</small>
|
||||
</div>
|
||||
|
||||
{/* JSON Display */}
|
||||
{showJsonFor === record.uri && (
|
||||
<div className="json-display">
|
||||
<h5>JSON Record:</h5>
|
||||
<pre className="json-content">
|
||||
{JSON.stringify(record, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
|
27
run.zsh
27
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
|
||||
}
|
||||
|
||||
|
@ -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<Vec<String>> {
|
||||
let system_prompt = "You are a content analyzer. Analyze the given content and provide:
|
||||
1. Suggestions for improving the content
|
||||
|
@ -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?;
|
||||
|
@ -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
|
||||
|
@ -20,11 +20,13 @@ pub struct CommentStorage {
|
||||
pub comments: Vec<Comment>,
|
||||
}
|
||||
|
||||
#[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("<div class=\"comments\">\n");
|
||||
html.push_str(" <h3>コメント</h3>\n");
|
||||
|
@ -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;
|
@ -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};
|
||||
|
@ -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<String>,
|
||||
}
|
||||
|
||||
#[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<AuthConfig> {
|
||||
}
|
||||
|
||||
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<AuthConfig> {
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
@ -291,3 +310,30 @@ fn save_config(config: &AuthConfig) -> Result<()> {
|
||||
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()];
|
||||
}
|
@ -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<Vec<UserRecord>> {
|
||||
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<Vec<Value>> {
|
||||
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());
|
||||
|
@ -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)?;
|
||||
|
@ -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,
|
||||
|
@ -3,4 +3,3 @@ pub mod tools;
|
||||
pub mod types;
|
||||
|
||||
pub use server::McpServer;
|
||||
pub use types::*;
|
@ -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 {
|
||||
|
@ -1,5 +1,4 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct McpRequest {
|
||||
|
16
src/oauth.rs
16
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<String> {
|
||||
let now = chrono::Utc::now().timestamp() as usize;
|
||||
let claims = Claims {
|
||||
@ -54,22 +54,24 @@ pub fn create_jwt(oauth_data: &OAuthData) -> Result<String> {
|
||||
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<Claims> {
|
||||
let token_data = decode::<Claims>(
|
||||
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<OAuthCallback>,
|
||||
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<serde_json::Value> {
|
||||
if let Ok(Some(oauth_data)) = session.get::<OAuthData>("oauth_data").await {
|
||||
if let Ok(Some(jwt_token)) = session.get::<String>("jwt_token").await {
|
||||
@ -195,6 +198,7 @@ pub async fn oauth_session_handler(session: Session) -> Json<serde_json::Value>
|
||||
}))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn oauth_logout_handler(session: Session) -> Json<serde_json::Value> {
|
||||
let _ = session.remove::<OAuthData>("oauth_data").await;
|
||||
let _ = session.remove::<String>("jwt_token").await;
|
||||
|
@ -16,6 +16,7 @@ impl TemplateEngine {
|
||||
Ok(Self { tera })
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn create_context(&self, config: &Config, posts: &[Post]) -> Result<Context> {
|
||||
let mut context = Context::new();
|
||||
context.insert("config", &config.site);
|
||||
|
@ -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(),
|
||||
|
@ -41,11 +41,13 @@ pub enum MarkdownSection {
|
||||
}
|
||||
|
||||
pub trait Translator {
|
||||
#[allow(dead_code)]
|
||||
async fn translate(&self, content: &str, config: &TranslationConfig) -> Result<String>;
|
||||
async fn translate_markdown(&self, content: &str, config: &TranslationConfig) -> Result<String>;
|
||||
async fn translate_sections(&self, sections: Vec<MarkdownSection>, config: &TranslationConfig) -> Result<Vec<MarkdownSection>>;
|
||||
}
|
||||
|
||||
#[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<String> {
|
||||
self.mappings.keys().cloned().collect()
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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"
|
||||
|
Reference in New Issue
Block a user