From 2c08a4acfbd13f6c96675829c8e821a344dc7231 Mon Sep 17 00:00:00 2001 From: syui Date: Wed, 25 Jun 2025 20:17:31 +0900 Subject: [PATCH] test blog profile --- my-blog/static/css/style.css | 39 ++++- my-blog/static/js/ask-ai.js | 77 +++++++++- my-blog/templates/base.html | 2 +- oauth/src/App.css | 103 ++++++++++++- oauth/src/App.jsx | 15 ++ oauth/src/api/atproto.js | 13 +- oauth/src/components/ProfileForm.jsx | 165 +++++++++++++++++++++ oauth/src/components/ProfileRecordList.jsx | 81 ++++++++++ oauth/src/components/RecordTabs.jsx | 55 +++++-- 9 files changed, 525 insertions(+), 25 deletions(-) create mode 100644 oauth/src/components/ProfileForm.jsx create mode 100644 oauth/src/components/ProfileRecordList.jsx diff --git a/my-blog/static/css/style.css b/my-blog/static/css/style.css index d0a80d0..e5731b8 100644 --- a/my-blog/static/css/style.css +++ b/my-blog/static/css/style.css @@ -170,7 +170,7 @@ a.view-markdown:any-link { } .ask-ai-content { - max-width: 1000px; + max-width: 800px; margin: 0 auto; } @@ -200,7 +200,7 @@ a.view-markdown:any-link { /* Main Content */ .main-content { grid-area: main; - max-width: 1000px; + max-width: 800px; margin: 0 auto; padding: 0px; width: 100%; @@ -969,6 +969,41 @@ article.article-content { .question-form { padding: 12px !important; } +} + +/* Profile Display Styles */ +.profile-avatar-fallback { + width: 40px; + height: 40px; + border-radius: 50%; + background: var(--theme-color); + color: var(--white); + display: flex; + align-items: center; + justify-content: center; + font-size: 16px; + font-weight: 700; +} + +.admin-badge { + background: var(--theme-color); + color: var(--white); + font-size: 10px; + padding: 2px 6px; + border-radius: 10px; + font-weight: 500; + margin-left: 8px; +} + +.loading-message, .error-message, .no-profiles { + text-align: center; + padding: 20px; + color: var(--dark-gray); +} + +.error-message { + color: #d32f2f; +} .input-container { flex-direction: column !important; diff --git a/my-blog/static/js/ask-ai.js b/my-blog/static/js/ask-ai.js index 824a3b4..22ecefa 100644 --- a/my-blog/static/js/ask-ai.js +++ b/my-blog/static/js/ask-ai.js @@ -37,10 +37,81 @@ function checkAuthenticationStatus() { document.getElementById('aiQuestion').focus(); }, 50); } else { - // User not authenticated - show auth message - document.getElementById('authCheck').style.display = 'block'; + // User not authenticated - show profiles instead of auth message + document.getElementById('authCheck').style.display = 'none'; document.getElementById('chatForm').style.display = 'none'; - document.getElementById('chatHistory').style.display = 'none'; + document.getElementById('chatHistory').style.display = 'block'; + loadAndShowProfiles(); + } +} + +// Load and display profiles from ai.syui.log.profile collection +async function loadAndShowProfiles() { + const chatHistory = document.getElementById('chatHistory'); + chatHistory.innerHTML = '
Loading profiles...
'; + + try { + const ADMIN_HANDLE = 'ai.syui.ai'; + const OAUTH_COLLECTION = 'ai.syui.log'; + const ATPROTO_PDS = 'syu.is'; + + const response = await fetch(`https://${ATPROTO_PDS}/xrpc/com.atproto.repo.listRecords?repo=${ADMIN_HANDLE}&collection=${OAUTH_COLLECTION}&limit=100`); + + if (!response.ok) { + throw new Error('Failed to fetch profiles'); + } + + const data = await response.json(); + console.log('Fetched records:', data.records); + + // Filter only profile records and sort + const profileRecords = (data.records || []).filter(record => record.value.type === 'profile'); + console.log('Profile records:', profileRecords); + + const profiles = profileRecords.sort((a, b) => { + if (a.value.profileType === 'admin' && b.value.profileType !== 'admin') return -1; + if (a.value.profileType !== 'admin' && b.value.profileType === 'admin') return 1; + return 0; + }); + console.log('Sorted profiles:', profiles); + + // Clear loading message + chatHistory.innerHTML = ''; + + // Display profiles using the same format as chat + profiles.forEach(profile => { + const profileDiv = document.createElement('div'); + profileDiv.className = 'chat-message ai-message comment-style'; + + const avatarElement = profile.value.author.avatar + ? `${profile.value.author.displayName || profile.value.author.handle}` + : `
${(profile.value.author.displayName || profile.value.author.handle || '?').charAt(0).toUpperCase()}
`; + + const adminBadge = profile.value.profileType === 'admin' + ? 'Admin' + : ''; + + profileDiv.innerHTML = ` +
+
${avatarElement}
+ +
+
${profile.value.text}
+ `; + chatHistory.appendChild(profileDiv); + }); + + if (profiles.length === 0) { + chatHistory.innerHTML = '
No profiles available
'; + } + + } catch (error) { + console.error('Error loading profiles:', error); + chatHistory.innerHTML = '
Failed to load profiles. Please try again later.
'; } } diff --git a/my-blog/templates/base.html b/my-blog/templates/base.html index ad9ff3e..fa2d07e 100644 --- a/my-blog/templates/base.html +++ b/my-blog/templates/base.html @@ -61,7 +61,7 @@