import { Body, Controller, Get, Param, Post, Req, Res } from '@nestjs/common'; import { ConversionJobView, PageExportInput, pageExportInputSchema } from '@dorfteich/shared'; import type { Response } from 'express'; import { AuthedRequest } from '../auth/auth.guard'; import { ZodValidationPipe } from '../common/zod-validation.pipe'; import { RequiresPagePermission, RequiresPondRole } from '../permissions/permission.decorators'; import { ExportService } from './export.service'; /** * Export endpoints (ADR 0009, issue #65): a whole pond as a ZIP of Markdown and * a single page to `.docx`/`.odt`. Per-page Markdown download stays on the pages * controller (`GET /pages/:id/export/markdown`, #30). */ @Controller() export class ExportController { constructor(private readonly exports: ExportService) {} /** Streamed ZIP of the pond's readable pages as Markdown (+ `media/`). The * `reader` role is "may see the pond"; the service filters to readable pages, * so a label-restricted reader gets only their slice. */ @Get('ponds/:pondId/export/markdown') @RequiresPondRole('reader', { idParam: 'pondId' }) async pondZip( @Param('pondId') pondId: string, @Req() request: AuthedRequest, @Res() response: Response, ): Promise { await this.exports.streamPondMarkdownZip(request.user!, pondId, response); } /** Enqueue a `.docx`/`.odt` export of one page; poll `GET /jobs/:id` and * download `GET /jobs/:id/result`. */ @Post('pages/:pageId/export') @RequiresPagePermission('read', { idParam: 'pageId' }) pageExport( @Param('pageId') pageId: string, @Body(new ZodValidationPipe(pageExportInputSchema)) input: PageExportInput, @Req() request: AuthedRequest, ): Promise { return this.exports.enqueuePageExport(request.user!, pageId, input.format); } }