11 changed files with 422 additions and 89 deletions
			
			
		| @ -0,0 +1,58 @@ | |||||
|  | const axios = require("axios"); | ||||
|  | const {R} = require("redbean-node"); | ||||
|  | 
 | ||||
|  | class Notification { | ||||
|  |     static async send(notification, msg) { | ||||
|  |         if (notification.type === "telegram") { | ||||
|  |             let res = await axios.get(`https://api.telegram.org/bot${notification.telegramBotToken}/sendMessage`, { | ||||
|  |                 params: { | ||||
|  |                     chat_id: notification.telegramChatID, | ||||
|  |                     text: msg, | ||||
|  |                 } | ||||
|  |             }) | ||||
|  |             return true; | ||||
|  |         } else { | ||||
|  |             throw new Error("Notification type is not supported") | ||||
|  |         } | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     static async save(notification, notificationID, userID) { | ||||
|  |         let bean | ||||
|  | 
 | ||||
|  |         if (notificationID) { | ||||
|  |             bean = await R.findOne("notification", " id = ? AND user_id = ? ", [ | ||||
|  |                 notificationID, | ||||
|  |                 userID, | ||||
|  |             ]) | ||||
|  | 
 | ||||
|  |             if (! bean) { | ||||
|  |                 throw new Error("notification not found") | ||||
|  |             } | ||||
|  | 
 | ||||
|  |         } else { | ||||
|  |             bean = R.dispense("notification") | ||||
|  |         } | ||||
|  | 
 | ||||
|  |         bean.name = notification.name; | ||||
|  |         bean.user_id = userID; | ||||
|  |         bean.config = JSON.stringify(notification) | ||||
|  |         await R.store(bean) | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     static async delete(notificationID, userID) { | ||||
|  |         let bean = await R.findOne("notification", " id = ? AND user_id = ? ", [ | ||||
|  |             notificationID, | ||||
|  |             userID, | ||||
|  |         ]) | ||||
|  | 
 | ||||
|  |         if (! bean) { | ||||
|  |             throw new Error("notification not found") | ||||
|  |         } | ||||
|  | 
 | ||||
|  |         await R.trash(bean) | ||||
|  |     } | ||||
|  | } | ||||
|  | 
 | ||||
|  | module.exports = { | ||||
|  |     Notification, | ||||
|  | } | ||||
| @ -1,7 +1,14 @@ | |||||
| import { defineConfig } from 'vite' | import { defineConfig } from 'vite' | ||||
| import vue from '@vitejs/plugin-vue' | import vue from '@vitejs/plugin-vue' | ||||
|  | import legacy from '@vitejs/plugin-legacy' | ||||
| 
 | 
 | ||||
| // https://vitejs.dev/config/
 | // https://vitejs.dev/config/
 | ||||
| export default defineConfig({ | export default defineConfig({ | ||||
|   plugins: [vue()] |   plugins: [ | ||||
|  |       vue(), | ||||
|  |       legacy({ | ||||
|  |           targets: ['ie >= 11'], | ||||
|  |           additionalLegacyPolyfills: ['regenerator-runtime/runtime'] | ||||
|  |       }) | ||||
|  |   ] | ||||
| }) | }) | ||||
|  | |||||
					Loading…
					
					
				
		Reference in new issue