Skip to content

Commit

Permalink
✨ 完成fcm推送
Browse files Browse the repository at this point in the history
  • Loading branch information
xkrfer committed Apr 17, 2022
1 parent be10f88 commit 7c42395
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
13 changes: 6 additions & 7 deletions src/helpers/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ if (FCM_API_KEY && FCM_PRIVATE_KEY && FCM_PUBLIC_KEY) {
}

export async function sendByFCM(pushSubscription: string, message: string) {
if (!pushSubscription || !(FCM_API_KEY && FCM_PRIVATE_KEY && FCM_PUBLIC_KEY))
return;
try {
await webpush.sendNotification(JSON.parse(pushSubscription), message);
} catch (err) {
logger.error('sendByFCM error', err);
}
logger.log(`fcm: ${message}`);
await webpush
.sendNotification(JSON.parse(pushSubscription), message)
.catch((err) => {
logger.error(err);
});
}
5 changes: 4 additions & 1 deletion src/modules/device/device.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export class DeviceController {
@Post('bind/fcm')
@HttpCode(200)
async bindFCM(@Body() body: BindDeviceFCMDto, @Session() session) {
const status = await this.deviceService.removeDevice(body, session.user);
const status = await this.deviceService.bindDeviceWithFCM(
body,
session.user,
);
return {
code: status ? Code.DONE : Code.ARGS,
error: '设备不存在或已注销',
Expand Down
1 change: 0 additions & 1 deletion src/modules/login/login.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class LoginController {
@Get('github')
async githubLogin(@Query() query, @Res() res) {
const token = await this.loginService.githubLogin(query.code);
// 设置cookie,signed启用加密
res.cookie('token', token, {
maxAge: 1000 * 60,
httpOnly: false,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
Body,
Controller,
Controller, Get,
HttpCode,
Post,
Session,
Expand Down Expand Up @@ -36,7 +36,7 @@ export class UserController {
};
}

@Post('config')
@Get('config')
@HttpCode(200)
@ApiOperation({ summary: '获取配置' })
async getConfig() {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions static/dist/assets/index.b34e7d35.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion static/dist/assets/index.fa27ff90.js

This file was deleted.

4 changes: 2 additions & 2 deletions static/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<link rel="icon" href="/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>pushdeer-web</title>
<script type="module" crossorigin src="/assets/index.fa27ff90.js"></script>
<link rel="stylesheet" href="/assets/index.deec828e.css">
<script type="module" crossorigin src="/assets/index.b34e7d35.js"></script>
<link rel="stylesheet" href="/assets/index.21dbb922.css">
</head>
<body>
<div id="app"></div>
Expand Down

0 comments on commit 7c42395

Please sign in to comment.