fix: 在Node环境下,CookieSet生成在执行目录下,而非当前目录下

This commit is contained in:
chesterchenn 2021-08-13 16:46:15 +08:00
parent b50a93a3b4
commit d6f3360288
1 changed files with 9 additions and 6 deletions

View File

@ -1793,9 +1793,11 @@ function nobyda() {
if (isNode) {
const request = require('request');
const fs = require("fs");
const path = require("path");
return ({
request,
fs
fs,
path
})
} else {
return (null)
@ -1851,11 +1853,12 @@ function nobyda() {
if (isSurge) return $persistentStore.write(value, key)
if (isNode) {
try {
if (!node.fs.existsSync(NodeSet)) node.fs.writeFileSync(NodeSet, JSON.stringify({}));
const dataValue = JSON.parse(node.fs.readFileSync(NodeSet));
if (!node.fs.existsSync(node.path.resolve(__dirname, NodeSet)))
node.fs.writeFileSync(node.path.resolve(__dirname, NodeSet), JSON.stringify({}));
const dataValue = JSON.parse(node.fs.readFileSync(node.path.resolve(__dirname, NodeSet)));
if (value) dataValue[key] = value;
if (!value) delete dataValue[key];
return node.fs.writeFileSync(NodeSet, JSON.stringify(dataValue));
return node.fs.writeFileSync(node.path.resolve(__dirname, NodeSet), JSON.stringify(dataValue));
} catch (er) {
return AnError('Node.js持久化写入', null, er);
}
@ -1875,8 +1878,8 @@ function nobyda() {
if (isSurge) return $persistentStore.read(key)
if (isNode) {
try {
if (!node.fs.existsSync(NodeSet)) return null;
const dataValue = JSON.parse(node.fs.readFileSync(NodeSet))
if (!node.fs.existsSync(node.path.resolve(__dirname, NodeSet))) return null;
const dataValue = JSON.parse(node.fs.readFileSync(node.path.resolve(__dirname, NodeSet)))
return dataValue[key]
} catch (er) {
return AnError('Node.js持久化读取', null, er)