-
-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ddcfcee
commit 288851b
Showing
8 changed files
with
103 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,7 @@ buvid3亦可不填 使用随机生成值 | |
acount 查看帐号信息 | ||
clear 清理动态和关注 | ||
update 检查更新 | ||
login 扫码登录自动更新CK | ||
help 帮助信息 | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const { readFileSync, writeFileSync } = require('fs'); | ||
const { log } = require("./utils"); | ||
const path = require('path'); | ||
const env_path = path.join(path.resolve(__dirname, '..'), "env.js") | ||
|
||
/* | ||
* 扫码登陆 | ||
* @param {string} num | ||
*/ | ||
async function login(num) { | ||
try { | ||
const { pcLogin } = await require('@catlair/blogin'); | ||
const loginInfo = await pcLogin(); | ||
if (!loginInfo) { | ||
log.error("登录状态","失败/取消"); | ||
return; | ||
} | ||
log.info("登录状态","登录成功"); | ||
JSON.stringify(loginInfo, null, 2); | ||
const uid = `${loginInfo.mid}`; | ||
const cookie = `${loginInfo.cookie}`; | ||
log.info("账号UID", uid); | ||
log.info("cookie", cookie); | ||
if (replaceCookie(env_path, uid, cookie)) { | ||
log.info("说明",`账号${num}已进行cookie自动更新,如未能生效请手动复制在env.js内替换。路径:${env_path}`); | ||
return; | ||
} | ||
} catch (error) { | ||
if (error?.message?.includes('Cannot find module')) { | ||
log.error('请先运行 yarn add @catlair/blogin'); | ||
return; | ||
} | ||
log.error(error); | ||
} | ||
} | ||
|
||
/* | ||
* 正则检索uid更新cookie | ||
* @param {string} filePath | ||
* @param {string} uid | ||
* @param {string} oldCK | ||
*/ | ||
async function replaceCookie(filePath,uid,oldCK) { | ||
try { | ||
const content = readFileSync(filePath, 'utf-8'); | ||
const DedeUserID = `DedeUserID=${uid}`; | ||
const reg = new RegExp(`['"]?COOKIE['"]?:\\s?['"](.*${DedeUserID}.*)['"]`, 'g'); | ||
const newCK = content.replaceAll(reg, substring => { | ||
let quote = substring.at(0) || ''; | ||
/['"]/.test(quote) || (quote = ''); | ||
const quote2 = oldCK.includes("'") | ||
? '"' | ||
: substring.match(/^['"]?COOKIE['"]?:\s?(['"])/)?.[1] || '"'; | ||
return `${quote}COOKIE${quote}: ${quote2}${oldCK}${quote2}`; | ||
}); | ||
if (content === newCK) return false; | ||
writeFileSync(filePath, newCK); | ||
return true; | ||
} catch (error) { | ||
log.error("替换错误",error); | ||
} | ||
return false; | ||
} | ||
|
||
module.exports = { login } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ create start | |
create check | ||
create clear | ||
create account | ||
create login | ||
|
||
cd $NAME | ||
npm i |