mirror of
https://github.com/yusufipk/RepoHub.git
synced 2026-09-11 18:46:07 +00:00
feat: add architecture sync script and cheerio dependency
- Added sync:arch npm script to synchronize architecture documentation - Installed cheerio for HTML parsing capabilities - Alphabetized package.json dependencies for better maintainability
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { query } from '@/lib/database/config'
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
// Check if arch platform exists
|
||||
const platformResult = await query(
|
||||
'SELECT * FROM platforms WHERE id = $1',
|
||||
['arch']
|
||||
)
|
||||
|
||||
// Count arch packages
|
||||
const countResult = await query(
|
||||
'SELECT COUNT(*) FROM packages WHERE platform_id = $1',
|
||||
['arch']
|
||||
)
|
||||
|
||||
// Get sample packages
|
||||
const sampleResult = await query(
|
||||
'SELECT name, version, description FROM packages WHERE platform_id = $1 LIMIT 5',
|
||||
['arch']
|
||||
)
|
||||
|
||||
return NextResponse.json({
|
||||
platform: platformResult.rows[0] || null,
|
||||
totalPackages: parseInt(countResult.rows[0].count),
|
||||
samplePackages: sampleResult.rows
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Debug error:', error)
|
||||
return NextResponse.json(
|
||||
{ error: error instanceof Error ? error.message : 'Unknown error' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { ArchPackageFetcher } from '@/services/archPackageFetcher'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
export const maxDuration = 300 // 5 minutes timeout
|
||||
|
||||
let syncInProgress = false
|
||||
let syncStatus = {
|
||||
status: 'idle' as 'idle' | 'fetching' | 'storing' | 'complete' | 'error',
|
||||
fetchProgress: 0,
|
||||
fetchTotal: 0,
|
||||
storeProgress: 0,
|
||||
storeTotal: 0,
|
||||
currentPackage: '',
|
||||
error: null as string | null
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json(syncStatus)
|
||||
}
|
||||
|
||||
export async function POST() {
|
||||
if (syncInProgress) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Sync already in progress' },
|
||||
{ status: 409 }
|
||||
)
|
||||
}
|
||||
|
||||
syncInProgress = true
|
||||
syncStatus = {
|
||||
status: 'fetching',
|
||||
fetchProgress: 0,
|
||||
fetchTotal: 0,
|
||||
storeProgress: 0,
|
||||
storeTotal: 0,
|
||||
currentPackage: '',
|
||||
error: null
|
||||
}
|
||||
|
||||
// Start sync in background
|
||||
;(async () => {
|
||||
try {
|
||||
const fetcher = new ArchPackageFetcher()
|
||||
|
||||
// Fetch packages
|
||||
console.log('🔄 Starting Arch Linux package fetch...')
|
||||
const packages = await fetcher.fetchAllPackages(
|
||||
(current, total, packageName) => {
|
||||
syncStatus.fetchProgress = current
|
||||
syncStatus.fetchTotal = total
|
||||
syncStatus.currentPackage = packageName
|
||||
}
|
||||
)
|
||||
|
||||
console.log(`✅ Fetched ${packages.length} Arch packages`)
|
||||
|
||||
// Store packages
|
||||
syncStatus.status = 'storing'
|
||||
syncStatus.storeTotal = packages.length
|
||||
|
||||
await fetcher.storePackages(
|
||||
packages,
|
||||
(current, total) => {
|
||||
syncStatus.storeProgress = current
|
||||
syncStatus.storeTotal = total
|
||||
}
|
||||
)
|
||||
|
||||
syncStatus.status = 'complete'
|
||||
console.log('✅ Arch Linux sync completed successfully')
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Arch sync error:', error)
|
||||
syncStatus.status = 'error'
|
||||
syncStatus.error = error instanceof Error ? error.message : 'Unknown error'
|
||||
} finally {
|
||||
syncInProgress = false
|
||||
}
|
||||
})()
|
||||
|
||||
return NextResponse.json({
|
||||
message: 'Arch Linux package sync started',
|
||||
status: syncStatus
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user