diff --git a/src/web/components/browser.ts b/src/web/components/browser.ts index 21567f0..d9452d7 100644 --- a/src/web/components/browser.ts +++ b/src/web/components/browser.ts @@ -175,6 +175,24 @@ export function renderRecordList( ` } +// Check if a record needs migration to new format +function needsMigration(value: unknown, collection: string): boolean { + if (!value || typeof value !== 'object') return false + const v = value as Record + + // Only for ai.syui.log.post and ai.syui.log.chat + if (!collection.startsWith('ai.syui.log.')) return false + + // Check: content is a string (old) instead of object (new) + if (typeof v.content === 'string') return true + // Check: has createdAt but no publishedAt + if (v.createdAt && !v.publishedAt) return true + // Check: missing site field + if (!v.site) return true + + return false +} + // Render single record detail export function renderRecordDetail( record: { uri: string; cid: string; value: unknown }, @@ -186,12 +204,18 @@ export function renderRecordDetail( ` : '' + const showMerge = isOwner && needsMigration(record.value, collection) + const mergeBtn = showMerge ? ` + + ` : '' + return `

${collection}

+ ${mergeBtn}

URI: ${record.uri}

CID: ${record.cid}

diff --git a/src/web/components/posts.ts b/src/web/components/posts.ts index 50da3be..1ff5882 100644 --- a/src/web/components/posts.ts +++ b/src/web/components/posts.ts @@ -3,6 +3,17 @@ import { renderMarkdown } from '../lib/markdown' import { renderDiscussion, loadDiscussionPosts } from './discussion' import { getCurrentLang } from './mode-tabs' +// Extract text content from post content (handles both string and object formats) +function getContentText(content: unknown): string { + if (!content) return '' + if (typeof content === 'string') return content + if (typeof content === 'object' && content !== null) { + const obj = content as Record + if (typeof obj.text === 'string') return obj.text + } + return '' +} + // Format date as yyyy/mm/dd function formatDate(dateStr: string): string { const d = new Date(dateStr) @@ -61,6 +72,8 @@ export function renderPostDetail( // Build post URL for discussion search const postUrl = siteUrl ? `${siteUrl}/@${handle}/${rkey}` : `${window.location.origin}/@${handle}/${rkey}` + const rawContent = getContentText(post.value.content) + const editBtn = isOwner ? `` : '' // Get current language and show appropriate content @@ -68,22 +81,22 @@ export function renderPostDetail( const translations = post.value.translations const originalLang = post.value.langs?.[0] || 'ja' - let displayTitle = post.value.title - let displayContent = post.value.content.text + let displayTitle = post.value.title || '' + let displayContent = rawContent // Use translation if available and not original language if (translations && currentLang !== originalLang && translations[currentLang]) { const trans = translations[currentLang] - displayTitle = trans.title || post.value.title - displayContent = trans.content + displayTitle = trans.title || post.value.title || '' + displayContent = trans.content || rawContent } - const content = renderMarkdown(displayContent) + const content = displayContent ? renderMarkdown(displayContent) : '' const editForm = isOwner ? `