feat: add frame
This commit is contained in:
@@ -35,6 +35,10 @@ func (h *Handler) APIRoutes() http.Handler {
|
||||
r.Delete("/carpets", h.apiCarpetDelete)
|
||||
r.Post("/carpets/{id}/upload", h.carpetUpload) // multipart (اشتراکی)
|
||||
|
||||
r.Get("/frames", h.apiFrames)
|
||||
r.Post("/frames", h.apiFrameUpsert)
|
||||
r.Delete("/frames", h.apiFrameDelete)
|
||||
|
||||
r.Get("/chat", h.apiChat)
|
||||
r.Post("/chat/pack", h.apiChatPackUpsert)
|
||||
r.Delete("/chat/pack", h.apiChatPackDelete)
|
||||
@@ -282,6 +286,51 @@ func (h *Handler) apiCarpetDelete(w http.ResponseWriter, r *http.Request) {
|
||||
httpx.JSON(w, http.StatusOK, map[string]any{"ok": true})
|
||||
}
|
||||
|
||||
// --- قابهای آواتار ---
|
||||
|
||||
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"),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) apiFrameUpsert(w http.ResponseWriter, r *http.Request) {
|
||||
var b struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
PriceCoins int64 `json:"price_coins"`
|
||||
VIP bool `json:"vip"`
|
||||
Sort int `json:"sort"`
|
||||
Enabled *bool `json:"enabled"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&b); err != nil || strings.TrimSpace(b.ID) == "" {
|
||||
httpx.Error(w, http.StatusBadRequest, "invalid body")
|
||||
return
|
||||
}
|
||||
vip := 0
|
||||
if b.VIP {
|
||||
vip = 1
|
||||
}
|
||||
enabled := 1
|
||||
if b.Enabled != nil && !*b.Enabled {
|
||||
enabled = 0
|
||||
}
|
||||
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 {
|
||||
httpx.Error(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.JSON(w, http.StatusOK, map[string]any{"ok": true})
|
||||
}
|
||||
|
||||
func (h *Handler) apiFrameDelete(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = h.db.ExecContext(r.Context(), `DELETE FROM avatar_frames WHERE id=?`, r.URL.Query().Get("id"))
|
||||
httpx.JSON(w, http.StatusOK, map[string]any{"ok": true})
|
||||
}
|
||||
|
||||
// --- چت ---
|
||||
|
||||
func (h *Handler) apiChat(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user