From abc42330ed5f14c79da939d2e797312c49264285 Mon Sep 17 00:00:00 2001 From: syui Date: Tue, 17 Jun 2025 14:11:27 +0900 Subject: [PATCH] fix --- oauth/src/config/app.ts | 2 +- oauth/src/services/atproto-oauth.ts | 46 ++++++++++------------------- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/oauth/src/config/app.ts b/oauth/src/config/app.ts index 2beb2bc..b73ff51 100644 --- a/oauth/src/config/app.ts +++ b/oauth/src/config/app.ts @@ -113,7 +113,7 @@ export function getAppConfig(): AppConfig { const aiEnabled = import.meta.env.VITE_AI_ENABLED === 'true'; const aiAskAi = import.meta.env.VITE_AI_ASK_AI === 'true'; const aiProvider = import.meta.env.VITE_AI_PROVIDER || 'ollama'; - const aiModel = import.meta.env.VITE_AI_MODEL || 'qwen2.5-coder:latest'; + const aiModel = import.meta.env.VITE_AI_MODEL || 'gemma3:4b'; const aiHost = import.meta.env.VITE_AI_HOST || 'https://ollama.syui.ai'; const aiSystemPrompt = import.meta.env.VITE_AI_SYSTEM_PROMPT || 'You are a helpful AI assistant trained on this blog\'s content.'; const atprotoPds = import.meta.env.VITE_ATPROTO_PDS || 'syu.is'; diff --git a/oauth/src/services/atproto-oauth.ts b/oauth/src/services/atproto-oauth.ts index 44cadd4..f23e86e 100644 --- a/oauth/src/services/atproto-oauth.ts +++ b/oauth/src/services/atproto-oauth.ts @@ -41,7 +41,6 @@ class AtprotoOAuthService { this.oauthClient = await BrowserOAuthClient.load({ clientId: clientId, handleResolver: 'https://bsky.social', // Default resolver - plcDirectoryUrl: 'https://plc.directory', // Default PLC directory }); @@ -177,46 +176,21 @@ class AtprotoOAuthService { return `${origin}/client-metadata.json`; } - private async detectPDSFromHandle(handle: string): Promise { - // Handle detection for OAuth PDS routing - - // Check if handle ends with known PDS domains first + private detectPDSFromHandle(handle: string): string { + // Supported PDS hosts and their corresponding handles const pdsMapping = { 'syu.is': 'https://syu.is', 'bsky.social': 'https://bsky.social', }; + // Check if handle ends with known PDS domains for (const [domain, pdsUrl] of Object.entries(pdsMapping)) { if (handle.endsWith(`.${domain}`)) { - // Using PDS for domain match return pdsUrl; } } - // For handles that don't match domain patterns, resolve via API - try { - // Try to resolve handle to get the actual PDS - const endpoints = ['https://syu.is', 'https://bsky.social']; - - for (const endpoint of endpoints) { - try { - const response = await fetch(`${endpoint}/xrpc/com.atproto.identity.resolveHandle?handle=${encodeURIComponent(handle)}`); - if (response.ok) { - const data = await response.json(); - if (data.did) { - return endpoint; - } - } - } catch (e) { - continue; - } - } - } catch (e) { - // Handle resolution failed, using default - } - // Default to bsky.social - // Using default bsky.social return 'https://bsky.social'; } @@ -241,7 +215,13 @@ class AtprotoOAuthService { // Detect PDS based on handle const pdsUrl = await this.detectPDSFromHandle(handle); - // For all handles, use the default OAuth client (no re-initialization) + // Re-initialize OAuth client with correct PDS if needed + if (pdsUrl !== 'https://bsky.social') { + this.oauthClient = await BrowserOAuthClient.load({ + clientId: this.getClientId(), + handleResolver: pdsUrl, + }); + } // OAuth client initialized @@ -611,4 +591,10 @@ class AtprotoOAuthService { } export const atprotoOAuthService = new AtprotoOAuthService(); + +// Debug: Make service available globally for testing +if (typeof window !== 'undefined') { + (window as any).atprotoOAuthService = atprotoOAuthService; +} + export type { AtprotoSession };