Browse Source

✨ feat: 公告功能上线

Pchen. 4 months ago
parent
commit
6bf5903a5e
1 changed files with 37 additions and 0 deletions
  1. 37 0
      apis/Public/GetNotice.js

+ 37 - 0
apis/Public/GetNotice.js

@@ -0,0 +1,37 @@
+const API = require("../../lib/API")
+const db = require("../../plugin/DataBase/db")
+const { BaseStdResponse } = require("../../BaseStdResponse")
+
+class GetNotice extends API {
+    constructor() {
+        super();
+
+        this.setPath('/Public/GetNotice')
+        this.setMethod('GET')
+    }
+
+    async onRequest(req, res) {
+        let { key } = req.query
+
+        if ([key].some(value => value === '' || value === null || value === undefined))
+            return res.json({
+                ...BaseStdResponse.MISSING_PARAMETER
+            })
+
+        let sql = 'SELECT content FROM notice WHERE \`key\` = ?'
+        let rows = await db.query(sql, [key])
+
+        if (!rows || rows.length === 0)
+            return res.json({
+                ...BaseStdResponse.OK,
+                msg: ''
+            })
+
+        res.json({
+            ...BaseStdResponse.OK,
+            msg: rows[0].content || ''
+        })
+    }
+}
+
+module.exports.GetNotice = GetNotice