修复注释乱码

This commit is contained in:
dindang 2026-07-27 17:30:16 +08:00
parent 1754e99919
commit 4da1944f3b

View File

@ -16,7 +16,7 @@ import (
"floorvisualizer/internal/repository" "floorvisualizer/internal/repository"
) )
// 閳光偓閳光偓 Floor options 閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓 // --- Floor options ---
type FloorOption struct { type FloorOption struct {
ID string `json:"id"` ID string `json:"id"`
@ -50,8 +50,8 @@ type RoomOption struct {
var woodPatterns = []PatternOption{ var woodPatterns = []PatternOption{
{Code: 1, Name: "直铺工字拼Straight Lay", Category: "wood", Pattern: "planks running from bottom-left toward top-right of the image, joints staggered randomly, at least 6 inch offset between rows"}, {Code: 1, Name: "直铺工字拼Straight Lay", Category: "wood", Pattern: "planks running from bottom-left toward top-right of the image, joints staggered randomly, at least 6 inch offset between rows"},
{Code: 2, Name: "横铺 Horizontal Lay", Category: "wood", Pattern: "planks running horizontally left to right, parallel to the bottom edge of the image, joints staggered randomly, at least 6 inch offset"}, {Code: 2, Name: "横铺 Horizontal Lay", Category: "wood", Pattern: "planks running horizontally left to right, parallel to the bottom edge of the image, joints staggered randomly, at least 6 inch offset"},
{Code: 3, Name: "人字 Herringbone", Category: "wood", Pattern: "ALL planks must be IDENTICAL width - no piece may appear narrower. Planks at 90 degrees forming continuous zigzag V-lines from bottom-left to top-right of the image. At far distance, planks remain distinct with visible seams - NOT merging into a solid mass."}, {Code: 3, Name: "人字 Herringbone", Category: "wood", Pattern: "ALL planks must be IDENTICAL width - no piece may appear narrower. Planks at 90° forming continuous zigzag V-lines from bottom-left to top-right of the image. At far distance, planks remain distinct with visible seams - NOT merging into a solid mass."},
{Code: 4, Name: "鱼骨 Chevron", Category: "wood", Pattern: "planks with 45 degree mitered ends forming continuous V-points aligned from bottom-left to top-right of the image"}, {Code: 4, Name: "鱼骨 Chevron", Category: "wood", Pattern: "planks with 45° mitered ends forming continuous V-points aligned from bottom-left to top-right of the image"},
} }
var tilePatterns = []PatternOption{ var tilePatterns = []PatternOption{
@ -59,7 +59,7 @@ var tilePatterns = []PatternOption{
{Code: 6, Name: "工字铺1/2错缝Running Bond", Category: "tile", Pattern: "rows parallel to bottom edge of image, each row offset 50% from previous, horizontal grout lines continuous, vertical grout lines staggered"}, {Code: 6, Name: "工字铺1/2错缝Running Bond", Category: "tile", Pattern: "rows parallel to bottom edge of image, each row offset 50% from previous, horizontal grout lines continuous, vertical grout lines staggered"},
{Code: 7, Name: "三七错铺 1/3 Offset", Category: "tile", Pattern: "rows parallel to bottom edge of image, each row offset exactly 33% of tile length, every third row aligns"}, {Code: 7, Name: "三七错铺 1/3 Offset", Category: "tile", Pattern: "rows parallel to bottom edge of image, each row offset exactly 33% of tile length, every third row aligns"},
{Code: 8, Name: "六边形 Hexagonal", Category: "tile", Pattern: "six-sided tiles interlocked in honeycomb mesh, flat edges horizontal (parallel to bottom edge of image), grout follows hexagonal edges"}, {Code: 8, Name: "六边形 Hexagonal", Category: "tile", Pattern: "six-sided tiles interlocked in honeycomb mesh, flat edges horizontal (parallel to bottom edge of image), grout follows hexagonal edges"},
{Code: 9, Name: "斜铺60度对角Diagonal", Category: "tile", Pattern: "tiles rotated 60 degrees to the image frame, grout lines run diagonally at 60 and 150 degrees to the bottom edge, no lines parallel to image edges"}, {Code: 9, Name: "斜铺60度对角Diagonal", Category: "tile", Pattern: "tiles rotated 60° to the image frame, grout lines run diagonally at 60 and 150 degrees to the bottom edge, no lines parallel to image edges"},
} }
var roomOptions = []RoomOption{ var roomOptions = []RoomOption{
@ -113,7 +113,7 @@ func loadFloorOptions(db *sql.DB) ([]FloorOption, error) {
return nil, err return nil, err
} }
type key struct{ brand, style string } type key struct{ brand, style string }
seen := map[key]int{} // key 閳?index in out slice seen := map[key]int{} // key index in out slice
var out []FloorOption var out []FloorOption
for _, p := range prods { for _, p := range prods {
k := key{p.Brand, p.StyleName} k := key{p.Brand, p.StyleName}
@ -199,7 +199,7 @@ func findFloorBySKU(db *sql.DB, sku string) *FloorOption {
return f return f
} }
// 閳光偓閳光偓 Public accessors for worker 閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓 // --- Public accessors for worker ---
func FindFloorBySKUPublic(db *sql.DB, sku string) *FloorOption { return findFloorBySKU(db, sku) } func FindFloorBySKUPublic(db *sql.DB, sku string) *FloorOption { return findFloorBySKU(db, sku) }
func FindPatternByCodePublic(code string) *PatternOption { func FindPatternByCodePublic(code string) *PatternOption {
@ -218,7 +218,7 @@ func BuildFloorPromptPublic(f FloorOption, p PatternOption, room *RoomOption) st
} }
// BuildCombinedFloorPrompt builds a single prompt that identifies the floor area AND replaces it. // BuildCombinedFloorPrompt builds a single prompt that identifies the floor area AND replaces it.
// No separate mask generation step 閳?the AI does both in one pass. // No separate mask generation step the AI does both in one pass.
var baseboardColorNames = map[string]string{ var baseboardColorNames = map[string]string{
"white": "白色", "floor": "与地板同色", "cream": "米白", "white": "白色", "floor": "与地板同色", "cream": "米白",
"lightgray": "浅灰", "darkgray": "深灰", "wood": "木色(深棕)", "lightgray": "浅灰", "darkgray": "深灰", "wood": "木色(深棕)",
@ -258,7 +258,7 @@ func buildPatternConstraint(code int) string {
} }
} }
// 閳光偓閳光偓 Floor Generate Handler (Redis queue) 閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓 // --- Floor Generate Handler (Redis queue) ---
func SetQueue(enqueue func(ctx context.Context, jobID string, payload map[string]string) error) { func SetQueue(enqueue func(ctx context.Context, jobID string, payload map[string]string) error) {
generateQueue = enqueue generateQueue = enqueue
@ -346,9 +346,9 @@ func FloorGenerate(client *openrouter.Client, db *sql.DB) http.HandlerFunc {
} }
} }
// 閳光偓閳光偓 Progress 閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓 // --- Progress ---
// 閳光偓閳光偓 Floor Status Query 閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓 // --- Floor Status Query ---
func FloorStatus(w http.ResponseWriter, r *http.Request) { func FloorStatus(w http.ResponseWriter, r *http.Request) {
jobID := r.URL.Query().Get("job_id") jobID := r.URL.Query().Get("job_id")
@ -368,7 +368,7 @@ func FloorStatus(w http.ResponseWriter, r *http.Request) {
writeJSON(w, 200, js) writeJSON(w, 200, js)
} }
// 閳光偓閳光偓 Options 閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓 // --- Options ---
func FloorOptions(db *sql.DB) http.HandlerFunc { func FloorOptions(db *sql.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
@ -400,7 +400,7 @@ func FloorOptions(db *sql.DB) http.HandlerFunc {
} }
} }
// materialIndex caches SKU 閳?material description from MaterialAssets JSON files. // materialIndex caches SKU material description from MaterialAssets JSON files.
var materialIndex map[string]string var materialIndex map[string]string
// LoadMaterialIndex loads the material description index from a JSON file. // LoadMaterialIndex loads the material description index from a JSON file.
@ -450,13 +450,13 @@ func loadSpecialFloors(db *sql.DB) []FloorOption {
continue continue
} }
f.FloorDescription = r.Description f.FloorDescription = r.Description
// Keep f.ImageURL from DB (canonical smallest) 閳?do NOT override with local path // Keep f.ImageURL from DB (canonical smallest) do NOT override with local path
out = append(out, *f) out = append(out, *f)
} }
return out return out
} }
// 閳光偓閳光偓 Prompts 閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓閳光偓 // --- Prompts ---
func buildMaskPrompt(room *RoomOption) string { func buildMaskPrompt(room *RoomOption) string {
base := "你是精确的地面分割工具。请为这张室内照片生成纯黑白遮罩图。\n\n" + base := "你是精确的地面分割工具。请为这张室内照片生成纯黑白遮罩图。\n\n" +
@ -585,10 +585,6 @@ func buildFloorPrompt(floor FloorOption, pattern PatternOption, room *RoomOption
return buildCompactFloorPrompt(floor, pattern, room) return buildCompactFloorPrompt(floor, pattern, room)
} }
func buildProductNameGuard(floor FloorOption) string {
return compactProductNameGuard(floor)
}
func validateContent(client *openrouter.Client, ctx context.Context, imagePath string) (bool, int) { func validateContent(client *openrouter.Client, ctx context.Context, imagePath string) (bool, int) {
imgData, err := os.ReadFile(imagePath) imgData, err := os.ReadFile(imagePath)
if err != nil { if err != nil {