From d5b9bca68b121e358c73c22e41fc676c7c4a1cd7 Mon Sep 17 00:00:00 2001 From: whyour Date: Thu, 1 Apr 2021 23:50:24 +0800 Subject: [PATCH] =?UTF-8?q?git=5Fpull=20=E9=87=8D=E6=9E=84=EF=BC=8C?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +- back/api/config.ts | 2 +- back/config/index.ts | 6 + sample/crontab.list.sample | 55 +---- shell/git_pull.sh | 442 ++++++++++++++++++------------------- src/layouts/index.less | 11 +- src/layouts/index.tsx | 12 +- src/pages/code/index.tsx | 2 +- src/pages/config/index.tsx | 3 +- src/pages/cookie/index.tsx | 24 +- src/pages/diff/index.tsx | 4 +- src/pages/diy/index.tsx | 2 +- 12 files changed, 278 insertions(+), 290 deletions(-) diff --git a/.gitignore b/.gitignore index 042e6e73..db2d9a82 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,9 @@ /src/.umi-production /src/.umi-test /.env.local +.env + /config /log -.env \ No newline at end of file +/db +/manual_log \ No newline at end of file diff --git a/back/api/config.ts b/back/api/config.ts index 6bd4bf5b..d2539113 100644 --- a/back/api/config.ts +++ b/back/api/config.ts @@ -36,7 +36,7 @@ export default (app: Router) => { default: break; } - res.send({ code: 200, content }); + res.send({ code: 200, data: content }); } catch (e) { logger.error('🔥 error: %o', e); return next(e); diff --git a/back/config/index.ts b/back/config/index.ts index 830e10bb..1092c904 100644 --- a/back/config/index.ts +++ b/back/config/index.ts @@ -17,6 +17,9 @@ const logPath = path.join(rootPath, 'log/'); const authError = '错误的用户名密码,请重试'; const loginFaild = '请先登录!'; const configString = 'config sample crontab shareCode diy'; +const dbPath = path.join(rootPath, 'db/'); +const manualLogPath = path.join(rootPath, 'manual_log/'); +const cronDbFile = path.join(rootPath, 'db/crontab.db'); if (envFound.error) { throw new Error("⚠️ Couldn't find .env file ⚠️"); @@ -48,4 +51,7 @@ export default { 'crontab.list': crontabFile, 'diy.sh': diyFile, }, + dbPath, + cronDbFile, + manualLogPath, }; diff --git a/sample/crontab.list.sample b/sample/crontab.list.sample index 29c8028e..2ca7c064 100644 --- a/sample/crontab.list.sample +++ b/sample/crontab.list.sample @@ -1,5 +1,6 @@ # 更新shell及面板代码 55 2,13 * * * git_pull >> ${QL_DIR}/log/git_pull.log 2>&1 + # 更新你需要的仓库的代码 # diy test作者 test仓库 test路径1|test路径2 黑名单1文件名|黑名单2文件名 33 * * * * diy whyour hundun "quanx/jx|quanx/jd" tokens >> ${QL_DIR}/log/diy_pull.log 2>&1 @@ -14,49 +15,13 @@ # 导出所有互助码清单,日志在log/export_sharecodes下 48 5 * * * export_sharecodes -# 重启挂机脚本,挂机脚本可以随容器启动而启动,建议需要重启挂机程序时直接重启容器,如实在不想通过重启容器而重启挂机程序,可以解除下一行注释 -# 33 13 * * * js hangup +# 重启挂机脚本 +# 33 3 * * * js hangup -# 运行lxk0301大佬的js脚本,仅列出长期任务作初始化用,AutoAddCron=true时,将自动添加短期任务。 -# 请保留任务名称中的前缀"jd_",去掉后缀".js",如果有些任务你不想运行,注释掉就好了,不要删除。 -# 非lxk0301/jd_scripts仓库中的脚本不能以“jd_”、“jr_”、“jx_”开头。请在最后保留一个空行。 -5 9 * * * js jd_bean_change -28 5 * * * js jd_bean_home -4 0,9 * * * js jd_bean_sign -0,30 0 * * * js jd_blueCoin -12 8,12,18 * * * js jd_bookshop -37 7 * * * js jd_car -13 8,22 * * * js jd_cash -0 0 * * * js jd_car_exchange -2 0 * * * js jd_club_lottery -43 13 * * * js jd_crazy_joy -54 2-23/3 * * * js jd_daily_egg -20 * * * * js jd_dreamFactory -29 7,12,18 * * * js jd_fruit -49 6 * * * js jd_get_share_code -36 * * * * js jd_jdfactory -14 11 * * * js jd_jdzz -6 0,8,9,13,18,22 * * * js jd_joy -*/20 0-22 * * * js jd_joy_feedPets -0 0,8,12,16 * * * js jd_joy_reward -12 9-20/2 * * * js jd_joy_run -0 0,6 * * * js jd_joy_steal -0 9,12,18 * * * js jd_jxnc -32 7 * * * js jd_kd -13-33/5 13 * * * js jd_live -15 1 * * * js jd_lotteryMachine -40 */4 * * * js jd_moneyTree -20 0,20 * * * js jd_necklace -10 7,12,18 * * * js jd_pet -25 * * * * js jd_pigPet -35 7-22 * * * js jd_plantBean -11 0 * * * js jd_rankingList -1 1 * * * js jd_redPacket -0 0 * * * js jd_shop -16 0 * * * js jd_small_home -35 */3 * * * js jd_speed -9 1-23/5 * * * js jd_superMarket -25 9 * * * js jd_syj -44 5 * * 5 js jd_unbind -45 23 * * * js jd_unsubscribe -19 11 * * * js jx_sign +# 重置密码 +# 33 6 */7 * * js resetpwd + +# 运行所有脚本(慎用) +# 33 9 */7 * * js runall + +# 其他定时任务 diff --git a/shell/git_pull.sh b/shell/git_pull.sh index 3ae8ebdb..f5bb7810 100755 --- a/shell/git_pull.sh +++ b/shell/git_pull.sh @@ -1,163 +1,77 @@ #!/usr/bin/env bash -## 文件路径、脚本网址、文件版本以及各种环境的判断 -ShellDir=${QL_DIR:-$(cd $(dirname $0); pwd)} -[[ ${QL_DIR} ]] && ShellJs=js -LogDir=${ShellDir}/log -[ ! -d ${LogDir} ] && mkdir -p ${LogDir} -ScriptsDir=${ShellDir}/scripts -ConfigDir=${ShellDir}/config -FileConf=${ConfigDir}/config.sh -CookieConf=${ConfigDir}/cookie.sh -FileDiy=${ConfigDir}/diy.sh -FileConfSample=${ShellDir}/sample/config.sh.sample -ListCron=${ConfigDir}/crontab.list -ListCronLxk=${ScriptsDir}/docker/crontab_list.sh -ListTask=${LogDir}/task.list -ListJs=${LogDir}/js.list -ListJsAdd=${LogDir}/js-add.list -ListJsDrop=${LogDir}/js-drop.list -ContentVersion=${ShellDir}/version -ContentNewTask=${ShellDir}/new_task -ContentDropTask=${ShellDir}/drop_task -SendCount=${ShellDir}/send_count -isTermux=${ANDROID_RUNTIME_ROOT}${ANDROID_ROOT} +## 常量 +ShellDir=${QL_DIR:-$( + cd $(dirname $0) + pwd +)} +[[ $QL_DIR ]] && ShellJs=js +LogDir=$ShellDir/log +[ ! -d $LogDir ] && mkdir -p $LogDir +DbDir=$ShellDir/db +[ ! -d $DbDir ] && mkdir -p $DbDir +ManualLogDir=$ShellDir/manual_log +[ ! -d $ManualLogDir ] && mkdir -p $ManualLogDir +ScriptsDir=$ShellDir/scripts +ConfigDir=$ShellDir/config +FileConf=$ConfigDir/config.sh +CookieConf=$ConfigDir/cookie.sh +ExtraShell=$ConfigDir/extra.sh +FileConfSample=$ShellDir/sample/config.sh.sample +ListCronSample=$ShellDir/sample/crontab.list.sample +ListCronCurrent=$ConfigDir/crontab.list +ListCronRemote=$ScriptsDir/docker/crontab_list.sh +ListCurrentTask=$LogDir/task.list +ListRemoteTask=$LogDir/js.list +ListJsAdd=$LogDir/js-add.list +ListJsDrop=$LogDir/js-drop.list +ContentVersion=$ShellDir/version +ContentNewTask=$ShellDir/new_task +ContentDropTask=$ShellDir/drop_task +SendVersion=$ShellDir/send_version +isTermux=$ANDROID_RUNTIME_ROOT$ANDROID_ROOT ShellURL=https://github.com.cnpmjs.org/whyour/qinglong ScriptsURL=https://github.com.cnpmjs.org/gossh520/jd_scripts -## 导入配置文件 -function Import_Conf { - if [ -f ${FileConf} ]; then - . ${CookieConf} - . ${FileConf} +Import_Conf() { + if [ ! -s $FileConf ]; then + echo -e "复制一份 $FileConfSample 示例配置文件\n\n" + cp -fv $FileConfSample $FileConf fi + if [ ! -s $ListCronCurrent ]; then + echo -e "复制一份 $ListCronSample 基础定时任务\n\n" + cp -fv $ListCronSample $ListCronCurrent + fi + [ -f $CookieConf ] && . $CookieConf + [ -f $FileConf ] && . $FileConf } -## 更新crontab,gitee服务器同一时间限制5个链接,因此每个人更新代码必须错开时间,每次执行git_pull随机生成。 -## 每天次数随机,更新时间随机,更新秒数随机,至少6次,至多12次,大部分为8-10次,符合正态分布。 -function Update_Cron { - if [[ $(date "+%-H") -le 2 ]] && [ -f ${ListCron} ]; then - RanMin=$((${RANDOM} % 60)) - RanSleep=$((${RANDOM} % 56)) - RanHourArray[0]=$((${RANDOM} % 3)) - for ((i=1; i<14; i++)); do - j=$(($i - 1)) - tmp=$((${RANDOM} % 3 + ${RanHourArray[j]} + 2)) - [[ ${tmp} -lt 24 ]] && RanHourArray[i]=${tmp} || break - done - RanHour=${RanHourArray[0]} - for ((i=1; i<${#RanHourArray[*]}; i++)); do - RanHour="${RanHour},${RanHourArray[i]}" - done - perl -i -pe "s|.+(git_pull? .+git_pull\.log.*)|${RanMin} ${RanHour} \* \* \* sleep ${RanSleep} && \1|" ${ListCron} - crontab ${ListCron} - fi -} -function Git_PullShell { +# 更新shell +Git_Pull_Shell() { echo -e "更新shell...\n" - cd ${ShellDir} + cd $ShellDir git remote set-url origin $ShellURL git fetch --all ExitStatusShell=$? git reset --hard origin/master git pull - echo } -## 更新shell成功后的操作 -function Git_PullShellNext { - if [[ ${ExitStatusShell} -eq 0 ]]; then +Git_Pull_Shell_Next() { + if [[ $ExitStatusShell -eq 0 ]]; then echo -e "更新shell成功...\n" - [[ "${PanelDependOld}" != "${PanelDependNew}" ]] && cd ${ShellDir}/panel && Npm_Install panel - cp -f ${FileConfSample} ${ConfigDir}/config.sh.sample - [ -d ${ScriptsDir}/node_modules ] && Notify_Version + [ ! -d $ShellDir/node_modules ] && Npm_Install panel + [ -f $ShellDir/package.json ] && PanelDependNew=$(cat $ShellDir/package.json) + [[ "$PanelDependOld" != "$PanelDependNew" ]] && cd $ShellDir && Npm_Install panel + cp -f $FileConfSample $ConfigDir/config.sh.sample + Notify_Version else echo -e "更新shell失败,请检查原因...\n" fi } -## 克隆scripts -function Git_CloneScripts { - git clone -b master ${ScriptsURL} ${ScriptsDir} - ExitStatusScripts=$? - echo -} - -## 更新scripts -function Git_PullScripts { - echo -e "更新scripts...\n" - cd ${ScriptsDir} - git remote set-url origin $ScriptsURL - git fetch --all - ExitStatusScripts=$? - git reset --hard origin/master - git pull - echo -} - -## 检测文件:LXK9301/jd_scripts 仓库中的 docker/crontab_list.sh -## 检测定时任务是否有变化,此函数会在Log文件夹下生成四个文件,分别为: -## task.list crontab.list中的所有任务清单,仅保留脚本名 -## js.list 上述检测文件中用来运行js脚本的清单(去掉后缀.js,非运行脚本的不会包括在内) -## js-add.list 如果上述检测文件增加了定时任务,这个文件内容将不为空 -## js-drop.list 如果上述检测文件删除了定时任务,这个文件内容将不为空 -function Diff_Cron { - if [ -f ${ListCron} ]; then - if [ -n "${QL_DIR}" ] - then - grep -E " j[drx]_\w+" ${ListCron} | perl -pe "s|.+ (j[drx]_\w+).*|\1|" | sort -u > ${ListTask} - else - grep "${ShellDir}/" ${ListCron} | grep -E " j[drx]_\w+" | perl -pe "s|.+ (j[drx]_\w+).*|\1|" | sort -u > ${ListTask} - fi - cat ${ListCronLxk} | grep -E "j[drx]_\w+\.js" | perl -pe "s|.+(j[drx]_\w+)\.js.+|\1|" | sort -u > ${ListJs} - grep -vwf ${ListTask} ${ListJs} > ${ListJsAdd} - grep -vwf ${ListJs} ${ListTask} > ${ListJsDrop} - else - echo -e "${ListCron} 文件不存在,请先定义你自己的crontab.list...\n" - fi -} - -## 检测配置文件版本 -function Notify_Version { - ## 识别出两个文件的版本号 - VerConfSample=$(grep " Version: " ${FileConfSample} | perl -pe "s|.+v((\d+\.?){3})|\1|") - [ -f ${FileConf} ] && VerConf=$(grep " Version: " ${FileConf} | perl -pe "s|.+v((\d+\.?){3})|\1|") - - ## 删除旧的发送记录文件 - [ -f "${SendCount}" ] && [[ $(cat ${SendCount}) != ${VerConfSample} ]] && rm -f ${SendCount} - - ## 识别出更新日期和更新内容 - UpdateDate=$(grep " Date: " ${FileConfSample} | awk -F ": " '{print $2}') - UpdateContent=$(grep " Update Content: " ${FileConfSample} | awk -F ": " '{print $2}') - - ## 如果是今天,并且版本号不一致,则发送通知 - if [ -f ${FileConf} ] && [[ "${VerConf}" != "${VerConfSample}" ]] && [[ ${UpdateDate} == $(date "+%Y-%m-%d") ]] - then - if [ ! -f ${SendCount} ]; then - notify "检测到配置文件config.sh.sample有更新" "更新日期: ${UpdateDate}\n当前版本: ${VerConf}\n新的版本: ${VerConfSample}\n更新内容: ${UpdateContent}\n更新说明: 如需使用新功能请对照config.sh.sample,将相关新参数手动增加到你自己的config.sh中,否则请无视本消息。本消息只在该新版本配置文件更新当天发送一次。" - fi - else - [ -f ${ContentVersion} ] && rm -f ${ContentVersion} - [ -f ${SendCount} ] && rm -f ${SendCount} - fi -} - -## npm install 子程序,判断是否为安卓,判断是否安装有yarn -function Npm_InstallSub { - if [ -n "${isTermux}" ] - then - npm install --no-bin-links --no-save || npm install --no-save --no-bin-links --registry=https://registry.npm.taobao.org - elif ! type yarn >/dev/null 2>&1 - then - npm install --no-save || npm install --no-save --registry=https://registry.npm.taobao.org - else - echo -e "检测到本机安装了 yarn,使用 yarn 替代 npm...\n" - yarn install || yarn install --registry=https://registry.npm.taobao.org - fi -} - ## npm install -function Npm_Install { +Npm_Install() { echo -e "检测到 $1 的依赖包有变化,运行 npm install...\n" Npm_InstallSub if [ $? -ne 0 ]; then @@ -183,131 +97,197 @@ function Npm_Install { fi } -## 输出是否有新的定时任务 -function Output_ListJsAdd { - if [ -s ${ListJsAdd} ]; then - echo -e "检测到有新的定时任务:\n" - cat ${ListJsAdd} - echo +## npm install 子程序,判断是否为安卓,判断是否安装有yarn +function Npm_InstallSub() { + if [ -n "$isTermux" ]; then + npm install --no-bin-links --no-save || npm install --no-save --no-bin-links --registry=https://registry.npm.taobao.org + elif ! type yarn >/dev/null 2>&1; then + npm install --no-save || npm install --no-save --registry=https://registry.npm.taobao.org + else + echo -e "检测到本机安装了 yarn,使用 yarn 替代 npm...\n" + yarn install || yarn install --registry=https://registry.npm.taobao.org fi } -## 输出是否有失效的定时任务 -function Output_ListJsDrop { - if [ ${ExitStatusScripts} -eq 0 ] && [ -s ${ListJsDrop} ]; then - echo -e "检测到有失效的定时任务:\n" - cat ${ListJsDrop} - echo - fi -} +## 检测配置文件版本 +Notify_Version() { + ## 识别出两个文件的版本号 + VerConfSample=$(grep " Version: " $FileConfSample | perl -pe "s|.+v((\d+\.?){3})|\1|") + [ -f $FileConf ] && VerConf=$(grep " Version: " $FileConf | perl -pe "s|.+v((\d+\.?){3})|\1|") -## 自动删除失效的脚本与定时任务,需要5个条件:1.AutoDelCron 设置为 true;2.正常更新js脚本,没有报错;3.js-drop.list不为空;4.crontab.list存在并且不为空;5.已经正常运行过npm install -## 检测文件:LXK9301/jd_scripts 仓库中的 docker/crontab_list.sh -## 如果检测到某个定时任务在上述检测文件中已删除,那么在本地也删除对应定时任务 -function Del_Cron { - if [ "${AutoDelCron}" = "true" ] && [ -s ${ListJsDrop} ] && [ -s ${ListCron} ] && [ -d ${ScriptsDir}/node_modules ]; then - echo -e "开始尝试自动删除定时任务如下:\n" - cat ${ListJsDrop} - echo - JsDrop=$(cat ${ListJsDrop}) - for Cron in ${JsDrop} - do - perl -i -ne "{print unless / ${Cron}( |$)/}" ${ListCron} - done - crontab ${ListCron} - echo -e "成功删除失效的脚本与定时任务,当前的定时任务清单如下:\n\n--------------------------------------------------------------\n" - crontab -l - echo -e "\n--------------------------------------------------------------\n" - if [ -d ${ScriptsDir}/node_modules ]; then - notify "删除 lxk0301 失效脚本" "${JsDrop}" + ## 删除旧的发送记录文件 + [ -f "$SendVersion" ] && [[ $(cat $SendVersion) != $VerConfSample ]] && rm -f $SendVersion + + ## 识别出更新日期和更新内容 + UpdateDate=$(grep " Date: " $FileConfSample | awk -F ": " '{print $2}') + UpdateContent=$(grep " Update Content: " $FileConfSample | awk -F ": " '{print $2}') + + ## 如果是今天,并且版本号不一致,则发送通知 + if [ -f $FileConf ] && [[ "$VerConf" != "$VerConfSample" ]] && [[ $UpdateDate == $(date "+%Y-%m-%d") ]]; then + if [ ! -f $SendVersion ]; then + notify "检测到配置文件config.sh.sample有更新" "更新日期: $UpdateDate\n当前版本: $VerConf\n新的版本: $VerConfSample\n更新内容: $UpdateContent\n更新说明: 如需使用新功能请对照config.sh.sample,将相关新参数手动增加到你自己的config.sh中,否则请无视本消息。本消息只在该新版本配置文件更新当天发送一次。" fi + else + [ -f $ContentVersion ] && rm -f $ContentVersion + [ -f $SendVersion ] && rm -f $SendVersion fi } -## 自动增加新的定时任务,需要5个条件:1.AutoAddCron 设置为 true;2.正常更新js脚本,没有报错;3.js-add.list不为空;4.crontab.list存在并且不为空;5.已经正常运行过npm install -## 检测文件:LXK9301/jd_scripts 仓库中的 docker/crontab_list.sh -## 如果检测到检测文件中增加新的定时任务,那么在本地也增加 -## 本功能生效时,会自动从检测文件新增加的任务中读取时间,该时间为北京时间 -function Add_Cron { - if [ "${AutoAddCron}" = "true" ] && [ -s ${ListJsAdd} ] && [ -s ${ListCron} ] && [ -d ${ScriptsDir}/node_modules ]; then - echo -e "开始尝试自动添加定时任务如下:\n" - cat ${ListJsAdd} - echo - JsAdd=$(cat ${ListJsAdd}) +## 每天次数随机,更新时间随机,更新秒数随机,至少6次,至多12次,大部分为8-10次,符合正态分布。 +Random_Pull_Cron() { + if [[ $(date "+%-H") -le 2 ]]; then + RanMin=$(($RANDOM % 60)) + RanSleep=$(($RANDOM % 56)) + RanHourArray[0]=$(($RANDOM % 3)) + for ((i = 1; i < 14; i++)); do + j=$(($i - 1)) + tmp=$(($RANDOM % 3 + ${RanHourArray[j]} + 2)) + [[ $tmp -lt 24 ]] && RanHourArray[i]=$tmp || break + done + + for ((i = 1; i < ${#RanHourArray[*]}; i++)); do + RanHour="$RanHour,${RanHourArray[i]}" + done + + perl -i -pe "s|.+(git_pull? .+git_pull\.log.*)|$RanMin $RanHour \* \* \* sleep $RanSleep && \1|" $ListCronCurrent + crontab $ListCronCurrent + fi +} - for Cron in ${JsAdd} - do - if [[ ${Cron} == jd_bean_sign ]] - then - echo "4 0,9 * * * ${ShellJs} ${Cron}" >> ${ListCron} +## 克隆scripts +Git_Clone_Scripts() { + git clone -b master $ScriptsURL $ScriptsDir + ExitStatusScripts=$? +} + +## 更新scripts +Git_Pull_Scripts() { + if [ -d $ScriptsDir/.git ]; then + echo -e "更新scripts...\n" + cd $ScriptsDir + git remote set-url origin $ScriptsURL + git fetch --all + ExitStatusScripts=$? + git reset --hard origin/master + git pull + else + Git_Clone_Scripts + fi +} + +Git_Pull_Scripts_Next() { + if [[ $ExitStatusShell -eq 0 ]]; then + echo -e "更新scripts成功...\n" + [ ! -d $ScriptsDir/node_modules ] && Npm_Install scripts + [ -f $ScriptsDir/package.json ] && ScriptsDependNew=$(cat $ScriptsDir/package.json) + [[ "$ScriptsDependOld" != "$ScriptsDependNew" ]] && cd $ScriptsDir && Npm_Install scripts + Diff_Cron + if [ -s $ListJsDrop ]; then + Output_ListJs $ListJsDrop "失效" + Del_Cron + fi + if [ -s $ListJsAdd ]; then + Output_ListJs $ListJsAdd "新" + Add_Cron + fi + else + echo -e "更新scripts失败,请检查原因...\n" + fi +} + +Diff_Cron() { + cat $ListCronRemote | grep -E "node.+j[drx]_\w+\.js" | perl -pe "s|.+(j[drx]_\w+)\.js.+|\1|" | sort -u >$ListRemoteTask + cat $ListCronCurrent | grep -E "$ShellJs j[drx]_\w+" | perl -pe "s|.*$ShellJs (j[drx]_\w+)\.*|\1|" | sort -u >$ListCurrentTask + if [ -s $ListCurrentTask ]; then + grep -vwf $ListCurrentTask $ListRemoteTask >$ListJsAdd + else + cp -f $ListRemoteTask $ListJsAdd + fi + if [ -s $ListRemoteTask ]; then + grep -vwf $ListRemoteTask $ListCurrentTask >$ListJsDrop + else + cp -f $ListCurrentTask $ListJsDrop + fi +} + +Del_Cron() { + if [ $AutoDelCron == true ] && [ -s $ListJsDrop ]; then + echo -e "开始尝试自动删除定时任务如下:\n" + cat $ListJsDrop + echo + JsDrop=$(cat $ListJsDrop) + for Cron in $JsDrop; do + perl -i -ne "{print unless / $Cron( |$)/}" $ListCronCurrent + done + crontab $ListCronCurrent + echo -e "成功删除失效的脚本与定时任务\n" + notify "删除 lxk0301 失效脚本" "$JsDrop" + fi +} + +Add_Cron() { + if [ $AutoAddCron == true ] && [ -s $ListJsAdd ]; then + echo -e "开始尝试自动添加定时任务\n" + JsAdd=$(cat $ListJsAdd) + for Cron in $JsAdd; do + if [[ $Cron == jd_bean_sign ]]; then + echo "4 0,9 * * * $ShellJs $Cron" >> $ListCronCurrent else - cat ${ListCronLxk} | grep -E "\/${Cron}\." | perl -pe "s|(^.+)node */scripts/(j[drx]_\w+)\.js.+|\1${ShellJs} \2|" >> ${ListCron} + cat $ListCronRemote | grep -E "\/$Cron\." | perl -pe "s|(^.+)node */scripts/(j[drx]_\w+)\.js.+|\1$ShellJs \2|" >> $ListCronCurrent fi done - if [ $? -eq 0 ] - then - crontab ${ListCron} - echo -e "成功添加新的定时任务,当前的定时任务清单如下:\n\n--------------------------------------------------------------\n" - crontab -l - echo -e "\n--------------------------------------------------------------\n" - if [ -d ${ScriptsDir}/node_modules ]; then - notify "新增 lxk0301 自定义脚本" "${JsAdd}" - fi + if [ $? -eq 0 ]; then + crontab $ListCronCurrent + echo -e "成功添加新的定时任务...\n" + notify "新增lxk0301脚本" "$JsAdd" else echo -e "添加新的定时任务出错,请手动添加...\n" - if [ -d ${ScriptsDir}/node_modules ]; then - notify "尝试自动添加 lxk0301 以下新的定时任务出错,请手动添加:" "${JsAdd}" - fi + notify "尝试自动添加lxk0301以下新的定时任务出错,请手动添加:" "$JsAdd" fi fi } -## 在日志中记录时间与路径 +## 输出定时任务变化 +Output_ListJs() { + local list=$1 + local type=$2 + if [ -s $list ]; then + echo -e "检测到有$type的定时任务:\n" + cat $list + echo + fi +} + +################################################################################################################################# echo -e "\n--------------------------------------------------------------\n" echo -n "系统时间:" echo $(date "+%Y-%m-%d %H:%M:%S") if [ "${TZ}" = "UTC" ]; then - echo echo -n "北京时间:" echo $(date -d "8 hour" "+%Y-%m-%d %H:%M:%S") fi -echo -e "\nJS脚本目录:${ScriptsDir}\n" +echo -e "\nJS脚本目录:$ScriptsDir\n" echo -e "--------------------------------------------------------------\n" -## 导入配置,更新cron,设置url,更新shell,复制sample,复制entrypoint,发送新配置通知 -Import_Conf "git_pull" -Update_Cron -[ -f ${ShellDir}/panel/package.json ] && PanelDependOld=$(cat ${ShellDir}/panel/package.json) -Git_PullShell -[ -f ${ShellDir}/panel/package.json ] && PanelDependNew=$(cat ${ShellDir}/panel/package.json) -Git_PullShellNext +Import_Conf +Random_Pull_Cron -## 克隆或更新js脚本 -[ -f ${ScriptsDir}/package.json ] && ScriptsDependOld=$(cat ${ScriptsDir}/package.json) -[ -d ${ScriptsDir}/.git ] && Git_PullScripts || Git_CloneScripts -[ -f ${ScriptsDir}/package.json ] && ScriptsDependNew=$(cat ${ScriptsDir}/package.json) +# 更新shell +[ -f $ShellDir/package.json ] && PanelDependOld=$(cat $ShellDir/package.json) +Git_Pull_Shell +Git_Pull_Shell_Next -## 执行各函数 -if [[ ${ExitStatusScripts} -eq 0 ]] -then - echo -e "更新scripts成功...\n" - Diff_Cron - [[ "${ScriptsDependOld}" != "${ScriptsDependNew}" ]] && cd ${ScriptsDir} && Npm_Install scripts - Output_ListJsAdd - Output_ListJsDrop - Del_Cron - Add_Cron -else - echo -e "更新scripts失败,请检查原因...\n" -fi +## 更新scripts +[ -f $ScriptsDir/package.json ] && ScriptsDependOld=$(cat $ScriptsDir/package.json) +Git_Pull_Scripts +Git_Pull_Scripts_Next -## 调用用户自定义的diy.sh -if [[ ${EnableExtraShell} == true ]]; then - if [ -f ${FileDiy} ] - then - . ${FileDiy} +## 调用用户自定义的extra.sh +if [[ $EnableExtraShell == true ]]; then + if [ -f $ExtraShell ]; then + . $ExtraShell else - echo -e "${FileDiy} 文件不存在,跳过执行DIY脚本...\n" + echo -e "$ExtraShell 文件不存在,跳过执行DIY脚本...\n" fi fi diff --git a/src/layouts/index.less b/src/layouts/index.less index aabc4d70..0a59c478 100644 --- a/src/layouts/index.less +++ b/src/layouts/index.less @@ -8,7 +8,7 @@ body { .code-mirror-wrapper .CodeMirror { position: absolute; - height: calc(100% - 24px); + height: calc(100% - 48px); width: 100%; } @@ -19,5 +19,14 @@ body { overflow: auto; height: calc(100vh - 96px); background-color: #fff; + padding: 24px; + } +} + +@media (max-width: 768px) { + .ant-pro-grid-content.wide { + .ant-pro-page-container-children-content { + height: calc(100vh - 144px); + } } } diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index c4d6e934..973cea42 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -39,11 +39,19 @@ export default function (props: any) { const theme = localStorage.getItem('qinglong_dark_theme') || 'auto'; setFetchMethod(window.fetch); if (theme === 'dark') { - enableDarkMode({ darkSchemeTextColor: '#fff' }); + enableDarkMode({ + brightness: 100, + contrast: 90, + sepia: 10, + }); } else if (theme === 'light') { disableDarkMode(); } else { - followSystemColorScheme({ darkSchemeTextColor: '#fff' }); + followSystemColorScheme({ + brightness: 100, + contrast: 90, + sepia: 10, + }); } }, []); diff --git a/src/pages/code/index.tsx b/src/pages/code/index.tsx index f7818c39..b5e4194c 100644 --- a/src/pages/code/index.tsx +++ b/src/pages/code/index.tsx @@ -17,7 +17,7 @@ const Crontab = () => { request .get(`${config.apiPrefix}config/shareCode`) .then((data) => { - setValue(data.content); + setValue(data.data); }) .finally(() => setLoading(false)); }; diff --git a/src/pages/config/index.tsx b/src/pages/config/index.tsx index 9618188f..ba35b07e 100644 --- a/src/pages/config/index.tsx +++ b/src/pages/config/index.tsx @@ -4,7 +4,6 @@ import config from '@/utils/config'; import { PageContainer } from '@ant-design/pro-layout'; import { Controlled as CodeMirror } from 'react-codemirror2'; import { request } from '@/utils/http'; -import QRCode from 'qrcode.react'; const Config = () => { const [width, setWdith] = useState('100%'); @@ -18,7 +17,7 @@ const Config = () => { request .get(`${config.apiPrefix}config/config`) .then((data) => { - setValue(data.content); + setValue(data.data); }) .finally(() => setLoading(false)); }; diff --git a/src/pages/cookie/index.tsx b/src/pages/cookie/index.tsx index 79439434..2385c0b1 100644 --- a/src/pages/cookie/index.tsx +++ b/src/pages/cookie/index.tsx @@ -1,5 +1,13 @@ import React, { PureComponent, Fragment, useState, useEffect } from 'react'; -import { Button, notification, Modal, Table, Tag, Space } from 'antd'; +import { + Button, + notification, + Modal, + Table, + Tag, + Space, + Typography, +} from 'antd'; import { EditOutlined, DeleteOutlined } from '@ant-design/icons'; import config from '@/utils/config'; import { PageContainer } from '@ant-design/pro-layout'; @@ -7,6 +15,8 @@ import { request } from '@/utils/http'; import QRCode from 'qrcode.react'; import CookieModal from './modal'; +const { Text } = Typography; + enum Status { '正常', '失效', @@ -197,7 +207,11 @@ const Config = () => { const deleteCookie = (record: any, index: number) => { Modal.confirm({ title: '确认删除', - content: `确认删除Cookie ${record.cookie} 吗`, + content: ( + <> + 确认删除Cookie {record.cookie} 吗 + + ), onOk() { request .delete(`${config.apiPrefix}cookie`, { @@ -270,7 +284,11 @@ const Config = () => { > { const getConfig = () => { request.get(`${config.apiPrefix}config/config`).then((data) => { - setValue(data.content); + setValue(data.data); }); }; @@ -25,7 +25,7 @@ const Crontab = () => { request .get(`${config.apiPrefix}config/sample`) .then((data) => { - setSample(data.content); + setSample(data.data); }) .finally(() => setLoading(false)); }; diff --git a/src/pages/diy/index.tsx b/src/pages/diy/index.tsx index 348071c4..cd223b90 100644 --- a/src/pages/diy/index.tsx +++ b/src/pages/diy/index.tsx @@ -17,7 +17,7 @@ const Crontab = () => { request .get(`${config.apiPrefix}config/diy`) .then((data) => { - setValue(data.content); + setValue(data.data); }) .finally(() => setLoading(false)); };