docs(gateway): gateway 剩余文件注释改中文(逐行 1:1,代码零字节改动)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

主人 2026-10-03 拍板「注释一律中文」;gateway 至此整包注释中文化完成(本会话共 3 批:
已推库 16 个文件 + 本批剩余文件)。
校验:机械校验(非注释改动行)= 空;剥注释后代码文本逐行比对全等(不一致文件数 0);
全树 go test ./... 58 包 ok / 0 FAIL;交叉编译绿。
This commit is contained in:
AskaEth committed 2026-10-03 22:28:25 +08:00
1 parent 91e8d7a029
commit 074ffc4ebf
73 files changed
+2529 -2529

No files matched your search

+19 -19
View File
@@ -19,13 +19,13 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/auth"
)
// testPNG is the smallest byte string the stdlib sniffer recognizes as
// image/png (the 8-byte signature plus padding); the handler only sniffs the
// head, it never decodes the image.
// testPNG 是标准库嗅探器能识别为 image/png 的最小字节串
// (8 字节签名加填充);handler 只嗅探头部,
// 绝不解码该图片。
var testPNG = append([]byte("\x89PNG\r\n\x1a\n"), make([]byte, 64)...)
// uploadTestEnv builds a Server whose data dir is a fresh temp dir and returns
// the httptest server, the JWT service and the resolved data dir.
// uploadTestEnv 构建一个 Server,其数据目录是全新的临时目录,返回
// httptest 服务器、JWT 服务与解析后的数据目录。
func uploadTestEnv(t *testing.T) (*httptest.Server, *auth.JWTService, string) {
t.Helper()
cfg := cfgDefault()
@@ -34,9 +34,9 @@ func uploadTestEnv(t *testing.T) (*httptest.Server, *auth.JWTService, string) {
return ts, jwt, cfg.DataDir
}
// postUpload sends a multipart/form-data POST to /api/v1/upload. field is the
// part name (normally "file"); filename is the client-supplied name, which the
// handler must ignore.
// postUpload 向 /api/v1/upload 发送 multipart/form-data POST。field 是
// 部件名(通常为 "file");filename 是客户端提供的名字,
// handler 必须忽略它。
func postUpload(t *testing.T, ts *httptest.Server, token, field, filename string, content []byte) (*http.Response, []byte) {
t.Helper()
var buf bytes.Buffer
@@ -71,7 +71,7 @@ func postUpload(t *testing.T, ts *httptest.Server, token, field, filename string
return resp, body
}
// uploadData is the decoded upload response.
// uploadData 是解码后的上传响应。
type uploadData struct {
URL string `json:"url"`
Size int64 `json:"size"`
@@ -110,7 +110,7 @@ func TestUploadAndServeImage(t *testing.T) {
if !strings.HasPrefix(data.URL, "http://") || !strings.Contains(data.URL, uploadFilePrefix) {
t.Fatalf("url = %q, want absolute %s URL", data.URL, uploadFilePrefix)
}
// The client's original filename must never reach disk or the response.
// 客户端原始文件名绝不得到达磁盘或响应。
if strings.Contains(data.Name, "evil") || strings.ContainsAny(data.Name, "/\\") {
t.Fatalf("name = %q, want a server-generated hex name", data.Name)
}
@@ -121,8 +121,8 @@ func TestUploadAndServeImage(t *testing.T) {
t.Fatalf("stored file: %v", err)
}
// The static route is a capability URL: no bearer token, and the bytes and
// caching/type headers must come back intact.
// 静态路由是能力 URL:不带 bearer token,且字节与
// 缓存/类型头必须原样返回。
get, err := ts.Client().Get(data.URL)
if err != nil {
t.Fatalf("get upload: %v", err)
@@ -230,8 +230,8 @@ func TestUploadFileServedThroughSPA(t *testing.T) {
t.Parallel()
cfg := cfgDefault()
cfg.DataDir = t.TempDir()
// A non-nil frontend enables the SPA wrapper in Handler; the /api/v1/files/
// route must still reach the API mux instead of falling back to index.html.
// 非 nil 的 frontend 会在 Handler 中启用 SPA 包装;
// /api/v1/files/ 路由仍必须抵达 API mux,而不是回退到 index.html。
frontend := fstest.MapFS{"index.html": &fstest.MapFile{Data: []byte("<html>spa</html>")}}
_, ts, jwt := buildEnv(t, cfg, Deps{Frontend: frontend})
tok, _ := jwt.Sign("acct", auth.RoleOwner, time.Hour)
@@ -259,13 +259,13 @@ func TestUploadFileRejectsTraversal(t *testing.T) {
t.Parallel()
cfg := cfgDefault()
cfg.DataDir = t.TempDir()
// A non-nil frontend reproduces production routing: without the explicit
// guard, ServeMux would clean the raw `..` path and redirect to a path the SPA
// then answers with index.html.
// 非 nil 的 frontend 复现生产路由:没有显式
// 防护时,ServeMux 会清理原始 `..` 路径并重定向到一个 SPA
// 随后用 index.html 应答的路径。
frontend := fstest.MapFS{"index.html": &fstest.MapFile{Data: []byte("<html>spa</html>")}}
_, ts, _ := buildEnv(t, cfg, Deps{Frontend: frontend})
// A file that really exists directly under the data dir (not in uploads/)
// must not be reachable through the static route.
// 直接存在于数据目录下(不在 uploads/ 中)的真实文件
// 绝不得经静态路由可达。
if err := os.WriteFile(filepath.Join(cfg.DataDir, "secret.png"), testPNG, 0o600); err != nil {
t.Fatalf("write decoy: %v", err)
}