diff --git a/src/app/admin/page.tsx b/src/app/admin/page.tsx index f6d3af6..1a79156 100644 --- a/src/app/admin/page.tsx +++ b/src/app/admin/page.tsx @@ -586,9 +586,11 @@ export default function AdminPage() { diff --git a/src/app/api/admin/export/route.ts b/src/app/api/admin/export/route.ts index d0be048..7c2bb61 100644 --- a/src/app/api/admin/export/route.ts +++ b/src/app/api/admin/export/route.ts @@ -5,55 +5,28 @@ import path from 'path'; export async function GET() { try { - const rootDir = process.cwd(); - const dockerDir = path.join(rootDir, 'docker'); - const postsDir = path.join(rootDir, 'posts'); - let tarballName: string; - let tarballPath: string; - let tarCwd: string; - let tarItems: string[]; - let tarOptions: any = { - gzip: true, - portable: true, - noMtime: true, - }; + const dockerDir = '/app/docker'; // update this to your actual path + const tarballName = 'docker-export.tar.gz'; + const tarballPath = path.join('/tmp', tarballName); - if (existsSync(dockerDir)) { - // Docker is in use: export the entire root directory (excluding node_modules, .next, etc) - tarballName = 'root-export.tar.gz'; - tarballPath = path.join('/tmp', tarballName); - tarCwd = rootDir; - tarItems = ['.']; - tarOptions.file = tarballPath; - tarOptions.cwd = tarCwd; - tarOptions.filter = (filepath: string) => { - // Exclude node_modules, .next, .git, /tmp, and tarball itself - const excludes = [ - 'node_modules', '.next', '.git', 'tmp', 'docker.sock', tarballName - ]; - // Only check top-level folders/files - const rel = filepath.split(path.sep)[0]; - return !excludes.includes(rel); - }; - } else { - // Not docker: export only the posts directory - tarballName = 'posts-export.tar.gz'; - tarballPath = path.join('/tmp', tarballName); - tarCwd = rootDir; - tarItems = ['posts']; - tarOptions.file = tarballPath; - tarOptions.cwd = tarCwd; + if (!existsSync(dockerDir)) { + return NextResponse.json({ error: `${dockerDir} directory does not exist` }, { status: 400 }); } - // Create tarball await tar.c( - tarOptions, - tarItems + { + gzip: true, + file: tarballPath, + cwd: path.dirname(dockerDir), + portable: true, + noMtime: true, + }, + [path.basename(dockerDir)] ); - // Stream the tarball as a response const stat = statSync(tarballPath); const stream = createReadStream(tarballPath); + return new Response(stream as any, { status: 200, headers: { @@ -63,7 +36,7 @@ export async function GET() { }, }); } catch (error) { - console.error('Error exporting tarball:', error); - return NextResponse.json({ error: 'Error exporting tarball' }, { status: 500 }); + console.error('Error exporting docker:', error); + return NextResponse.json({ error: 'Error exporting docker' }, { status: 500 }); } -} \ No newline at end of file +} \ No newline at end of file