Skip to content

Commit

Permalink
✨ Feature(custom): add api doc for 36677 port
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile committed Mar 18, 2024
1 parent 5cd34a6 commit 872a1a7
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
78 changes: 78 additions & 0 deletions src/main/server/apiDoc.ts
Original file line number Diff line number Diff line change
@@ -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
}
\`\`\`
`
7 changes: 7 additions & 0 deletions src/main/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 872a1a7

Please sign in to comment.