refactor: decouple user send API from roles

This commit is contained in:
dreamhunter2333
2026-08-23 21:15:17 +08:00
parent 21c5390723
commit 9109612322
+1 -9
View File
@@ -1,6 +1,6 @@
import { Context } from "hono"; import { Context } from "hono";
import { commonGetUserRole, handleListQuery } from "../common"; import { handleListQuery } from "../common";
import i18n from "../i18n"; import i18n from "../i18n";
import { sendMail } from "../mails_api/send_mail_api"; import { sendMail } from "../mails_api/send_mail_api";
import { import {
@@ -27,18 +27,11 @@ const getAddressOrError = async (
return c.text(msgs.AddressNotBindedMsg, 400); return c.text(msgs.AddressNotBindedMsg, 400);
} }
const setUserRole = async (c: Context<HonoCustomType>): Promise<void> => {
const { user_id } = c.get("userPayload");
const userRole = await commonGetUserRole(c, user_id);
c.set("userRolePayload", userRole?.role);
}
const settings = async (c: Context<HonoCustomType>): Promise<Response> => { const settings = async (c: Context<HonoCustomType>): Promise<Response> => {
const address = await getAddressOrError(c); const address = await getAddressOrError(c);
if (address instanceof Response) { if (address instanceof Response) {
return address; return address;
} }
await setUserRole(c);
const { balance } = await getSendBalanceState(c, address); const { balance } = await getSendBalanceState(c, address);
return c.json({ return c.json({
address, address,
@@ -67,7 +60,6 @@ const send = async (c: Context<HonoCustomType>): Promise<Response> => {
if (address instanceof Response) { if (address instanceof Response) {
return address; return address;
} }
await setUserRole(c);
const msgs = i18n.getMessagesbyContext(c); const msgs = i18n.getMessagesbyContext(c);
try { try {
const reqJson = await c.req.json(); const reqJson = await c.req.json();