From c99e2545a1b9fceb182dfd8e79db31d068f9c05a Mon Sep 17 00:00:00 2001 From: purocean Date: Mon, 14 Jun 2021 13:40:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20DEMO=20=E5=A2=9E=E5=8A=A0=E7=BC=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/demo.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/frontend/src/demo.ts b/frontend/src/demo.ts index 888699a9..f1cc0eed 100644 --- a/frontend/src/demo.ts +++ b/frontend/src/demo.ts @@ -4,6 +4,7 @@ import file from './useful/file' if (FLAG_DEMO) { const xFetch = window.fetch + const cache: {[key: string]: string} = {} file.upload = (repo, path, fileData: File) => Promise.resolve({ repo, @@ -58,14 +59,26 @@ if (FLAG_DEMO) { if (method === 'POST') { return Promise.resolve({ status: 'ok', message: '保存成功' }) } else if (method === 'GET') { - return xFetch('/' + (url.searchParams.get('doc') || 'FEATURES.md')).then(res => res.text()).then(md => ({ + const path = '/' + (url.searchParams.get('doc') || 'FEATURES.md') + const data = { status: 'ok', message: '获取成功', data: { - content: md, + content: '', hash: 'test' } - })) + } + + if (cache[path]) { + data.data.content = cache[path] + return Promise.resolve(data) + } + + return xFetch(path).then(res => res.text()).then(md => { + cache[path] = md + data.data.content = md + return data + }) } }