fix: 循环引用

This commit is contained in:
shanmite 2021-02-24 17:25:13 +08:00
parent a8919c008e
commit 9273502008
5 changed files with 13 additions and 13 deletions

View File

@ -16,4 +16,5 @@ set COOKIE=
set NUMBER=1
set CLEAR=true
set SCKEY=
set PUSH_PLUS_TOKEN=
set PUSH_PLUS_TOKEN=
set LOCALLAUNCH=true

View File

@ -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<boolean>} 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,

View File

@ -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 {

View File

@ -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
}

View File

@ -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");