From c5a749821cd6cf9743b08610e762ea2aa81c2f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=8A=B1=E8=8A=B1=E8=8A=B1=E5=84=BF?= <860563585bxy@gmail.com> Date: Tue, 9 Jan 2024 14:55:28 +0000 Subject: [PATCH] =?UTF-8?q?add=EF=BC=9A#=E5=96=B5=E5=96=B5=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 小花花花儿 <860563585bxy@gmail.com> --- apps/admin.js | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/apps/admin.js b/apps/admin.js index 8cfa3429..f57936b9 100644 --- a/apps/admin.js +++ b/apps/admin.js @@ -2,6 +2,8 @@ import fs from 'node:fs' import lodash from 'lodash' import { exec } from 'child_process' import { Cfg, Common, Data, Version, App } from '#miao' +import makemsg from "../../../lib/common/common.js" +import { execSync } from "child_process"; import fetch from 'node-fetch' let keys = lodash.map(Cfg.getCfgSchemaMap(), (i) => i.key) @@ -24,6 +26,11 @@ app.reg({ fn: updateMiaoPlugin, desc: '【#管理】喵喵更新' }, + updatelog: { + rule: /^#?喵喵更新日志$/, + fn: Miaoupdatelog, + desc: '【#管理】喵喵更新' + }, sysCfg: { rule: sysCfgReg, fn: sysCfg, @@ -51,7 +58,7 @@ const checkAuth = async function (e) { return true } -async function sysCfg (e) { +async function sysCfg(e) { if (!await checkAuth(e)) { return true } @@ -92,7 +99,7 @@ async function sysCfg (e) { }, { e, scale: 1.4 }) } -async function updateRes (e) { +async function updateRes(e) { if (!await checkAuth(e)) { return true } @@ -136,7 +143,7 @@ async function updateRes (e) { let timer -async function updateMiaoPlugin (e) { +async function updateMiaoPlugin(e) { if (!await checkAuth(e)) { return true } @@ -184,7 +191,36 @@ async function updateMiaoPlugin (e) { return true } -async function miaoApiInfo (e) { +async function Miaoupdatelog(e, plugin = 'miao-plugin') { + let cm = 'git log -20 --oneline --pretty=format:"%h||[%cd] %s" --date=format:"%F %T"' + if (plugin) { + cm = `cd ./plugins/${plugin}/ && ${cm}` + } + let logAll + try { + logAll = await execSync(cm, { encoding: 'utf-8', windowsHide: true }) + } catch (error) { + logger.error(error.toString()) + this.reply(error.toString()) + } + if (!logAll) return false + logAll = logAll.split('\n') + let log = [] + for (let str of logAll) { + str = str.split('||') + if (str[0] == this.oldCommitId) break + if (str[1].includes('Merge branch')) continue + log.push(str[1]) + } + let line = log.length + log = log.join('\n\n') + if (log.length <= 0) return '' + let end = '更多详细信息,请前往gitee查看\nhttps://gitee.com/yoimiya-kokomi/miao-plugin' + log = await makemsg.makeForwardMsg(this.e, [log, end], `${plugin}更新日志,共${line}条`) + e.reply(log) +} + +async function miaoApiInfo(e) { if (!await checkAuth(e)) { return true } @@ -202,4 +238,4 @@ async function miaoApiInfo (e) { return e.reply('token检查错误,请求失败') } e.reply(data.msg) -} +} \ No newline at end of file