This commit is contained in:
2025-06-17 14:11:27 +09:00
parent 2143d5b142
commit abc42330ed
2 changed files with 17 additions and 31 deletions

View File

@@ -113,7 +113,7 @@ export function getAppConfig(): AppConfig {
const aiEnabled = import.meta.env.VITE_AI_ENABLED === 'true'; const aiEnabled = import.meta.env.VITE_AI_ENABLED === 'true';
const aiAskAi = import.meta.env.VITE_AI_ASK_AI === 'true'; const aiAskAi = import.meta.env.VITE_AI_ASK_AI === 'true';
const aiProvider = import.meta.env.VITE_AI_PROVIDER || 'ollama'; 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 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 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'; const atprotoPds = import.meta.env.VITE_ATPROTO_PDS || 'syu.is';

View File

@@ -41,7 +41,6 @@ class AtprotoOAuthService {
this.oauthClient = await BrowserOAuthClient.load({ this.oauthClient = await BrowserOAuthClient.load({
clientId: clientId, clientId: clientId,
handleResolver: 'https://bsky.social', // Default resolver handleResolver: 'https://bsky.social', // Default resolver
plcDirectoryUrl: 'https://plc.directory', // Default PLC directory
}); });
@@ -177,46 +176,21 @@ class AtprotoOAuthService {
return `${origin}/client-metadata.json`; return `${origin}/client-metadata.json`;
} }
private async detectPDSFromHandle(handle: string): Promise<string> { private detectPDSFromHandle(handle: string): string {
// Handle detection for OAuth PDS routing // Supported PDS hosts and their corresponding handles
// Check if handle ends with known PDS domains first
const pdsMapping = { const pdsMapping = {
'syu.is': 'https://syu.is', 'syu.is': 'https://syu.is',
'bsky.social': 'https://bsky.social', 'bsky.social': 'https://bsky.social',
}; };
// Check if handle ends with known PDS domains
for (const [domain, pdsUrl] of Object.entries(pdsMapping)) { for (const [domain, pdsUrl] of Object.entries(pdsMapping)) {
if (handle.endsWith(`.${domain}`)) { if (handle.endsWith(`.${domain}`)) {
// Using PDS for domain match
return pdsUrl; 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 // Default to bsky.social
// Using default bsky.social
return 'https://bsky.social'; return 'https://bsky.social';
} }
@@ -241,7 +215,13 @@ class AtprotoOAuthService {
// Detect PDS based on handle // Detect PDS based on handle
const pdsUrl = await this.detectPDSFromHandle(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 // OAuth client initialized
@@ -611,4 +591,10 @@ class AtprotoOAuthService {
} }
export const atprotoOAuthService = new 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 }; export type { AtprotoSession };