1.后台新增移动端顶级接口文档,md格式显示

This commit is contained in:
2026-05-14 10:59:00 +08:00
parent 932a433613
commit 90ec085cd5
8 changed files with 381 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace app\admin\controller\docs;
use app\common\controller\Backend;
use support\Response;
use Webman\Http\Request;
/**
* 后台只读展示《36字花-移动端接口设计草案》Markdown并提供下载。
*/
class Doc36ZiHuaMobileApi extends Backend
{
private const DOC_RELATIVE = 'docs' . DIRECTORY_SEPARATOR . '36字花-移动端接口设计草案.md';
public function content(Request $request): Response
{
$response = $this->initializeBackend($request);
if ($response !== null) {
return $response;
}
$path = $this->docAbsolutePath();
if (!is_file($path)) {
return $this->error(__('Document file not found'));
}
$raw = file_get_contents($path);
if ($raw === false) {
return $this->error(__('Failed to read document'));
}
return $this->success('', [
'markdown' => $raw,
'filename' => '36字花-移动端接口设计草案.md',
]);
}
public function download(Request $request): Response
{
$response = $this->initializeBackend($request);
if ($response !== null) {
return $response;
}
$path = $this->docAbsolutePath();
if (!is_file($path)) {
return $this->error(__('Document file not found'));
}
$body = file_get_contents($path);
if ($body === false) {
return $this->error(__('Failed to read document'));
}
$utf8Name = '36字花-移动端接口设计草案.md';
$asciiFallback = '36zihua-mobile-api-design-draft.md';
$disposition = sprintf(
'attachment; filename="%s"; filename*=UTF-8\'\'%s',
$asciiFallback,
rawurlencode($utf8Name)
);
return new Response(200, [
'Content-Type' => 'text/markdown; charset=UTF-8',
'Content-Disposition' => $disposition,
'Cache-Control' => 'private, max-age=0, must-revalidate',
], $body);
}
private function docAbsolutePath(): string
{
return rtrim(base_path(), DIRECTORY_SEPARATOR . '/') . DIRECTORY_SEPARATOR . self::DOC_RELATIVE;
}
}

View File

@@ -96,4 +96,6 @@ return [
'Please input correct username' => 'Please enter the correct username',
'Please enter a valid commission rate for non-top role group' => 'Non-top role groups require a commission rate between 0 and 100 (%)',
'Group Name Arr' => 'Group Name Arr',
'Document file not found' => 'Document file not found',
'Failed to read document' => 'Failed to read document',
];

View File

@@ -115,4 +115,6 @@ return [
'Please input correct username' => '请输入正确的用户名',
'Please enter a valid commission rate for non-top role group' => '非顶级角色组须填写 0100 的分红比例(%)',
'Group Name Arr' => '分组名称数组',
'Document file not found' => '文档文件不存在',
'Failed to read document' => '读取文档失败',
];