1.新增显示分红说明文档菜单
2.文档新增英文版
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace app\admin\controller\docs;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\docs\MarkdownDocReader;
|
||||
use support\Response;
|
||||
use Webman\Http\Request;
|
||||
|
||||
@@ -13,7 +14,17 @@ use Webman\Http\Request;
|
||||
*/
|
||||
class Doc36ZiHuaMobileApi extends Backend
|
||||
{
|
||||
private const DOC_RELATIVE = 'docs' . DIRECTORY_SEPARATOR . '36字花-移动端接口设计草案.md';
|
||||
private const DOC_ZH = [
|
||||
'relative' => '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
|
||||
{
|
||||
@@ -22,19 +33,20 @@ class Doc36ZiHuaMobileApi extends Backend
|
||||
return $response;
|
||||
}
|
||||
|
||||
$path = $this->docAbsolutePath();
|
||||
if (!is_file($path)) {
|
||||
$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($path);
|
||||
$raw = file_get_contents($doc['path']);
|
||||
if ($raw === false) {
|
||||
return $this->error(__('Failed to read document'));
|
||||
}
|
||||
|
||||
return $this->success('', [
|
||||
'markdown' => $raw,
|
||||
'filename' => '36字花-移动端接口设计草案.md',
|
||||
'filename' => $doc['filename'],
|
||||
'lang' => $doc['lang'],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -45,22 +57,20 @@ class Doc36ZiHuaMobileApi extends Backend
|
||||
return $response;
|
||||
}
|
||||
|
||||
$path = $this->docAbsolutePath();
|
||||
if (!is_file($path)) {
|
||||
$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($path);
|
||||
$body = file_get_contents($doc['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)
|
||||
$doc['ascii_fallback'],
|
||||
rawurlencode($doc['filename'])
|
||||
);
|
||||
|
||||
return new Response(200, [
|
||||
@@ -69,9 +79,4 @@ class Doc36ZiHuaMobileApi extends Backend
|
||||
'Cache-Control' => 'private, max-age=0, must-revalidate',
|
||||
], $body);
|
||||
}
|
||||
|
||||
private function docAbsolutePath(): string
|
||||
{
|
||||
return rtrim(base_path(), DIRECTORY_SEPARATOR . '/') . DIRECTORY_SEPARATOR . self::DOC_RELATIVE;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user