fix getprofile

This commit is contained in:
2025-06-16 01:57:12 +09:00
parent 60d9e8292c
commit 7cf426e479

View File

@@ -431,9 +431,17 @@ function App() {
if (user.did && user.did.includes('-placeholder')) { if (user.did && user.did.includes('-placeholder')) {
// Resolving placeholder DID // Resolving placeholder DID
try { try {
let profileData;
if (agent) {
const profileResponse = await agent.getProfile({ actor: user.handle });
profileData = profileResponse.data;
} else {
// フォールバックpublic API
const profileResponse = await fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(user.handle)}`); const profileResponse = await fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(user.handle)}`);
if (profileResponse.ok) { if (profileResponse.ok) {
const profileData = await profileResponse.json(); profileData = await profileResponse.json();
}
}
if (profileData.did) { if (profileData.did) {
// Resolved DID // Resolved DID
return { return {
@@ -441,7 +449,6 @@ function App() {
did: profileData.did did: profileData.did
}; };
} }
}
} catch (err) { } catch (err) {
// Failed to resolve DID // Failed to resolve DID
} }
@@ -580,11 +587,18 @@ function App() {
sortedComments.map(async (record) => { sortedComments.map(async (record) => {
if (!record.value.author?.avatar && record.value.author?.handle) { if (!record.value.author?.avatar && record.value.author?.handle) {
try { try {
// Public API でプロフィール取得 let profileData;
if (agent) {
// 認証されたAPIでプロフィール取得
const profileResponse = await agent.getProfile({ actor: record.value.author.handle });
profileData = profileResponse.data;
} else {
// フォールバックpublic API
const profileResponse = await fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(record.value.author.handle)}`); const profileResponse = await fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(record.value.author.handle)}`);
if (profileResponse.ok) { if (profileResponse.ok) {
const profileData = await profileResponse.json(); profileData = await profileResponse.json();
}
}
return { return {
...record, ...record,
value: { value: {
@@ -596,7 +610,6 @@ function App() {
} }
} }
}; };
}
} catch (err) { } catch (err) {
// Ignore enhancement errors // Ignore enhancement errors
} }
@@ -796,14 +809,21 @@ function App() {
let resolvedDid = `did:plc:${handle.replace(/\./g, '-')}-placeholder`; // フォールバック let resolvedDid = `did:plc:${handle.replace(/\./g, '-')}-placeholder`; // フォールバック
try { try {
// Public APIでプロフィールを取得してDIDを解決 let profileData;
if (agent) {
// 認証されたAPIでプロフィールを取得してDIDを解決
const profileResponse = await agent.getProfile({ actor: handle });
profileData = profileResponse.data;
} else {
// フォールバックpublic API
const profileResponse = await fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(handle)}`); const profileResponse = await fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(handle)}`);
if (profileResponse.ok) { if (profileResponse.ok) {
const profileData = await profileResponse.json(); profileData = await profileResponse.json();
}
}
if (profileData.did) { if (profileData.did) {
resolvedDid = profileData.did; resolvedDid = profileData.did;
} }
}
} catch (err) { } catch (err) {
} }
@@ -1534,27 +1554,6 @@ function App() {
</div> </div>
)} )}
{/* User Section - moved from above */}
{user && !appConfig.rkey && (
<div className="user-section">
<div className="user-info">
<div className="user-profile">
<img
src={user.avatar || generatePlaceholderAvatar(user.handle)}
alt="User Avatar"
className="user-avatar"
/>
<div className="user-details">
<h3>{user.displayName || user.handle}</h3>
<p className="user-handle">@{user.handle}</p>
<p className="user-did">{user.did}</p>
</div>
</div>
<button onClick={handleLogout} className="logout-button">
Logout
</button>
</div>
{/* Admin Section - User Management */} {/* Admin Section - User Management */}
{isAdmin(user) && ( {isAdmin(user) && (
<div className="admin-section"> <div className="admin-section">
@@ -1640,9 +1639,6 @@ function App() {
</div> </div>
</div> </div>
)} )}
</div>
)}
</section> </section>
</main> </main>