From 92735020086eefeb9033fcee09e82f413c3d6f6e Mon Sep 17 00:00:00 2001 From: shanmite <1971513084@qq.com> Date: Wed, 24 Feb 2021 17:25:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BE=AA=E7=8E=AF=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- env.example.bat | 3 ++- lib/GithubAPI.js | 8 ++++---- lib/MyStorage.js | 6 +++--- lib/setVariable.js | 6 ++---- main.js | 3 ++- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/env.example.bat b/env.example.bat index 236ecb1..699c03d 100644 --- a/env.example.bat +++ b/env.example.bat @@ -16,4 +16,5 @@ set COOKIE= set NUMBER=1 set CLEAR=true set SCKEY= -set PUSH_PLUS_TOKEN= \ No newline at end of file +set PUSH_PLUS_TOKEN= +set LOCALLAUNCH=true \ No newline at end of file diff --git a/lib/GithubAPI.js b/lib/GithubAPI.js index 87b7ab4..bad2bf2 100644 --- a/lib/GithubAPI.js +++ b/lib/GithubAPI.js @@ -2,7 +2,6 @@ const { createReadStream, createWriteStream } = require('fs') const unzip = require('unzipper'); const { strToJson } = require("./Base") const { HttpRequest } = require("./HttpRequest") -const GlobalVar = require('./GlobalVar.json') const { GITHUB_REPOSITORY } = process.env; @@ -44,19 +43,20 @@ const GihubAPI = { }); }, /** - * + * 下载构件 + * @param {string} PAT * @param {number} id * @param {number} size * @returns {Promise} success: true */ - downloadArtifacts: (id, size) => { + downloadArtifacts: (PAT, id, size) => { return new Promise((resolve) => { HttpRequest({ method: 'GET', url: `https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/artifacts/${id}/zip`, headers: { accept: 'application/vnd.github.v3+json', - Authorization: `token ${GlobalVar.PAT}` + Authorization: `token ${PAT}` }, config: { redirect: true, diff --git a/lib/MyStorage.js b/lib/MyStorage.js index 7c27113..0398e71 100644 --- a/lib/MyStorage.js +++ b/lib/MyStorage.js @@ -6,12 +6,12 @@ const MyStorage = { /** * 初始化dyid.txt */ - init: () => { + init: (PAT) => { return new Promise((resolve) => { GihubAPI.listArtifacts().then(async artifact => { const { id, size_in_bytes } = artifact; - if (size_in_bytes) { - GihubAPI.downloadArtifacts(id, size_in_bytes).then(async status => { + if (PAT && size_in_bytes) { + GihubAPI.downloadArtifacts(PAT, id, size_in_bytes).then(async status => { if (status) { console.log('存储初始化成功'); } else { diff --git a/lib/setVariable.js b/lib/setVariable.js index 6843a31..93d72bd 100644 --- a/lib/setVariable.js +++ b/lib/setVariable.js @@ -1,5 +1,4 @@ const Script = require("./Script"); -const { getRemoteConfig } = require("./Base"); const MyStorage = require("./MyStorage"); const Base = require("./Base"); @@ -28,7 +27,6 @@ async function setVariable(cookie, PAT = '', SCKEY = '', PUSH_PLUS_TOKEN = '') { const key = ['DedeUserID','bili_jct'] GlobalVar.cookie = cookie; GlobalVar.SCKEY = SCKEY; - GlobalVar.PAT = PAT; GlobalVar.PUSH_PLUS_TOKEN = PUSH_PLUS_TOKEN; cookie.split(/\s*;\s*/).forEach(item=>{ const _item = item.split('='); @@ -36,9 +34,9 @@ async function setVariable(cookie, PAT = '', SCKEY = '', PUSH_PLUS_TOKEN = '') { }) GlobalVar.csrf = GlobalVar.bili_jct; GlobalVar.myUID = GlobalVar.DedeUserID; - GlobalVar.remoteconfig = await getRemoteConfig(); + GlobalVar.remoteconfig = await Base.getRemoteConfig(); await Base.ifNotExistCreateFile('GlobalVar.json',JSON.stringify(GlobalVar)); - await MyStorage.init() + await MyStorage.init(PAT) return } diff --git a/main.js b/main.js index e573a00..d9626f9 100644 --- a/main.js +++ b/main.js @@ -1,9 +1,10 @@ const { setVariable } = require("./lib/setVariable"); -const { NUMBER, CLEAR, COOKIE, PAT, SCKEY, PUSH_PLUS_TOKEN } = process.env; +const { NUMBER, CLEAR, COOKIE, PAT, SCKEY, PUSH_PLUS_TOKEN, LOCALLAUNCH } = process.env; ((async () => { if (typeof COOKIE === 'string' && COOKIE.length > 10) { + if (!LOCALLAUNCH && !PAT) { console.log('请查看README文件, 填入相应的PAT'); return; } await setVariable(COOKIE, PAT, SCKEY, PUSH_PLUS_TOKEN); const { start, isMe, checkCookie } = require("./lib/lottery-in-nodejs"); const { clear } = require("./lib/clear");