'docs' . DIRECTORY_SEPARATOR . '36字花-移动端接口设计草案.md', 'filename' => '36字花-移动端接口设计草案.md', 'ascii_fallback' => '36zihua-mobile-api-design-draft.md', ]; private const DOC_EN = [ 'relative' => 'docs' . DIRECTORY_SEPARATOR . 'en' . DIRECTORY_SEPARATOR . '36zihua-mobile-api-design-draft.md', 'filename' => '36zihua-mobile-api-design-draft.md', 'ascii_fallback' => '36zihua-mobile-api-design-draft.md', ]; public function content(Request $request): Response { $response = $this->initializeBackend($request); if ($response !== null) { return $response; } $doc = MarkdownDocReader::resolve($request, self::DOC_ZH, self::DOC_EN); if (!is_file($doc['path'])) { return $this->error(__('Document file not found')); } $raw = file_get_contents($doc['path']); if ($raw === false) { return $this->error(__('Failed to read document')); } return $this->success('', [ 'markdown' => $raw, 'filename' => $doc['filename'], 'lang' => $doc['lang'], ]); } public function download(Request $request): Response { $response = $this->initializeBackend($request); if ($response !== null) { return $response; } $doc = MarkdownDocReader::resolve($request, self::DOC_ZH, self::DOC_EN); if (!is_file($doc['path'])) { return $this->error(__('Document file not found')); } $body = file_get_contents($doc['path']); if ($body === false) { return $this->error(__('Failed to read document')); } $disposition = sprintf( 'attachment; filename="%s"; filename*=UTF-8\'\'%s', $doc['ascii_fallback'], rawurlencode($doc['filename']) ); return new Response(200, [ 'Content-Type' => 'text/markdown; charset=UTF-8', 'Content-Disposition' => $disposition, 'Cache-Control' => 'private, max-age=0, must-revalidate', ], $body); } }