Feature(custom): add api doc for 36677 port

This commit is contained in:
Kuingsmile 2024-03-18 17:22:04 +08:00
parent 5cd34a6abe
commit 872a1a799e
2 changed files with 85 additions and 0 deletions

78
src/main/server/apiDoc.ts Normal file
View File

@ -0,0 +1,78 @@
export const markdownContent = `
## Server的使用
PicList内置了一个小型的服务器HTTP请求来上传图片
\`0.0.0.0\`,默认监听端口:\`36677\`
###
PicList提供了接口鉴权功能
![202310102349225](https://assets.piclist.cn/image/202310102349225.webp)
URL查询参数\`key\`即可,例如:\`http://xxx:36677/upload?key=xxx\`
### <Badge type="tip" text="2.6.3+" />
- : \`POST\`
- url: \`http://127.0.0.1:36677/upload\` (此处以默认配置为例)
- body: \`multipart/form-data\`格式key任选value为图片文件
### HTTP调用上传剪贴板图片
- : \`POST\`
- url: \`http://127.0.0.1:36677/upload\` (此处以默认配置为例)
- body: \`{list: ['xxx.jpg']}\` 必须是JSON格式
::: tip Tip
PicList支持通过设置\`picbed\`\`configName\`两个URL查询参数来指定上传图床和配置文件。例如
\`http://127.0.0.1:36677/upload?picbed=aws-s3&configName=piclist-test\`
使\`aws-s3\`图床,并且使用\`piclist-test\`配置文件。
:::
\`\`\`json
{
"success": true, // or false
"result": ["url"]
}
\`\`\`
### HTTP调用上传具体路径图片
- method: \`POST\`
- url: \`http://127.0.0.1:36677/upload\` (此处以默认配置为例)
- request body: \`{list: ['xxx.jpg']}\` 必须是JSON格式
\`\`\`json
{
"success": true, // or false
"result": ["url"]
}
\`\`\`
### HTTP调用删除图片
- method: \`POST\`
- url: \`http://127.0.0.1:36677/delete\` (此处以默认配置为例)
- request body: \`{list: [{xx:xx}]}\` 必须是JSON格式
list中的每一项都是一个对象\`fullResult\`字段组成。
\`\`\`json
{
"success": true, // or false
"message": xxx
}
\`\`\`
`

View File

@ -11,6 +11,8 @@ import multer from 'multer'
import { app } from 'electron'
import path from 'path'
import fs from 'fs-extra'
import { marked } from 'marked'
import { markdownContent } from './apiDoc'
const appPath = app.getPath('userData')
const serverTempDir = path.join(appPath, 'serverTemp')
@ -141,6 +143,11 @@ class Server {
})
}
}
} else if (request.method === 'GET') {
response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' })
const htmlContent = marked(markdownContent)
response.write(htmlContent)
response.end()
} else {
logger.warn(`[PicList Server] don't support [${request.method}] method`)
response.statusCode = 404