feat: DEMO 增加缓存

This commit is contained in:
purocean
2021-06-14 13:40:21 +08:00
parent bfdf3ec652
commit c99e2545a1
+16 -3
View File
@@ -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
})
}
}