mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-01-22 22:28:14 -05:00
✨ Feature(custom): add api doc for 36677 port
This commit is contained in:
parent
5cd34a6abe
commit
872a1a799e
78
src/main/server/apiDoc.ts
Normal file
78
src/main/server/apiDoc.ts
Normal 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
|
||||||
|
}
|
||||||
|
\`\`\`
|
||||||
|
`
|
@ -11,6 +11,8 @@ import multer from 'multer'
|
|||||||
import { app } from 'electron'
|
import { app } from 'electron'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
|
import { marked } from 'marked'
|
||||||
|
import { markdownContent } from './apiDoc'
|
||||||
|
|
||||||
const appPath = app.getPath('userData')
|
const appPath = app.getPath('userData')
|
||||||
const serverTempDir = path.join(appPath, 'serverTemp')
|
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 {
|
} else {
|
||||||
logger.warn(`[PicList Server] don't support [${request.method}] method`)
|
logger.warn(`[PicList Server] don't support [${request.method}] method`)
|
||||||
response.statusCode = 404
|
response.statusCode = 404
|
||||||
|
Loading…
Reference in New Issue
Block a user