support visite api docs in embed docs

pull/88/head
alimy 3 years ago
parent e47604b249
commit 0224a8a4dc

@ -111,23 +111,6 @@ PaoPao主要由以下优秀的开源项目/工具构建
```
提示: 如果需要内嵌web前端ui请先构建web前端(建议设置web/.env为VITE_HOST="")。
5. docker构建
```sh
# 默认参数构建, 默认内嵌web ui并设置api host为空
%> docker build -t your/paopao-ce:tag .
# 内嵌web ui并且自定义API host参数
%> docker build -t your/paopao-ce:tag --build-arg API_HOST=http://paopao.info .
# 内嵌web ui并且使用本地web/.env中的API host
%> docker build -t your/paopao-ce:tag --build-arg USE_API_HOST=no .
# 内嵌web ui并且使用本地编译的web/dist构建
%> docker build -t your/paopao-ce:tag --build-arg USE_DIST=yes .
# 只编译api server
%> docker build -t your/paopao-ce:tag --build-arg EMBED_UI=no .
```
#### 前端
@ -147,20 +130,6 @@ PaoPao主要由以下优秀的开源项目/工具构建
build完成后可以在dist目录获取编译产出配置nginx指向至该目录即可
3. 使用Docker构建
```sh
%> cd web
# 默认参数构建
%> docker build -t your/paopao-ce:web .
# 自定义API host 参数构建
%> docker build -t your/paopao-ce:web --build-arg API_HOST=http://paopao.info .
# 使用本地编译的dist构建
%> docker build -t your/paopao-ce:web --build-arg USE_DIST=yes .
```
#### 桌面端
1. 进入前端目录 `web`,编辑 `.env` 文件中后端服务地址,下载依赖包
@ -184,11 +153,48 @@ PaoPao主要由以下优秀的开源项目/工具构建
桌面端是使用[Rust](https://www.rust-lang.org/) + [tauri](https://github.com/tauri-apps/tauri)编写
需要安装tauri的依赖具体参考[https://tauri.studio/v1/guides/getting-started/prerequisites](https://tauri.studio/v1/guides/getting-started/prerequisites).
### docker-compose 运行
### 使用Docker构建、运行
* 后端:
```sh
# 默认参数构建, 默认内嵌web ui并设置api host为空
%> docker build -t your/paopao-ce:tag .
# 内嵌web ui并且自定义API host参数
%> docker build -t your/paopao-ce:tag --build-arg API_HOST=http://paopao.info .
# 内嵌web ui并且使用本地web/.env中的API host
%> docker build -t your/paopao-ce:tag --build-arg USE_API_HOST=no .
# 内嵌web ui并且使用本地编译的web/dist构建
%> docker build -t your/paopao-ce:tag --build-arg USE_DIST=yes .
# 只编译api server
%> docker build -t your/paopao-ce:tag --build-arg EMBED_UI=no .
# 运行
%> docker run -p 8008:8008 -v ${PWD}/config.yaml.sample:/app/paopao-ce/config.yaml your/paopao-ce:tag
```
* 前端:
```sh
%> cd web
# 默认参数构建
%> docker build -t your/paopao-ce:web .
# 自定义API host 参数构建
%> docker build -t your/paopao-ce:web --build-arg API_HOST=http://paopao.info .
# 使用本地编译的dist构建
%> docker build -t your/paopao-ce:web --build-arg USE_DIST=yes .
```
### 使用 docker-compose 运行
```sh
%> git clone https://github.com/rocboss/paopao-ce.git
%> docker compose up --build
# visit http://localhost:8008
# visit http://127.0.0.1:8008
```
默认是使用config.yaml.sample的配置如果需要自定义配置请拷贝默认配置文件(比如config.yaml)修改后再同步配置到docker-compose.yaml如下
```
@ -212,6 +218,12 @@ PaoPao主要由以下优秀的开源项目/工具构建
....
```
### API 文档
构建时将 `docs` 添加到TAGS中:
```sh
%> make run TAGS='docs'
# visit http://127.0.0.1:8008/docs
```
### 其他说明

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1,17 @@
//go:build docs
// +build docs
package docs
import (
"embed"
"net/http"
)
//go:embed index.html openapi.json **/*
var files embed.FS
// NewFileSystem get an embed static assets http.FileSystem instance.
func NewFileSystem() http.FileSystem {
return http.FS(files)
}

@ -0,0 +1,19 @@
<!DOCTYPE html>
<!-- Important: must specify -->
<html>
<head>
<meta charset="utf-8" />
<!-- Important: rapi-doc uses utf8 charecters -->
<script
type="module"
src="/docs/assets/rapidoc-min.js"
></script>
</head>
<body>
<rapi-doc
spec-url="/docs/openapi.json"
render-style="read"
>
</rapi-doc>
</body>
</html>

@ -0,0 +1,334 @@
{
"openapi": "3.0.0",
"info": {
"title": "paopao-ce API",
"description": "# The paopao-ce API documentation\n\nWelcome to the paopao-ce API documentation!\n\n",
"version": "0.1.0"
},
"servers": [
{
"url": "https://api.paopao.info"
}
],
"tags": [],
"paths": {
"/{bucket}": {
"post": {
"summary": "Upload Image",
"description": "Upload an image to the given bucket.\nThe `content-type` header must be provided as well\nas the `content-length` header otherwise the request will be rejected.\n\nThe uploaded file must also not exceed the given `content-length`.",
"parameters": [
{
"name": "bucket",
"schema": {
"type": "string"
},
"in": "path",
"description": "The bucket that the image should be uploaded.",
"required": true,
"deprecated": false
},
{
"name": "content-length",
"schema": {
"type": "integer",
"format": "uint64"
},
"in": "header",
"description": "The total size of the image in bytes.",
"required": true,
"deprecated": false
},
{
"name": "format",
"schema": {
"$ref": "#/components/schemas/ImageKind"
},
"in": "query",
"description": "The format that the uploaded image is encoded in.\n\nIf not provided, lust will guess the encoding.",
"required": false,
"deprecated": false
}
],
"requestBody": {
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UploadInfo"
}
}
}
},
"404": {
"description": "Bucket not found"
},
"400": {
"description": "The image format was incorrect or the system was\nunable to guess the format of the image."
},
"413": {
"description": "The upload exceeds the configured maximum file size."
},
"401": {
"description": "You are not authorized to complete this action.\n\nThis normally means the `Authorization` bearer has been left out\nof the request or is invalid."
}
}
}
},
"/{bucket}/{image_id}": {
"get": {
"summary": "Fetch Image",
"description": "Fetch the image from the storage backend and apply and additional affects\nif required.",
"parameters": [
{
"name": "bucket",
"schema": {
"type": "string"
},
"in": "path",
"description": "The bucket to try fetch the image from.",
"required": true,
"deprecated": false
},
{
"name": "image_id",
"schema": {
"type": "string",
"format": "uuid"
},
"in": "path",
"description": "The id of the image.",
"required": true,
"deprecated": false
},
{
"name": "format",
"schema": {
"$ref": "#/components/schemas/ImageKind"
},
"in": "query",
"description": "The encoding format that the image should be returned as.",
"required": false,
"deprecated": false
},
{
"name": "size",
"schema": {
"type": "string"
},
"in": "query",
"description": "The size preset that should be used when returning the image.",
"required": false,
"deprecated": false
},
{
"name": "width",
"schema": {
"type": "integer",
"format": "uint32"
},
"in": "query",
"description": "A custom width to resize the returned image to.",
"required": false,
"deprecated": false
},
{
"name": "height",
"schema": {
"type": "integer",
"format": "uint32"
},
"in": "query",
"description": "A custom height to resize the returned image to.",
"required": false,
"deprecated": false
},
{
"name": "accept",
"schema": {
"type": "string"
},
"in": "header",
"description": "A set of `,` seperated content-types that could be sent as a response.\nE.g. `image/png,image/webp,image/gif`",
"required": false,
"deprecated": false
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
},
"headers": {
"CONTENT-TYPE": {
"required": true,
"deprecated": false,
"schema": {
"type": "string"
}
}
}
},
"400": {
"description": "The request is invalid with the current configuration.\n\nSee the detail section for more info.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Detail"
}
}
}
},
"404": {
"description": "Bucket does not exist or image does not exist.\n\nSee the detail section for more info.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Detail"
}
}
}
}
}
},
"delete": {
"summary": "Delete Image",
"description": "Delete the given image.\nThis will purge all variants of the image including sizing presets and formats.\n\nImages that do not exist already will be ignored and will not return a 404.",
"parameters": [
{
"name": "bucket",
"schema": {
"type": "string"
},
"in": "path",
"description": "The bucket to try delete the image from.",
"required": true,
"deprecated": false
},
{
"name": "image_id",
"schema": {
"type": "string",
"format": "uuid"
},
"in": "path",
"description": "The image to delete try delete.",
"required": true,
"deprecated": false
}
],
"responses": {
"200": {
"description": ""
},
"401": {
"description": "You are not authorized to complete this action.\n\nThis normally means the `Authorization` bearer has been left out\nof the request or is invalid."
},
"404": {
"description": "Bucket does not exist."
}
}
}
}
},
"components": {
"schemas": {
"Detail": {
"type": "object",
"required": [
"detail"
],
"properties": {
"detail": {
"type": "string",
"description": "Additional information regarding the response."
}
}
},
"ImageKind": {
"type": "string",
"enum": [
"png",
"jpeg",
"webp",
"gif"
]
},
"ImageUploadInfo": {
"type": "object",
"required": [
"sizing_id"
],
"properties": {
"sizing_id": {
"type": "integer",
"format": "uint32",
"description": "The computed image sizing id.\n\nThis is useful for tracking files outside of lust as this is\ngenerally used for filtering within the storage systems."
}
}
},
"UploadInfo": {
"type": "object",
"required": [
"image_id",
"processing_time",
"io_time",
"checksum",
"images",
"bucket_id"
],
"properties": {
"image_id": {
"type": "string",
"format": "uuid",
"description": "The generated ID for the file.\n\nThis can be used to access the file for the given bucket."
},
"processing_time": {
"type": "number",
"format": "float",
"description": "The time spent processing the image in seconds."
},
"io_time": {
"type": "number",
"format": "float",
"description": "The time spent uploading the image to the persistent store."
},
"checksum": {
"type": "integer",
"format": "uint32",
"description": "The crc32 checksum of the uploaded image."
},
"images": {
"type": "array",
"description": "The information that is specific to the image.",
"items": {
"$ref": "#/components/schemas/ImageUploadInfo"
}
},
"bucket_id": {
"type": "integer",
"format": "uint32",
"description": "The id of the bucket the image was stored in.\n\nThis is useful for tracking files outside of lust as this is\ngenerally used for filtering within the storage systems."
}
}
}
}
}
}

@ -0,0 +1,13 @@
//go:build !docs
// +build !docs
package routers
import (
"github.com/gin-gonic/gin"
)
// registerDocs stub function for register docs asset route
func registerDocs(e *gin.Engine) {
// empty
}

@ -0,0 +1,14 @@
//go:build docs
// +build docs
package routers
import (
"github.com/gin-gonic/gin"
"github.com/rocboss/paopao-ce/docs"
)
// registerDocs register docs asset route
func registerDocs(e *gin.Engine) {
e.StaticFS("/docs", docs.NewFileSystem())
}

@ -24,8 +24,9 @@ func NewRouter() *gin.Engine {
corsConfig.AddAllowHeaders("Authorization")
e.Use(cors.New(corsConfig))
// 按需注册 静态资源、LocalOSS 路由
// 按需注册 docs、静态资源、LocalOSS 路由
{
registerDocs(e)
registerStatick(e)
routeLocalOSS(e)
}

Loading…
Cancel
Save