Files
BlueArchiveToolkit/internal/api/openapi.go
T
nyaKazuha 3f78f8f880 feat(api): 补齐资源分发服务入口
新增 bat-api 资源 bootstrap/分发 HTTP 服务、RPC release 发现、CDN path 分发、launcher 资源引导兼容、控制面中间件、OpenAPI 和 systemd 模板。

同步 Go 边界文档,明确 Rust bat 是资源生产者和同步运维入口,Go bat-api 是只读 bootstrap/分发服务,试验 Go CLI 产物为 bin/bat-go。

验证:未运行新命令;本轮已按要求停止重复构建/测试。
2026-07-31 00:41:48 +08:00

162 lines
4.1 KiB
Go

package api
import (
"net/http"
"strconv"
)
const openAPISpecYAML = `openapi: 3.0.3
info:
title: BlueArchive Toolkit bat-api
version: 0.1.0
description: Resource bootstrap and read-only distribution API.
servers:
- url: http://127.0.0.1:18080
security:
- bearerAuth: []
- queryToken: []
paths:
/healthz:
get:
summary: Liveness and refresh diagnostics
responses:
"200":
description: Service is alive.
/readyz:
get:
summary: Release readiness
responses:
"200":
description: A distributable release is available.
"503":
description: No distributable release is available.
/v1/bootstrap:
get:
summary: Startup resource bootstrap
responses:
"200":
description: Resource bootstrap response.
"503":
description: Release is not ready.
/v1/launcher/bootstrap:
get:
summary: Launcher-shaped resource bootstrap
responses:
"200":
description: Launcher bootstrap response.
"503":
description: Release is not ready.
/api/launcher/game/config:
get:
summary: Resource-only launcher game config compatibility
responses:
"200":
description: Launcher envelope with resource metadata.
/api/launcher/game/config/json:
get:
summary: Resource-only launcher manifest URL compatibility
parameters:
- name: version
in: query
schema:
type: string
- name: file_path
in: query
schema:
type: string
responses:
"200":
description: Launcher envelope pointing to resource bootstrap JSON.
/api/launcher/advanced/game/download/cdn:
get:
summary: Resource-only launcher CDN compatibility
responses:
"200":
description: Launcher envelope with public base URL as CDN root.
/v1/release:
get:
summary: Current release summary
responses:
"200":
description: Release summary.
/v1/resources:
get:
summary: Paginated resource manifest entries
parameters:
- name: offset
in: query
schema:
type: integer
minimum: 0
- name: limit
in: query
schema:
type: integer
minimum: 1
maximum: 1000
responses:
"200":
description: Resource list page.
/v1/server-info:
get:
summary: Rewritten server-info document
responses:
"200":
description: Server-info JSON with AddressablesCatalogUrlRoot rewritten.
/openapi.yaml:
get:
summary: OpenAPI document
responses:
"200":
description: OpenAPI YAML.
/admin/:
get:
summary: Reserved admin panel entry
responses:
"200":
description: Admin panel placeholder and links.
/prod-clientpatch.bluearchiveyostar.com/{path}:
get:
summary: CDN-shaped resource bytes
parameters:
- name: path
in: path
required: true
schema:
type: string
responses:
"200":
description: Resource bytes.
"206":
description: Partial resource bytes.
head:
summary: CDN-shaped resource metadata
responses:
"200":
description: Resource headers.
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
queryToken:
type: apiKey
in: query
name: bat_token
`
func (s *Server) handleOpenAPI(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet && r.Method != http.MethodHead {
writeErrorJSON(w, http.StatusMethodNotAllowed, "method_not_allowed", "method not allowed")
return
}
w.Header().Set("Content-Type", "application/yaml; charset=utf-8")
w.Header().Set("Cache-Control", "no-store")
w.Header().Set("Content-Length", strconv.Itoa(len(openAPISpecYAML)))
w.WriteHeader(http.StatusOK)
if r.Method == http.MethodHead {
return
}
_, _ = w.Write([]byte(openAPISpecYAML))
}