Skip to content

Commit

Permalink
fix: handle missing user info to prevent panic
Browse files Browse the repository at this point in the history
  • Loading branch information
gizmo-ds committed Apr 20, 2024
1 parent 0955eac commit 98fe7a8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion routes/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { EmbedField } from '@/discord/types';

export default eventHandler(async e => {
if (!DISCORD_WEBHOOK_URL || DISCORD_WEBHOOK_URL === '') return { ec: 200 };
if (!WEBHOOK_SECRET || WEBHOOK_SECRET === '') return { ec: 200 };

const query = new URL(e.node.req.url, `http://${e.node.req.headers['host']}`)
.searchParams;
Expand All @@ -14,14 +15,17 @@ export default eventHandler(async e => {

const data: WebHookRequest = JSON.parse(body);
const order = data.data.order;
// TODO: 暂时只支持赞助, 售卖方案目前不支持
if (order.product_type !== 0) return { ec: 200 };

let user = {
name: '爱发电用户',
avatar: 'https://pic1.afdiancdn.com/default/avatar/avatar-purple.png',
user_id: order.user_id
};
try {
user = (await getProfile(order.user_id)).data.user;
const _user = (await getProfile(order.user_id)).data.user;
if (_user) user = _user;
} catch (error) {}

const fields: EmbedField[] = [];
Expand Down

0 comments on commit 98fe7a8

Please sign in to comment.