mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-05 23:47:50 +08:00
refactor: decouple user send API from roles
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user