import { syncWikiArticles } from '../../../utils/syncWikiArticles.js'

export default defineEventHandler(async (event) => {
  await requireAdmin(event)

  try {
    return await syncWikiArticles()
  } catch (err) {
    console.error('[wiki-sync] Outline fetch failed:', err)
    throw createError({
      statusCode: err.statusCode || 502,
      statusMessage: err.statusMessage || 'Failed to fetch documents from Outline'
    })
  }
})
