mirror of
https://github.com/qitoqito/psyduck.git
synced 2026-01-12 12:40:44 +08:00
修复win环境下运行bug
This commit is contained in:
parent
30b337c711
commit
cabea23a7a
54
main.js
54
main.js
@ -1,9 +1,6 @@
|
||||
// import {Template} from "./template.js"
|
||||
// console.log(process )
|
||||
// let dirname = process.mainModule.path
|
||||
import fs from 'fs'
|
||||
import path from 'path';
|
||||
import {fileURLToPath} from 'url';
|
||||
import {fileURLToPath, pathToFileURL} from 'url';
|
||||
import ini from 'ini'
|
||||
|
||||
let filename;
|
||||
@ -28,33 +25,40 @@ if (length>2) {
|
||||
if (filename) {
|
||||
let type = filename.match(/(^[A-Za-z0-9]+)\_/)[1]
|
||||
try {
|
||||
let psyDuck = await import( `./parse/${type}/${filename}.js`)
|
||||
let jsPath = pathToFileURL(`./parse/${type}/${filename}.js`).href
|
||||
let psyDuck = await import(jsPath)
|
||||
let main = new psyDuck.Main()
|
||||
await main.init(params)
|
||||
} catch (e) {
|
||||
// console.log(e)
|
||||
let iniText = fs.readFileSync(`config/config.ini`, 'UTF-8')
|
||||
let config = ini.parse(iniText)
|
||||
let iniPath = `config/${type}.ini`
|
||||
if (config.env && config.env.iniPath) {
|
||||
iniPath = `${config.env.iniPath}/${type}.ini`
|
||||
}
|
||||
let scText = fs.readFileSync(iniPath, 'UTF-8')
|
||||
let script = ini.parse(scText)
|
||||
let map = ''
|
||||
for (let i in script) {
|
||||
if (i == filename && script[i].map) {
|
||||
map = script[i].map
|
||||
}
|
||||
}
|
||||
if (map) {
|
||||
params.mapping = map
|
||||
let psyDuck = await import( `./parse/${type}/${map}.js`)
|
||||
let main = new psyDuck.Main()
|
||||
await main.init(params)
|
||||
if (e == 'End') {
|
||||
console.log("End")
|
||||
}
|
||||
else {
|
||||
console.log("没有可执行的脚本")
|
||||
let iniText = fs.readFileSync(`config/config.ini`, 'UTF-8')
|
||||
let config = ini.parse(iniText)
|
||||
let iniPath = `config/${type}.ini`
|
||||
if (config.env && config.env.iniPath) {
|
||||
iniPath = `${config.env.iniPath}/${type}.ini`
|
||||
}
|
||||
let scText = fs.readFileSync(iniPath, 'UTF-8')
|
||||
let script = ini.parse(scText)
|
||||
let map = ''
|
||||
for (let i in script) {
|
||||
if (i == filename && script[i].map) {
|
||||
map = script[i].map
|
||||
}
|
||||
}
|
||||
if (map) {
|
||||
params.mapping = map
|
||||
let jsPath = pathToFileURL(`./parse/${type}/${map}.js`).href
|
||||
let psyDuck = await import(jsPath)
|
||||
let main = new psyDuck.Main()
|
||||
await main.init(params)
|
||||
}
|
||||
else {
|
||||
console.log("没有可执行的脚本")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
29
qlCreate.js
29
qlCreate.js
@ -181,7 +181,7 @@ class Ql {
|
||||
|
||||
async create() {
|
||||
if (!this.config) {
|
||||
consoel.log("请先初始化config.ini,并设置青龙ClientID和ClientSecret")
|
||||
console.log("请先初始化config.ini,并设置青龙ClientID和ClientSecret")
|
||||
return
|
||||
}
|
||||
await this.getToken()
|
||||
@ -221,9 +221,7 @@ class Ql {
|
||||
let title = obj[filename].title || `${psyDuck.profile.title}分身`
|
||||
let code = `
|
||||
import path from 'path';
|
||||
import {
|
||||
fileURLToPath
|
||||
} from 'url';
|
||||
import {fileURLToPath, pathToFileURL} from 'url';
|
||||
!(async () => {
|
||||
let dirpath = fileURLToPath(import.meta.url).replace('.swap','');
|
||||
let abspath = path.dirname(dirpath)
|
||||
@ -246,11 +244,16 @@ import {
|
||||
}
|
||||
}
|
||||
}
|
||||
let psyDuck = await import (\`\${abspath}/parse/\${type}/${map}.js\`)
|
||||
let jsPath = pathToFileURL(\`\${abspath}/parse/\${type}/${map}.js\`).href
|
||||
let psyDuck = await import (jsPath)
|
||||
let main = new psyDuck.Main()
|
||||
await main.init(params)
|
||||
})().catch((e) => {
|
||||
console.log(e)
|
||||
if (e == 'End') {
|
||||
console.log("End")
|
||||
}else{
|
||||
console.log(e)
|
||||
}
|
||||
})`
|
||||
fs.writeFile(`${abspath}/${filename}.js`, code, function(err, data) {
|
||||
if (err) {
|
||||
@ -281,9 +284,7 @@ import {
|
||||
let crontab = psyDuck.crontab()
|
||||
let code = `
|
||||
import path from 'path';
|
||||
import {
|
||||
fileURLToPath
|
||||
} from 'url';
|
||||
import {fileURLToPath, pathToFileURL} from 'url';
|
||||
!(async () => {
|
||||
let dirpath = fileURLToPath(import.meta.url).replace('.swap','');
|
||||
let abspath = path.dirname(dirpath)
|
||||
@ -304,11 +305,17 @@ import {
|
||||
}
|
||||
}
|
||||
}
|
||||
let psyDuck = await import (\`\${abspath}/parse/\${type}/\${filename}.js\`)
|
||||
let jsPath = pathToFileURL(\`\${abspath}/parse/\${type}/\${filename}.js\`).href
|
||||
let psyDuck = await import (jsPath)
|
||||
let main = new psyDuck.Main()
|
||||
await main.init(params)
|
||||
})().catch((e) => {
|
||||
console.log(e)
|
||||
if (e == 'End') {
|
||||
console.log("End")
|
||||
}else{
|
||||
console.log(e)
|
||||
}
|
||||
|
||||
})`
|
||||
fs.writeFile(`${abspath}/${script}`, code, function(err, data) {
|
||||
if (err) {
|
||||
|
||||
@ -34,7 +34,7 @@ export class Cache {
|
||||
await this._cache.connect();
|
||||
}
|
||||
else {
|
||||
let dirpath = fileURLToPath(import.meta.url).split('/util')[0];
|
||||
let dirpath = fileURLToPath(import.meta.url).split('/util')[0].split("\\util")[0];
|
||||
this._cache = new Tfc({dir: `${dirpath}/temp`})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user