caelum0x 94bf6dbf48 feat(ritgram): make search/trending/repo surfaces forge-aware for Rithub (Gitea)
Rithub (Gitea) repos were imported into the ritgram DB but most backend
paths and frontend views still assumed GitHub only:

- repositoryService.searchRepositories/getTrending were pure Octokit calls
  (the two endpoints behind /repositories/search and /repositories/trending,
  used by explore/discover/Feed/TrendingRepos) — now merge our own DB (any
  forge) with live GitHub search/trending, with Rithub repos listed first
  since a brand-new Rithub repo has 0 GitHub-scale stars and a pure
  star-sort would always bury it under unrelated GitHub trending noise.
- repositoryController's follow/unfollow/getPosts/getSnippets/getMedia/
  bookmark/update/remove/aitm-settings/etc. all resolved the repo via
  getRepository(owner, name) with no forge param (silently defaulting to
  github) — now thread ?forge= through via a resolveForge(req) helper.
- getActivityTimeline (repo activity feed) had the same default-to-github
  gap — now forge-aware too.
- searchController's repo selects (unifiedSearch/searchAll/searchRepositories/
  getPersonalizedTrending) didn't return `forge`, so the frontend had no way
  to badge or route Gitea rows differently — added `forge`/`htmlUrl` to each.
- trendingAlgorithmService.getTrendingRepositories merged by bare fullName,
  which could wrongly conflate a same-named GitHub and Gitea repo now that
  fullName is only forge-scoped unique — merge key is now `forge:fullName`.
- Added a periodic Gitea repo re-sync (jobs/syncGiteaRepos.ts, every 6h),
  reusing the exact upsert logic from scripts/importGiteaRepos.ts via a new
  shared services/giteaSyncService.ts — one real implementation, idempotent.
- Frontend: RepoCard/RepositorySocialCard/TrendingRepos/search page/trending
  page now show a "Rithub" badge on non-GitHub repos (web/lib/forge.ts).
  Fixed two unrelated pre-existing bugs found while wiring this up: the
  trending page sent invalid tier values (TRENDING_TODAY instead of the
  backend's today/week/hot/rising aliases) and unwrapped the wrong level of
  the {success,data:{...}} response envelope, so every trending panel showed
  "failed to load" / empty regardless of forge.

Verified locally: backend+frontend running against the real ritgram Neon DB,
curled search/trending/repo-detail(?forge=gitea), and a logged-in headless
Chrome screenshot of /search and /trending showing the 14 real Rithub repos
with the "Rithub" badge. tsc --noEmit clean on backend and web.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-11-13 16:15:11 +03:00

125 lines
4.3 KiB
TypeScript

'use client'
import { useEffect, useState } from 'react'
import { useRouter } from 'next/navigation'
import { useAuthStore } from '@/store/authStore'
import { userService } from '@/services/userService'
import api from '@/services/api'
import { useToast } from '@/components/ui/toast'
export default function DeleteAccountPage() {
const router = useRouter()
const { showToast } = useToast()
const { logout } = useAuthStore()
const [confirmText, setConfirmText] = useState('')
const [password, setPassword] = useState('')
// null until known — OAuth-only accounts have no password to re-enter.
const [hasPassword, setHasPassword] = useState<boolean | null>(null)
const [deleting, setDeleting] = useState(false)
useEffect(() => {
let active = true
api
.get('/v1/auth/me')
.then(({ data }) => {
if (active) setHasPassword(Boolean(data?.user?.password))
})
.catch(() => {
// Fall back to showing the field; the backend says if it is required.
if (active) setHasPassword(true)
})
return () => {
active = false
}
}, [])
const handleDelete = async () => {
if (confirmText !== 'DELETE') {
showToast('Please type DELETE to confirm', 'warning')
return
}
if (hasPassword && !password) {
showToast('Please enter your password to confirm', 'warning')
return
}
setDeleting(true)
try {
await userService.deleteAccount(hasPassword ? password : undefined)
await logout()
router.push('/login')
} catch (error) {
console.error('Delete account error:', error)
const message = (error as { response?: { data?: { message?: string; error?: string } } })
?.response?.data?.message
showToast(message || 'Failed to delete account', 'error')
} finally {
setDeleting(false)
}
}
return (
<div className="min-h-screen bg-background">
<div className="max-w-2xl mx-auto py-8 px-4">
<h1 className="text-2xl font-bold text-foreground mb-4">Delete Account</h1>
<div className="bg-red-500/10 border border-red-500 rounded-lg p-6 mb-6">
<p className="text-red-500 mb-4">
Warning: This action cannot be undone. All your data will be permanently deleted.
</p>
<p className="text-foreground/70">
This includes all your posts, reels, messages, and other data associated with your account.
</p>
</div>
<div className="space-y-4">
{hasPassword && (
<div>
<label className="block text-sm font-medium text-foreground mb-2">
Confirm with your password
</label>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
autoComplete="current-password"
className="w-full px-4 py-2 bg-surface border border-border rounded-lg text-foreground focus:outline-none focus:ring-2 focus:ring-red-500"
placeholder="Password"
/>
</div>
)}
<div>
<label className="block text-sm font-medium text-foreground mb-2">
Type <strong>DELETE</strong> to confirm
</label>
<input
type="text"
value={confirmText}
onChange={(e) => setConfirmText(e.target.value)}
className="w-full px-4 py-2 bg-surface border border-border rounded-lg text-foreground focus:outline-none focus:ring-2 focus:ring-red-500"
placeholder="DELETE"
/>
</div>
<div className="flex gap-4">
<button
onClick={handleDelete}
disabled={deleting || confirmText !== 'DELETE'}
className="px-6 py-2 bg-red-500 text-white rounded-lg font-semibold hover:opacity-90 disabled:opacity-50"
>
{deleting ? 'Deleting...' : 'Delete Account'}
</button>
<button
onClick={() => router.back()}
className="px-6 py-2 bg-surface border border-border rounded-lg text-foreground hover:bg-surface/80"
>
Cancel
</button>
</div>
</div>
</div>
</div>
)
}