Skip to content

Commit

Permalink
Optimized Notification
Browse files Browse the repository at this point in the history
Signed-off-by: jingyang <[email protected]>
  • Loading branch information
zjy365 committed Apr 22, 2024
1 parent 0a664ce commit 17aa4b8
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 27 deletions.
7 changes: 1 addition & 6 deletions frontend/packages/client-sdk/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { v4 } from 'uuid';
import { API_NAME } from './constants';
import {
AppMessageType,
AppSendMessageType,
MasterReplyMessageType,
SessionV1
} from './types';
import { AppMessageType, AppSendMessageType, MasterReplyMessageType, SessionV1 } from './types';
import { isBrowser } from './utils';

class ClientSDK {
Expand Down
4 changes: 3 additions & 1 deletion frontend/providers/workorder/src/api/platform.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SystemEnvResponse } from '@/pages/api/platform/getEnv';
import { GET, POST } from '@/services/request';
import { AppSession } from '@/types/user';
import { WorkOrderEditForm } from '@/types/workorder';
import { AxiosProgressEvent } from 'axios';

export const getSystemEnv = () => GET<SystemEnvResponse>('/api/platform/getEnv');
Expand Down Expand Up @@ -34,4 +35,5 @@ export const deleteFileByName = ({ fileName }: { fileName: string }) => {
export const AuthByDesktopSession = (payload: { token: string }) =>
POST<AppSession>('/api/auth/desktop', payload);

export const FeishuNotification = () => POST('/api/platform/feishu');
export const FeishuNotification = (payload: WorkOrderEditForm) =>
POST('/api/platform/feishu', payload);
1 change: 0 additions & 1 deletion frontend/providers/workorder/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ function App({ Component, pageProps }: AppProps) {
const { domain } = await initSystemEnv();
try {
const res = await sealosApp.getSession();
console.log(res, 'session=====');
if (!res?.token) return;
authUser(res.token);
} catch (err) {
Expand Down
48 changes: 33 additions & 15 deletions frontend/providers/workorder/src/pages/api/platform/feishu.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,50 @@
import { verifyAccessToken } from '@/services/backend/auth';
import { jsonRes } from '@/services/backend/response';
import { ApiResp } from '@/services/kubernet';
import { WorkOrderEditForm } from '@/types/workorder';
import type { NextApiRequest, NextApiResponse } from 'next';

export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) {
try {
const userForm = req.body as WorkOrderEditForm;
const { userId } = await verifyAccessToken(req);
const feishuUrl = process.env.ADMIN_FEISHU_URL;
const feishuCallBackUrl = process.env.ADMIN_FEISHU_CALLBACK_URL;

const payload = {
msg_type: 'post',
content: {
post: {
zh_cn: {
title: '工单提醒',
content: [
[
{
tag: 'text',
text: '有新工单: '
msg_type: 'interactive',
card: {
elements: [
{
tag: 'markdown',
content: `**用户ID:** ${userId}\n所属分类: ${userForm.type}\n描述信息: ${userForm.description}`
},
{
tag: 'action',
actions: [
{
tag: 'button',
text: {
tag: 'plain_text',
content: '查看详情'
},
{
tag: 'a',
text: '请查看链接',
href: feishuCallBackUrl
type: 'primary',
multi_url: {
url: feishuCallBackUrl,
android_url: '',
ios_url: '',
pc_url: ''
}
]
}
]
}
],
header: {
template: 'blue',
title: {
content: '有新的工单,请立即查看',
tag: 'plain_text'
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
data: result
});
} catch (error) {
jsonRes(res, { code: 500, data: error });
console.log(error);
jsonRes(res, { code: 500, error: error });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function EditOrder() {
orderId: res.orderId,
content: data.description
});
await FeishuNotification();
await FeishuNotification(data);
toast({
status: 'success',
title: 'success'
Expand Down
3 changes: 1 addition & 2 deletions frontend/providers/workorder/src/services/backend/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AppTokenPayload, DesktopTokenPayload } from '@/types/user';
import { verify, sign } from 'jsonwebtoken';
import type { NextApiRequest } from 'next';
import { ERROR_ENUM } from '../error';
import { reject } from 'lodash';

const desktopJwtSecret = (process.env.DESKTOP_JWT_SECRET as string) || '123456789';
const appJwtSecret = (process.env.APP_JWT_SECRET as string) || '123456789';
Expand Down Expand Up @@ -30,7 +29,7 @@ export const verifyDesktopToken: (token: string) => Promise<DesktopTokenPayload
});

export const verifyAppToken: (token: string) => Promise<AppTokenPayload> = (token) =>
new Promise((resolve) => {
new Promise((resolve, reject) => {
verify(token, appJwtSecret, (err, payload) => {
if (err) {
reject(err);
Expand Down

0 comments on commit 17aa4b8

Please sign in to comment.