fix: add frame

This commit is contained in:
2026-07-08 13:47:50 +03:30
parent b5420bac21
commit da6df0328f
5 changed files with 106 additions and 7 deletions
+43 -4
View File
@@ -39,6 +39,9 @@ func (h *Handler) APIRoutes() http.Handler {
r.Post("/frames", h.apiFrameUpsert)
r.Delete("/frames", h.apiFrameDelete)
r.Get("/rank-tiers", h.apiRankTiers)
r.Post("/rank-tiers", h.apiRankTierUpsert)
r.Get("/chat", h.apiChat)
r.Post("/chat/pack", h.apiChatPackUpsert)
r.Delete("/chat/pack", h.apiChatPackDelete)
@@ -291,8 +294,8 @@ func (h *Handler) apiCarpetDelete(w http.ResponseWriter, r *http.Request) {
func (h *Handler) apiFrames(w http.ResponseWriter, r *http.Request) {
httpx.JSON(w, http.StatusOK, map[string]any{
"frames": h.rows(r.Context(),
`SELECT id,title,price_coins,vip,sort,enabled FROM avatar_frames ORDER BY sort`,
"id", "title", "price_coins", "vip", "sort", "enabled"),
`SELECT id,title,price_coins,vip,c1,c2,sort,enabled FROM avatar_frames ORDER BY sort`,
"id", "title", "price_coins", "vip", "c1", "c2", "sort", "enabled"),
})
}
@@ -302,6 +305,8 @@ func (h *Handler) apiFrameUpsert(w http.ResponseWriter, r *http.Request) {
Title string `json:"title"`
PriceCoins int64 `json:"price_coins"`
VIP bool `json:"vip"`
C1 string `json:"c1"`
C2 string `json:"c2"`
Sort int `json:"sort"`
Enabled *bool `json:"enabled"`
}
@@ -317,9 +322,11 @@ func (h *Handler) apiFrameUpsert(w http.ResponseWriter, r *http.Request) {
if b.Enabled != nil && !*b.Enabled {
enabled = 0
}
// رنگ‌ها را نرمال کن (حذفِ # و فاصله).
clean := func(s string) string { return strings.TrimPrefix(strings.TrimSpace(s), "#") }
if _, err := h.db.ExecContext(r.Context(),
`INSERT OR REPLACE INTO avatar_frames (id,title,price_coins,vip,sort,enabled) VALUES (?,?,?,?,?,?)`,
b.ID, b.Title, b.PriceCoins, vip, b.Sort, enabled); err != nil {
`INSERT OR REPLACE INTO avatar_frames (id,title,price_coins,vip,c1,c2,sort,enabled) VALUES (?,?,?,?,?,?,?,?)`,
b.ID, b.Title, b.PriceCoins, vip, clean(b.C1), clean(b.C2), b.Sort, enabled); err != nil {
httpx.Error(w, http.StatusInternalServerError, err.Error())
return
}
@@ -331,6 +338,38 @@ func (h *Handler) apiFrameDelete(w http.ResponseWriter, r *http.Request) {
httpx.JSON(w, http.StatusOK, map[string]any{"ok": true})
}
// --- رتبه‌ها (رنگ/برچسب؛ مجموعه ثابت است، فقط ویرایش) ---
func (h *Handler) apiRankTiers(w http.ResponseWriter, r *http.Request) {
httpx.JSON(w, http.StatusOK, map[string]any{
"rank_tiers": h.rows(r.Context(),
`SELECT id,label,c1,c2,sort FROM rank_tiers ORDER BY sort`,
"id", "label", "c1", "c2", "sort"),
})
}
func (h *Handler) apiRankTierUpsert(w http.ResponseWriter, r *http.Request) {
var b struct {
ID string `json:"id"`
Label string `json:"label"`
C1 string `json:"c1"`
C2 string `json:"c2"`
Sort int `json:"sort"`
}
if err := json.NewDecoder(r.Body).Decode(&b); err != nil || strings.TrimSpace(b.ID) == "" {
httpx.Error(w, http.StatusBadRequest, "invalid body")
return
}
clean := func(s string) string { return strings.TrimPrefix(strings.TrimSpace(s), "#") }
if _, err := h.db.ExecContext(r.Context(),
`INSERT OR REPLACE INTO rank_tiers (id,label,c1,c2,sort) VALUES (?,?,?,?,?)`,
b.ID, b.Label, clean(b.C1), clean(b.C2), b.Sort); err != nil {
httpx.Error(w, http.StatusInternalServerError, err.Error())
return
}
httpx.JSON(w, http.StatusOK, map[string]any{"ok": true})
}
// --- چت ---
func (h *Handler) apiChat(w http.ResponseWriter, r *http.Request) {