← back to Letsbegin

app/api/projects/route.ts

34 lines

import { NextResponse } from 'next/server'
import fs from 'fs'
import path from 'path'

const PROJECTS_DIR = '/root/Projects'

export async function GET() {
  try {
    const entries = fs.readdirSync(PROJECTS_DIR, { withFileTypes: true })

    const projects = entries
      .filter(entry => entry.isDirectory())
      .filter(entry => !entry.name.startsWith('.'))
      .map(entry => {
        const projectPath = path.join(PROJECTS_DIR, entry.name)
        const claudeMdPath = path.join(projectPath, '.claude', 'CLAUDE.md')
        const hasClaudeMd = fs.existsSync(claudeMdPath) ||
                          fs.existsSync(path.join(projectPath, 'CLAUDE.md'))

        return {
          name: entry.name,
          path: projectPath,
          hasClaudeMd
        }
      })
      .sort((a, b) => a.name.localeCompare(b.name))

    return NextResponse.json({ projects })
  } catch (error) {
    console.error('Failed to list projects:', error)
    return NextResponse.json({ error: 'Failed to list projects' }, { status: 500 })
  }
}