Skip to content

Commit

Permalink
refactor: 新增 ApiTest 页面
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 30, 2023
1 parent caaa6cf commit 7178ae4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 24 deletions.
37 changes: 14 additions & 23 deletions src/components/test/SiyuanTest.vue
Expand Up @@ -30,7 +30,7 @@ import { AppInstance } from "~/src/appInstance.ts"
import { Utils } from "~/src/utils/utils.ts"
import { SiYuanApiAdaptor, SiyuanConfig, SiyuanKernelApi } from "zhi-siyuan-api"
import { MediaObject, Post } from "zhi-blog-api"
import { Buffer } from "node:buffer"
import { fileToBuffer } from "~/src/utils/polyfillUtils.ts"
const logger = createLogger("publisher-index")
Expand Down Expand Up @@ -178,19 +178,6 @@ const onImageSelect = async (event: Event) => {
}
}
const fileToBuffer = async (file: any): Promise<any> => {
return new Promise((resolve, reject) => {
const reader = new FileReader()
reader.onload = (e: any) => {
// 将 ArrayBuffer 转换成 Buffer 对象
const buffer = Buffer.from(e.target.result)
resolve(buffer)
}
reader.onerror = reject
reader.readAsArrayBuffer(file)
})
}
const siyuanGetRecentPosts = async () => {
isLoading.value = true
logMessage.value = ""
Expand Down Expand Up @@ -344,29 +331,33 @@ const siyuanGetRecentPosts = async () => {
</script>

<template>
<div id="publish-index">
<div id="siyuan-test">
<div class="method-list">
<el-select v-model="methodOption" class="m-2" placeholder="请选择方法名称" @change="onMethodChange">
<el-option v-for="item in methodOptions.options" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</div>

<p><el-button type="primary" :loading="isLoading" @click="siyuanGetRecentPosts">开始测试siyuan</el-button></p>
<div class="item">
<el-button type="primary" :loading="isLoading" @click="siyuanGetRecentPosts">开始测试siyuan</el-button>
</div>

<p><el-button>入参</el-button></p>
<p><el-input v-model="params" type="textarea" :rows="5"></el-input></p>
<p v-if="showParamFile"><input type="file" @change="onImageSelect" /></p>
<div class="item"><el-button>入参</el-button></div>
<div class="item"><el-input v-model="params" type="textarea" :rows="5"></el-input></div>
<div v-if="showParamFile" class="item"><input type="file" @change="onImageSelect" /></div>

<p><el-button>结果</el-button></p>
<p>
<div class="item"><el-button>结果</el-button></div>
<div class="item">
<el-input v-model="logMessage" type="textarea" :rows="10" placeholder="日志信息"></el-input>
</p>
</div>
</div>
</template>

<style lang="stylus" scoped>
#publish-index
#siyuan-test
margin 16px 20px
.item
margin-bottom 8px
.method-list
margin-bottom 16px
Expand Down
47 changes: 47 additions & 0 deletions src/utils/polyfillUtils.ts
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
* or visit www.terwer.space if you need additional information or have any
* questions.
*/

import { Buffer } from "node:buffer"

/**
* 将 file 对象转换为 Buffer
*
* @param file - file
* @author terwer
* @version 0.9.0
* @since 0.9.0
*/
export const fileToBuffer = async (file: any): Promise<any> => {
return new Promise((resolve, reject) => {
const reader = new FileReader()
reader.onload = (e: any) => {
// 将 ArrayBuffer 转换成 Buffer 对象
const buffer = Buffer.from(e.target.result)
resolve(buffer)
}
reader.onerror = reject
reader.readAsArrayBuffer(file)
})
}
5 changes: 4 additions & 1 deletion src/views/ApiTest.vue
Expand Up @@ -54,7 +54,10 @@ const changeTab = (tab: TabsPaneContext, event: Event) => {
</div>
</template>

<style scoped>
<style lang="stylus" scoped>
:deep(.el-tabs--border-card > .el-tabs__content)
padding 0
.tab-container {
margin: 0 20px;
}
Expand Down

0 comments on commit 7178ae4

Please sign in to comment.