mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-08-29 03:57:05 +08:00
fix: address user mail review feedback
This commit is contained in:
+1
-1
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
- test: |E2E| 覆盖 D1 数据库大小响应、配置键隔离,以及数据库页面套餐选择的持久化与刷新恢复
|
- test: |E2E| 覆盖 D1 数据库大小响应、配置键隔离,以及数据库页面套餐选择的持久化与刷新恢复
|
||||||
- fix: |E2E| 覆盖发信页面草稿编辑、正文格式切换及 HTML 预览
|
- fix: |E2E| 覆盖发信页面草稿编辑、正文格式切换及 HTML 预览
|
||||||
- test: |E2E| 覆盖用户 JWT 发信接口的地址归属、额度扣减、实际投递和发件箱操作,以及用户中心查看地址凭证、切换发件地址和按地址过滤发件箱的完整流程
|
- fix: |E2E| 覆盖用户 JWT 发信接口的地址归属、额度扣减、实际投递和发件箱操作,以及用户中心查看地址凭证、切换发件地址和按地址过滤发件箱的完整流程
|
||||||
|
|
||||||
## v1.11.0
|
## v1.11.0
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
- test: |E2E| Cover the D1 database-size response, config-key isolation, and persistence of the database-page plan selection across reloads
|
- test: |E2E| Cover the D1 database-size response, config-key isolation, and persistence of the database-page plan selection across reloads
|
||||||
- fix: |E2E| Cover draft editing, content-format switching, and HTML preview in the send-mail composer
|
- fix: |E2E| Cover draft editing, content-format switching, and HTML preview in the send-mail composer
|
||||||
- test: |E2E| Cover address ownership, balance decrement, delivery, and sent-item operations through the User JWT API, plus user-center credential display, sender switching, and sent-item filtering by address
|
- fix: |E2E| Cover address ownership, balance decrement, delivery, and sent-item operations through the User JWT API, plus user-center credential display, sender switching, and sent-item filtering by address
|
||||||
|
|
||||||
## v1.11.0
|
## v1.11.0
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ test.describe('User send mail API', () => {
|
|||||||
userId = user.userId;
|
userId = user.userId;
|
||||||
const bound = await createTestAddress(request, 'user-send-bound-');
|
const bound = await createTestAddress(request, 'user-send-bound-');
|
||||||
const accessRequest = await createTestAddress(request, 'user-send-access-');
|
const accessRequest = await createTestAddress(request, 'user-send-access-');
|
||||||
const outsider = await createTestAddress(request, 'user-send-outsider-');
|
const outsider = await createTestAddress(request, 'usr-outsider-');
|
||||||
addresses.push(bound, accessRequest, outsider);
|
addresses.push(bound, accessRequest, outsider);
|
||||||
await bindAddress(request, user.jwt, bound.jwt);
|
await bindAddress(request, user.jwt, bound.jwt);
|
||||||
await bindAddress(request, user.jwt, accessRequest.jwt);
|
await bindAddress(request, user.jwt, accessRequest.jwt);
|
||||||
@@ -166,12 +166,6 @@ test.describe('User send mail API', () => {
|
|||||||
));
|
));
|
||||||
expect(outsiderMail).toBeTruthy();
|
expect(outsiderMail).toBeTruthy();
|
||||||
|
|
||||||
const unauthorizedAddressDeleteRes = await request.delete(
|
|
||||||
`${WORKER_URL}/user_api/address/${outsider.address_id}/sendbox/${outsiderMail.id}`,
|
|
||||||
{ headers: { 'x-user-token': user.jwt } },
|
|
||||||
);
|
|
||||||
expect(unauthorizedAddressDeleteRes.status()).toBe(400);
|
|
||||||
|
|
||||||
const unauthorizedDeleteRes = await request.delete(
|
const unauthorizedDeleteRes = await request.delete(
|
||||||
`${WORKER_URL}/user_api/sendbox/${outsiderMail.id}`,
|
`${WORKER_URL}/user_api/sendbox/${outsiderMail.id}`,
|
||||||
{ headers: { 'x-user-token': user.jwt } },
|
{ headers: { 'x-user-token': user.jwt } },
|
||||||
@@ -189,16 +183,6 @@ test.describe('User send mail API', () => {
|
|||||||
);
|
);
|
||||||
expect((await updatedSettingsRes.json()).send_balance).toBe(9);
|
expect((await updatedSettingsRes.json()).send_balance).toBe(9);
|
||||||
|
|
||||||
const sendboxRes = await request.get(
|
|
||||||
`${WORKER_URL}/user_api/address/${bound.address_id}/sendbox?limit=20&offset=0`,
|
|
||||||
{ headers: { 'x-user-token': user.jwt } },
|
|
||||||
);
|
|
||||||
expect(sendboxRes.ok()).toBe(true);
|
|
||||||
const sendbox = await sendboxRes.json();
|
|
||||||
expect(sendbox.count).toBe(1);
|
|
||||||
expect(sendbox.results).toHaveLength(1);
|
|
||||||
expect(JSON.parse(sendbox.results[0].raw).subject).toBe(subject);
|
|
||||||
|
|
||||||
const userSendboxRes = await request.get(
|
const userSendboxRes = await request.get(
|
||||||
`${WORKER_URL}/user_api/sendbox?limit=20&offset=0`,
|
`${WORKER_URL}/user_api/sendbox?limit=20&offset=0`,
|
||||||
{ headers: { 'x-user-token': user.jwt } },
|
{ headers: { 'x-user-token': user.jwt } },
|
||||||
@@ -207,6 +191,7 @@ test.describe('User send mail API', () => {
|
|||||||
const userSendbox = await userSendboxRes.json();
|
const userSendbox = await userSendboxRes.json();
|
||||||
expect(userSendbox.count).toBe(1);
|
expect(userSendbox.count).toBe(1);
|
||||||
expect(userSendbox.results).toHaveLength(1);
|
expect(userSendbox.results).toHaveLength(1);
|
||||||
|
expect(JSON.parse(userSendbox.results[0].raw).subject).toBe(subject);
|
||||||
|
|
||||||
const filteredSendboxRes = await request.get(
|
const filteredSendboxRes = await request.get(
|
||||||
`${WORKER_URL}/user_api/sendbox?limit=20&offset=0&address=${encodeURIComponent(bound.address)}`,
|
`${WORKER_URL}/user_api/sendbox?limit=20&offset=0&address=${encodeURIComponent(bound.address)}`,
|
||||||
@@ -222,20 +207,14 @@ test.describe('User send mail API', () => {
|
|||||||
expect(outsiderFilterRes.ok()).toBe(true);
|
expect(outsiderFilterRes.ok()).toBe(true);
|
||||||
expect((await outsiderFilterRes.json()).count).toBe(0);
|
expect((await outsiderFilterRes.json()).count).toBe(0);
|
||||||
|
|
||||||
const outsiderSendboxRes = await request.get(
|
|
||||||
`${WORKER_URL}/user_api/address/${outsider.address_id}/sendbox?limit=20&offset=0`,
|
|
||||||
{ headers: { 'x-user-token': user.jwt } },
|
|
||||||
);
|
|
||||||
expect(outsiderSendboxRes.status()).toBe(400);
|
|
||||||
|
|
||||||
const deleteRes = await request.delete(
|
const deleteRes = await request.delete(
|
||||||
`${WORKER_URL}/user_api/sendbox/${sendbox.results[0].id}`,
|
`${WORKER_URL}/user_api/sendbox/${userSendbox.results[0].id}`,
|
||||||
{ headers: { 'x-user-token': user.jwt } },
|
{ headers: { 'x-user-token': user.jwt } },
|
||||||
);
|
);
|
||||||
expect(deleteRes.ok()).toBe(true);
|
expect(deleteRes.ok()).toBe(true);
|
||||||
|
|
||||||
const emptySendboxRes = await request.get(
|
const emptySendboxRes = await request.get(
|
||||||
`${WORKER_URL}/user_api/address/${bound.address_id}/sendbox?limit=20&offset=0`,
|
`${WORKER_URL}/user_api/sendbox?limit=20&offset=0`,
|
||||||
{ headers: { 'x-user-token': user.jwt } },
|
{ headers: { 'x-user-token': user.jwt } },
|
||||||
);
|
);
|
||||||
const emptySendbox = await emptySendboxRes.json();
|
const emptySendbox = await emptySendboxRes.json();
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ async function createUser(request: APIRequestContext) {
|
|||||||
test.describe('User send mail page', () => {
|
test.describe('User send mail page', () => {
|
||||||
test('selects a bound address, sends mail, and opens its sent items', async ({ page }) => {
|
test('selects a bound address, sends mail, and opens its sent items', async ({ page }) => {
|
||||||
const request = await apiRequest.newContext();
|
const request = await apiRequest.newContext();
|
||||||
let address: Awaited<ReturnType<typeof createTestAddress>> | undefined;
|
const addresses: Awaited<ReturnType<typeof createTestAddress>>[] = [];
|
||||||
let userId: number | undefined;
|
let userId: number | undefined;
|
||||||
let originalUserSettings: Record<string, unknown> | undefined;
|
let originalUserSettings: Record<string, unknown> | undefined;
|
||||||
|
|
||||||
@@ -48,14 +48,18 @@ test.describe('User send mail page', () => {
|
|||||||
|
|
||||||
const user = await createUser(request);
|
const user = await createUser(request);
|
||||||
userId = user.userId;
|
userId = user.userId;
|
||||||
address = await createTestAddress(request, 'user-send-browser-address-');
|
const address = await createTestAddress(request, 'usr-browser-');
|
||||||
const bindRes = await request.post(`${WORKER_URL}/user_api/bind_address`, {
|
const secondAddress = await createTestAddress(request, 'usr-second-');
|
||||||
headers: {
|
addresses.push(address, secondAddress);
|
||||||
Authorization: `Bearer ${address.jwt}`,
|
for (const boundAddress of addresses) {
|
||||||
'x-user-token': user.jwt,
|
const bindRes = await request.post(`${WORKER_URL}/user_api/bind_address`, {
|
||||||
},
|
headers: {
|
||||||
});
|
Authorization: `Bearer ${boundAddress.jwt}`,
|
||||||
expect(bindRes.ok()).toBe(true);
|
'x-user-token': user.jwt,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(bindRes.ok()).toBe(true);
|
||||||
|
}
|
||||||
|
|
||||||
await page.goto(`${FRONTEND_URL}/en/`);
|
await page.goto(`${FRONTEND_URL}/en/`);
|
||||||
await page.evaluate((userJwt) => {
|
await page.evaluate((userJwt) => {
|
||||||
@@ -67,7 +71,7 @@ test.describe('User send mail page', () => {
|
|||||||
const credentialResponse = page.waitForResponse((response) => (
|
const credentialResponse = page.waitForResponse((response) => (
|
||||||
response.request().method() === 'GET'
|
response.request().method() === 'GET'
|
||||||
&& new URL(response.url()).pathname
|
&& new URL(response.url()).pathname
|
||||||
=== `/user_api/bind_address_jwt/${address!.address_id}`
|
=== `/user_api/bind_address_jwt/${address.address_id}`
|
||||||
));
|
));
|
||||||
const addressRow = page.getByRole('row').filter({ hasText: address.address });
|
const addressRow = page.getByRole('row').filter({ hasText: address.address });
|
||||||
await addressRow.getByRole('button', { name: 'Address Credential' }).click();
|
await addressRow.getByRole('button', { name: 'Address Credential' }).click();
|
||||||
@@ -75,15 +79,16 @@ test.describe('User send mail page', () => {
|
|||||||
await expect(page.getByRole('dialog')).toContainText(address.address);
|
await expect(page.getByRole('dialog')).toContainText(address.address);
|
||||||
await page.getByRole('button', { name: 'close' }).click();
|
await page.getByRole('button', { name: 'close' }).click();
|
||||||
|
|
||||||
|
await page.getByText('Send Mail', { exact: true }).click();
|
||||||
|
await expect(page.getByRole('heading', { name: 'Compose email', exact: true })).toBeVisible();
|
||||||
|
|
||||||
const settingsResponse = page.waitForResponse((response) => (
|
const settingsResponse = page.waitForResponse((response) => (
|
||||||
new URL(response.url()).pathname
|
new URL(response.url()).pathname
|
||||||
=== `/user_api/address/${address!.address_id}/settings`
|
=== `/user_api/address/${address.address_id}/settings`
|
||||||
));
|
));
|
||||||
await page.getByText('Send Mail', { exact: true }).click();
|
await page.locator('.address-picker-select').click();
|
||||||
|
await page.locator('.n-base-select-option').filter({ hasText: address.address }).click();
|
||||||
expect((await settingsResponse).ok()).toBe(true);
|
expect((await settingsResponse).ok()).toBe(true);
|
||||||
|
|
||||||
await expect(page.getByRole('heading', { name: 'Compose email', exact: true })).toBeVisible();
|
|
||||||
await expect(page.locator('.composer-title')).toContainText(address.address);
|
|
||||||
await expect(page.locator('.address-picker-select')).toContainText(address.address);
|
await expect(page.locator('.address-picker-select')).toContainText(address.address);
|
||||||
|
|
||||||
const subject = `Browser user send ${Date.now()}`;
|
const subject = `Browser user send ${Date.now()}`;
|
||||||
@@ -95,7 +100,7 @@ test.describe('User send mail page', () => {
|
|||||||
const sendResponse = page.waitForResponse((response) => (
|
const sendResponse = page.waitForResponse((response) => (
|
||||||
response.request().method() === 'POST'
|
response.request().method() === 'POST'
|
||||||
&& new URL(response.url()).pathname
|
&& new URL(response.url()).pathname
|
||||||
=== `/user_api/address/${address!.address_id}/send_mail`
|
=== `/user_api/address/${address.address_id}/send_mail`
|
||||||
));
|
));
|
||||||
const sendboxResponse = page.waitForResponse((response) => (
|
const sendboxResponse = page.waitForResponse((response) => (
|
||||||
response.request().method() === 'GET'
|
response.request().method() === 'GET'
|
||||||
@@ -109,7 +114,7 @@ test.describe('User send mail page', () => {
|
|||||||
await expect(page.getByText(subject, { exact: true })).toBeVisible({ timeout: 15_000 });
|
await expect(page.getByText(subject, { exact: true })).toBeVisible({ timeout: 15_000 });
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (address) await deleteAddress(request, address.jwt);
|
await Promise.allSettled(addresses.map((address) => deleteAddress(request, address.jwt)));
|
||||||
if (userId !== undefined) {
|
if (userId !== undefined) {
|
||||||
await request.delete(`${WORKER_URL}/admin/users/${userId}`);
|
await request.delete(`${WORKER_URL}/admin/users/${userId}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,6 @@ const props = defineProps({
|
|||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
userAddressMode: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
addressOptions: {
|
addressOptions: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
@@ -50,7 +46,7 @@ const {
|
|||||||
|
|
||||||
const { t } = useScopedI18n('views.index.SendMail')
|
const { t } = useScopedI18n('views.index.SendMail')
|
||||||
|
|
||||||
const isUserAddressMode = computed(() => props.userAddressMode || props.addressId > 0)
|
const isUserAddressMode = computed(() => props.addressId > 0)
|
||||||
const mailSettings = computed(() => (
|
const mailSettings = computed(() => (
|
||||||
isUserAddressMode.value ? userAddressSettings.value : settings.value
|
isUserAddressMode.value ? userAddressSettings.value : settings.value
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -97,10 +97,9 @@ onMounted(fetchAddresses)
|
|||||||
<div class="user-mail-client">
|
<div class="user-mail-client">
|
||||||
<template v-if="mode === 'send_mail'">
|
<template v-if="mode === 'send_mail'">
|
||||||
<n-empty v-if="!selectedAddressId" class="address-empty" :description="t('noAddress')" />
|
<n-empty v-if="!selectedAddressId" class="address-empty" :description="t('noAddress')" />
|
||||||
<SendMail v-else :key="selectedAddressId" user-address-mode :address-id="selectedAddressId"
|
<SendMail v-else :key="selectedAddressId" v-model:address-id="selectedAddressId"
|
||||||
:address-options="addressOptions" :address-loading="addressLoading"
|
:address-options="addressOptions" :address-loading="addressLoading"
|
||||||
@address-scroll="handleAddressScroll" @update:address-id="selectedAddressId = $event"
|
@address-scroll="handleAddressScroll" @sent="emit('sent')" />
|
||||||
@sent="emit('sent')" />
|
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<n-input-group>
|
<n-input-group>
|
||||||
|
|||||||
@@ -90,8 +90,6 @@ The same user-address API group also provides:
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `GET` | `/user_api/address/:address_id/settings` | Get the address and remaining send balance |
|
| `GET` | `/user_api/address/:address_id/settings` | Get the address and remaining send balance |
|
||||||
| `POST` | `/user_api/address/:address_id/request_send_mail_access` | Request send access for the address |
|
| `POST` | `/user_api/address/:address_id/request_send_mail_access` | Request send access for the address |
|
||||||
| `GET` | `/user_api/address/:address_id/sendbox?limit=20&offset=0` | List sent items for the address with pagination |
|
|
||||||
| `DELETE` | `/user_api/address/:address_id/sendbox/:mail_id` | Delete one sent item for the address |
|
|
||||||
| `GET` | `/user_api/sendbox?limit=20&offset=0&address=optional-address` | List the current user's sent items, optionally filtered by a bound address |
|
| `GET` | `/user_api/sendbox?limit=20&offset=0&address=optional-address` | List the current user's sent items, optionally filtered by a bound address |
|
||||||
| `DELETE` | `/user_api/sendbox/:mail_id` | Delete one sent item owned by the current user |
|
| `DELETE` | `/user_api/sendbox/:mail_id` | Delete one sent item owned by the current user |
|
||||||
|
|
||||||
|
|||||||
@@ -90,8 +90,6 @@ res = requests.post(
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `GET` | `/user_api/address/:address_id/settings` | 获取地址和剩余发信额度 |
|
| `GET` | `/user_api/address/:address_id/settings` | 获取地址和剩余发信额度 |
|
||||||
| `POST` | `/user_api/address/:address_id/request_send_mail_access` | 为该地址申请发信权限 |
|
| `POST` | `/user_api/address/:address_id/request_send_mail_access` | 为该地址申请发信权限 |
|
||||||
| `GET` | `/user_api/address/:address_id/sendbox?limit=20&offset=0` | 分页获取该地址的发件箱 |
|
|
||||||
| `DELETE` | `/user_api/address/:address_id/sendbox/:mail_id` | 删除该地址的一条发件记录 |
|
|
||||||
| `GET` | `/user_api/sendbox?limit=20&offset=0&address=可选地址` | 分页获取当前用户的发件箱,可按绑定地址过滤 |
|
| `GET` | `/user_api/sendbox?limit=20&offset=0&address=可选地址` | 分页获取当前用户的发件箱,可按绑定地址过滤 |
|
||||||
| `DELETE` | `/user_api/sendbox/:mail_id` | 删除当前用户的一条发件记录 |
|
| `DELETE` | `/user_api/sendbox/:mail_id` | 删除当前用户的一条发件记录 |
|
||||||
|
|
||||||
|
|||||||
@@ -297,23 +297,17 @@ api.get('/api/sendbox', async (c) => {
|
|||||||
return getSendbox(c, address, limit, offset);
|
return getSendbox(c, address, limit, offset);
|
||||||
})
|
})
|
||||||
|
|
||||||
export const deleteSendbox = async (
|
api.delete('/api/sendbox/:id', async (c) => {
|
||||||
c: Context<HonoCustomType>, address: string, id: string | number
|
|
||||||
): Promise<Response> => {
|
|
||||||
const msgs = i18n.getMessagesbyContext(c);
|
const msgs = i18n.getMessagesbyContext(c);
|
||||||
if (!getBooleanValue(c.env.ENABLE_USER_DELETE_EMAIL)) {
|
if (!getBooleanValue(c.env.ENABLE_USER_DELETE_EMAIL)) {
|
||||||
return c.text(msgs.UserDeleteEmailDisabledMsg, 403)
|
return c.text(msgs.UserDeleteEmailDisabledMsg, 403)
|
||||||
}
|
}
|
||||||
|
const { address } = c.get("jwtPayload")
|
||||||
|
const { id } = c.req.param();
|
||||||
const { success } = await c.env.DB.prepare(
|
const { success } = await c.env.DB.prepare(
|
||||||
`DELETE FROM sendbox WHERE address = ? and id = ? `
|
`DELETE FROM sendbox WHERE address = ? and id = ? `
|
||||||
).bind(address, id).run();
|
).bind(address, id).run();
|
||||||
return c.json({
|
return c.json({
|
||||||
success: success
|
success: success
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
api.delete('/api/sendbox/:id', async (c) => {
|
|
||||||
const { address } = c.get("jwtPayload")
|
|
||||||
const { id } = c.req.param();
|
|
||||||
return deleteSendbox(c, address, id);
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ api.delete('/user_api/mails/:id', user_mail_api.deleteMail);
|
|||||||
api.get('/user_api/address/:address_id/settings', user_send_mail_api.settings);
|
api.get('/user_api/address/:address_id/settings', user_send_mail_api.settings);
|
||||||
api.post('/user_api/address/:address_id/request_send_mail_access', user_send_mail_api.requestAccess);
|
api.post('/user_api/address/:address_id/request_send_mail_access', user_send_mail_api.requestAccess);
|
||||||
api.post('/user_api/address/:address_id/send_mail', user_send_mail_api.send);
|
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.get('/user_api/sendbox', user_send_mail_api.listUserSendbox);
|
||||||
api.delete('/user_api/sendbox/:mail_id', user_send_mail_api.removeUserSendboxMail);
|
api.delete('/user_api/sendbox/:mail_id', user_send_mail_api.removeUserSendboxMail);
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,7 @@ import { Context } from "hono";
|
|||||||
|
|
||||||
import { commonGetUserRole, handleListQuery } from "../common";
|
import { commonGetUserRole, handleListQuery } from "../common";
|
||||||
import i18n from "../i18n";
|
import i18n from "../i18n";
|
||||||
import {
|
import { sendMail } from "../mails_api/send_mail_api";
|
||||||
deleteSendbox,
|
|
||||||
getSendbox,
|
|
||||||
sendMail,
|
|
||||||
} from "../mails_api/send_mail_api";
|
|
||||||
import {
|
import {
|
||||||
getSendBalanceState,
|
getSendBalanceState,
|
||||||
requestSendMailAccess,
|
requestSendMailAccess,
|
||||||
@@ -21,11 +17,12 @@ const getBindedAddress = async (
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const { user_id } = c.get("userPayload");
|
const { user_id } = c.get("userPayload");
|
||||||
return await c.env.DB.prepare(
|
const address = await c.env.DB.prepare(
|
||||||
`SELECT a.name FROM users_address ua`
|
`SELECT a.name FROM users_address ua`
|
||||||
+ ` JOIN address a ON a.id = ua.address_id`
|
+ ` JOIN address a ON a.id = ua.address_id`
|
||||||
+ ` WHERE ua.user_id = ? AND a.id = ?`
|
+ ` WHERE ua.user_id = ? AND a.id = ?`
|
||||||
).bind(user_id, addressId).first<string>("name");
|
).bind(user_id, addressId).first<string>("name");
|
||||||
|
return address ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getAddressOrError = async (
|
const getAddressOrError = async (
|
||||||
@@ -80,33 +77,17 @@ const send = async (c: Context<HonoCustomType>): Promise<Response> => {
|
|||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
await setUserRole(c);
|
await setUserRole(c);
|
||||||
|
const msgs = i18n.getMessagesbyContext(c);
|
||||||
try {
|
try {
|
||||||
const reqJson = await c.req.json();
|
const reqJson = await c.req.json();
|
||||||
await sendMail(c, address, reqJson);
|
await sendMail(c, address, reqJson);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to send user mail", error);
|
console.error("Failed to send user mail", error);
|
||||||
return c.text(`Failed to send mail ${(error as Error).message}`, 400);
|
return c.text(msgs.OperationFailedMsg, 500);
|
||||||
}
|
}
|
||||||
return c.json({ status: "ok" });
|
return c.json({ status: "ok" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const listSendbox = async (c: Context<HonoCustomType>): Promise<Response> => {
|
|
||||||
const address = await getAddressOrError(c);
|
|
||||||
if (address instanceof Response) {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
const { limit, offset } = c.req.query();
|
|
||||||
return getSendbox(c, address, limit, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeSendboxMail = async (c: Context<HonoCustomType>): Promise<Response> => {
|
|
||||||
const address = await getAddressOrError(c);
|
|
||||||
if (address instanceof Response) {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
return deleteSendbox(c, address, c.req.param("mail_id"));
|
|
||||||
}
|
|
||||||
|
|
||||||
const listUserSendbox = async (c: Context<HonoCustomType>): Promise<Response> => {
|
const listUserSendbox = async (c: Context<HonoCustomType>): Promise<Response> => {
|
||||||
const { user_id } = c.get("userPayload");
|
const { user_id } = c.get("userPayload");
|
||||||
const { address, limit, offset } = c.req.query();
|
const { address, limit, offset } = c.req.query();
|
||||||
@@ -149,8 +130,6 @@ export default {
|
|||||||
settings,
|
settings,
|
||||||
requestAccess,
|
requestAccess,
|
||||||
send,
|
send,
|
||||||
listSendbox,
|
|
||||||
removeSendboxMail,
|
|
||||||
listUserSendbox,
|
listUserSendbox,
|
||||||
removeUserSendboxMail,
|
removeUserSendboxMail,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user