mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-05 15:38:34 +08:00
fix: align user mail navigation
This commit is contained in:
@@ -24,6 +24,8 @@ api.post('/user_api/address/:address_id/request_send_mail_access', user_send_mai
|
||||
api.post('/user_api/address/:address_id/send_mail', user_send_mail_api.send);
|
||||
api.get('/user_api/address/:address_id/sendbox', user_send_mail_api.listSendbox);
|
||||
api.delete('/user_api/address/:address_id/sendbox/:mail_id', user_send_mail_api.removeSendboxMail);
|
||||
api.get('/user_api/sendbox', user_send_mail_api.listUserSendbox);
|
||||
api.delete('/user_api/sendbox/:mail_id', user_send_mail_api.removeUserSendboxMail);
|
||||
|
||||
// user api
|
||||
api.post('/user_api/login', user.login);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Context } from "hono";
|
||||
|
||||
import { commonGetUserRole } from "../common";
|
||||
import { commonGetUserRole, handleListQuery } from "../common";
|
||||
import i18n from "../i18n";
|
||||
import {
|
||||
deleteSendbox,
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
getSendBalanceState,
|
||||
requestSendMailAccess,
|
||||
} from "../mails_api/send_balance";
|
||||
import { getBooleanValue } from "../utils";
|
||||
|
||||
const getBindedAddress = async (
|
||||
c: Context<HonoCustomType>
|
||||
@@ -106,10 +107,50 @@ const removeSendboxMail = async (c: Context<HonoCustomType>): Promise<Response>
|
||||
return deleteSendbox(c, address, c.req.param("mail_id"));
|
||||
}
|
||||
|
||||
const listUserSendbox = async (c: Context<HonoCustomType>): Promise<Response> => {
|
||||
const { user_id } = c.get("userPayload");
|
||||
const { address, limit, offset } = c.req.query();
|
||||
const filters = ["ua.user_id = ?"];
|
||||
const params = [String(user_id)];
|
||||
if (address) {
|
||||
filters.push("sb.address = ?");
|
||||
params.push(address);
|
||||
}
|
||||
const fromQuery = ` FROM users_address ua`
|
||||
+ ` JOIN address a ON a.id = ua.address_id`
|
||||
+ ` JOIN sendbox sb ON sb.address = a.name`
|
||||
+ ` WHERE ${filters.join(" AND ")}`;
|
||||
return await handleListQuery(c,
|
||||
`SELECT sb.*${fromQuery}`,
|
||||
`SELECT count(*) as count${fromQuery}`,
|
||||
params, limit, offset, "sb.id desc"
|
||||
);
|
||||
}
|
||||
|
||||
const removeUserSendboxMail = async (c: Context<HonoCustomType>): Promise<Response> => {
|
||||
const msgs = i18n.getMessagesbyContext(c);
|
||||
if (!getBooleanValue(c.env.ENABLE_USER_DELETE_EMAIL)) {
|
||||
return c.text(msgs.UserDeleteEmailDisabledMsg, 403);
|
||||
}
|
||||
const { user_id } = c.get("userPayload");
|
||||
const { mail_id } = c.req.param();
|
||||
const { success } = await c.env.DB.prepare(
|
||||
`DELETE FROM sendbox WHERE id = ?`
|
||||
+ ` AND EXISTS (`
|
||||
+ `SELECT 1 FROM users_address ua`
|
||||
+ ` JOIN address a ON a.id = ua.address_id`
|
||||
+ ` WHERE ua.user_id = ? AND a.name = sendbox.address`
|
||||
+ `)`
|
||||
).bind(mail_id, user_id).run();
|
||||
return c.json({ success });
|
||||
}
|
||||
|
||||
export default {
|
||||
settings,
|
||||
requestAccess,
|
||||
send,
|
||||
listSendbox,
|
||||
removeSendboxMail,
|
||||
listUserSendbox,
|
||||
removeUserSendboxMail,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user