4ec3e55030
ci/woodpecker/tag/build Pipeline was successful
① 前端:取消二维码解析的后端降级。二维码一律由前端 jsQR 解码并提取 uuid; 识别失败直接提示用户换更清晰的图片,不再把图片回传后端。 ② 后端:删除 POST /task/qr/decode 接口(handler.DecodeTaskQr)及其路由; 删除 qrcode.go 中所有图片解码相关代码(DecodeQRFromImage / decodeQRImage / scaleImage / ResolveQrUuidFromContent / decodeQrTextToUuid)——后端不再接收二维码图片。 保留 ExtractQrUuid(纯正则文本提取),提交签到(fillScanSubmitForm)与历史值归一化仍在用。 ③ 依赖:go mod tidy 移除 github.com/makiuchi-d/gozxing(不再被引用)。 golang.org/x/image 因验证码字体(captcha.go)仍在用,保留。 删除仅供已删测试使用的 internal/service/cpdaily/testdata/test_qr.png。 ④ 前端 API:移除 auth.ts 的 decodeQr()。 ⑤ 验证:go build / go vet / go test ./...、vue-tsc --noEmit、npm run build 全过。
40 lines
1.4 KiB
Go
40 lines
1.4 KiB
Go
package cpdaily
|
||
|
||
import (
|
||
"regexp"
|
||
"strings"
|
||
)
|
||
|
||
// qrUuidPattern 匹配二维码内容中的 uuid 参数(如 ...?uuid=1583a6...&isNeedExtra=0)
|
||
var qrUuidPattern = regexp.MustCompile(`uuid=([0-9a-zA-Z_-]+)`)
|
||
|
||
// bareUuidPattern 匹配纯 uuid(32 位十六进制字符串,如 1583a66272854585833eb13b56fc1937)
|
||
var bareUuidPattern = regexp.MustCompile(`^[0-9a-fA-F]{32}$`)
|
||
|
||
// bareTokenPattern 匹配"整串即 uuid 的裸值",用于存库后回读的场景。
|
||
// 链接里的 uuid 允许 [0-9a-zA-Z_-]+(见 qrUuidPattern),并非都是 32 位 hex,
|
||
// 因此仅靠 bareUuidPattern 无法反解非 hex 的 uuid,会导致签到失败。
|
||
// 长度限制 8~64 且不含空白/URL 符号,避免把普通文本误判为 uuid。
|
||
var bareTokenPattern = regexp.MustCompile(`^[0-9a-zA-Z_-]{8,64}$`)
|
||
|
||
// ExtractQrUuid 从二维码文本内容中提取签到二维码 uuid。
|
||
// 支持三种形式:完整链接(取 uuid= 参数值)、32 位 hex 裸 uuid、其它形式的裸 uuid token。
|
||
//
|
||
// 二维码图片的识别在前端完成(jsQR),后端只接收解析后的 uuid 文本,故此处不涉及图片解码。
|
||
func ExtractQrUuid(text string) string {
|
||
text = strings.TrimSpace(text)
|
||
if text == "" {
|
||
return ""
|
||
}
|
||
if m := qrUuidPattern.FindStringSubmatch(text); len(m) == 2 {
|
||
return m[1]
|
||
}
|
||
if bareUuidPattern.MatchString(text) {
|
||
return strings.ToLower(text)
|
||
}
|
||
if bareTokenPattern.MatchString(text) {
|
||
return text
|
||
}
|
||
return ""
|
||
}
|