mirror of
https://github.com/yusufipk/RepoHub.git
synced 2026-09-11 18:46:07 +00:00
feat: add multiple package sync sources and API integration
- Added undici dependency and implemented three package fetcher variants (simple text parsing, v2 with better error handling, and official repository sync) - Integrated real API calls in PlatformSelector and PackageBrowser components with fallback to mock data - Extended sync API route to support multiple data sources (debian-simple, ubuntu-simple, debian-official-v2, etc.) with platform initialization
This commit is contained in:
@@ -1,20 +1,90 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { MetadataFetcher } from '@/services/metadataFetcher'
|
||||
import { DebianPackageFetcher } from '@/services/debianPackageFetcher'
|
||||
import { PackageFetcherV2 } from '@/services/packageFetcherV2'
|
||||
import { SimplePackageFetcher } from '@/services/simplePackageFetcher'
|
||||
import { PlatformInitializer } from '@/services/platformInitializer'
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const { platform_id, all_platforms } = body
|
||||
const { platform_id, all_platforms, source } = body
|
||||
|
||||
if (all_platforms) {
|
||||
// Sync all platforms
|
||||
// Initialize platforms first
|
||||
await PlatformInitializer.initializePlatforms()
|
||||
|
||||
if (source === 'debian-simple') {
|
||||
// Sync Debian packages (simple text parsing, no gzip)
|
||||
await SimplePackageFetcher.fetchDebianPackages()
|
||||
return NextResponse.json({
|
||||
message: 'Debian packages synced (simple text parsing)',
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
} else if (source === 'ubuntu-simple') {
|
||||
// Sync Ubuntu packages (simple text parsing, no gzip)
|
||||
await SimplePackageFetcher.fetchUbuntuPackages()
|
||||
return NextResponse.json({
|
||||
message: 'Ubuntu packages synced (simple text parsing)',
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
} else if (source === 'all-simple') {
|
||||
// Sync all Debian-based packages (simple text parsing)
|
||||
await SimplePackageFetcher.syncAll()
|
||||
return NextResponse.json({
|
||||
message: 'All Debian-based packages synced (simple text parsing)',
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
} else if (source === 'debian-official-v2') {
|
||||
// Sync Debian packages from official repository (v2 with better error handling)
|
||||
await PackageFetcherV2.fetchDebianPackages()
|
||||
return NextResponse.json({
|
||||
message: 'Debian packages synced from official repository (v2)',
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
} else if (source === 'ubuntu-official-v2') {
|
||||
// Sync Ubuntu packages from official repository (v2 with better error handling)
|
||||
await PackageFetcherV2.fetchUbuntuPackages()
|
||||
return NextResponse.json({
|
||||
message: 'Ubuntu packages synced from official repository (v2)',
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
} else if (source === 'all-official-v2') {
|
||||
// Sync all Debian-based packages from official repositories (v2)
|
||||
await PackageFetcherV2.syncAll()
|
||||
return NextResponse.json({
|
||||
message: 'All Debian-based packages synced from official repositories (v2)',
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
} else if (source === 'debian-official') {
|
||||
// Sync Debian packages from official repository
|
||||
await DebianPackageFetcher.fetchDebianPackages()
|
||||
return NextResponse.json({
|
||||
message: 'Debian packages synced from official repository',
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
} else if (source === 'ubuntu-official') {
|
||||
// Sync Ubuntu packages from official repository
|
||||
await DebianPackageFetcher.fetchUbuntuPackages()
|
||||
return NextResponse.json({
|
||||
message: 'Ubuntu packages synced from official repository',
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
} else if (source === 'all-official') {
|
||||
// Sync all Debian-based packages from official repositories
|
||||
await DebianPackageFetcher.syncAll()
|
||||
return NextResponse.json({
|
||||
message: 'All Debian-based packages synced from official repositories',
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
} else if (all_platforms) {
|
||||
// Sync all platforms (legacy method)
|
||||
await MetadataFetcher.syncAllPlatforms()
|
||||
return NextResponse.json({
|
||||
message: 'All platforms synced successfully',
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
} else if (platform_id) {
|
||||
// Sync specific platform
|
||||
// Sync specific platform (legacy method)
|
||||
await MetadataFetcher.syncPlatform(platform_id)
|
||||
return NextResponse.json({
|
||||
message: `Platform ${platform_id} synced successfully`,
|
||||
@@ -22,7 +92,7 @@ export async function POST(request: NextRequest) {
|
||||
})
|
||||
} else {
|
||||
return NextResponse.json(
|
||||
{ error: 'Either platform_id or all_platforms must be specified' },
|
||||
{ error: 'Either platform_id, all_platforms, or source must be specified' },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user