弃用 common.js

This commit is contained in:
fofolee 2020-07-22 00:44:55 +08:00
parent 9760e2c53e
commit 359f26b24b
2 changed files with 19 additions and 60 deletions

View File

@ -1,57 +0,0 @@
const fs = require('fs');
const path = require('path');
exports.fofo = {
pluginInfo: function () {
return JSON.parse(fs.readFileSync(path.join(__dirname, 'plugin.json')))
},
isDev: function () {
return /[a-zA-Z0-9\-]+\.asar/.test(__dirname) ? false : true
},
getDB: id => {
var db = utools.db.get(id),
dbData = db ? db.data : {};
return dbData;
},
putDB: (key, value, id) => {
var db = utools.db.get(id);
if (db) {
var rev = db._rev
var data = db.data
data[key] = value;
utools.db.put({ _id: id, data: data, _rev: rev });
} else {
var data = {};
data[key] = value;
utools.db.put({ _id: id, data: data });
}
},
showChangeLog: function () {
this.putDB('version', this.pluginInfo().version, 'plugin')
fs.readFile(path.join(__dirname, 'CHANGELOG.md'), { encoding: 'utf8' }, (err, data) => {
if (data) utools.ubrowser.goto(data, '更新日志').run({
width: 1280,
height: 920
})
})
},
isRunningAtFirstTime: function () {
var historyVersion = this.getDB('plugin').version
if (!historyVersion) return 'init'
if (this.pluginInfo().version > historyVersion) return 'update'
return false
},
GetFilePath: function (Path, File) {
if (this.isDev()) {
return path.join(__dirname, Path, File)
} else {
return path.join(__dirname.replace(/([a-zA-Z0-9\-]+\.asar)/,'$1.unpacked'), Path, File)
}
}
}

View File

@ -9,7 +9,6 @@ const util = require("util")
const PinyinMatch = require('pinyin-match'); const PinyinMatch = require('pinyin-match');
const axios = require('axios'); const axios = require('axios');
// axios.defaults.adapter = require('axios/lib/adapters/http') // axios.defaults.adapter = require('axios/lib/adapters/http')
fofoCommon = require('./common').fofo
if (!utools.isWindows()) process.env.PATH += ':/usr/local/bin:/usr/local/sbin' if (!utools.isWindows()) process.env.PATH += ':/usr/local/bin:/usr/local/sbin'
@ -326,6 +325,22 @@ swalOneByOne = options => {
swal.getQueueStep() ? Swal.insertQueueStep(options) : Swal.queue([options]) swal.getQueueStep() ? Swal.insertQueueStep(options) : Swal.queue([options])
} }
pluginInfo = () => {
return JSON.parse(fs.readFileSync(path.join(__dirname, 'plugin.json')))
}
isDev = () => {
return /[a-zA-Z0-9\-]+\.asar/.test(__dirname) ? false : true
}
let GetFilePath = (Path, File) => {
if (isDev()) {
return path.join(__dirname, Path, File)
} else {
return path.join(__dirname.replace(/([a-zA-Z0-9\-]+\.asar)/,'$1.unpacked'), Path, File)
}
}
let getSleepCodeByShell = ms => { let getSleepCodeByShell = ms => {
var cmd, tempFilePath var cmd, tempFilePath
if (utools.isWindows()) { if (utools.isWindows()) {
@ -342,7 +357,7 @@ let modWindowHeight = height => {
} }
// 屏蔽危险函数 // 屏蔽危险函数
let getuToolsLite = () => { getuToolsLite = () => {
var utoolsLite = Object.assign({}, utools) var utoolsLite = Object.assign({}, utools)
delete utoolsLite.db delete utoolsLite.db
delete utoolsLite.removeFeature delete utoolsLite.removeFeature
@ -531,7 +546,7 @@ htmlEncode = (value, raw) => {
py_beautify = (code, cb) => { py_beautify = (code, cb) => {
var file = getQuickCommandScriptFile('py') var file = getQuickCommandScriptFile('py')
fs.writeFile(file, code, { encoding: 'utf8' }, err => { fs.writeFile(file, code, { encoding: 'utf8' }, err => {
var cmd = `python "${fofoCommon.GetFilePath('assets/plugins', 'autopep8.py')}" "${file}"` var cmd = `python "${GetFilePath('assets/plugins', 'autopep8.py')}" "${file}"`
child_process.exec(cmd, { encoding: "buffer" }, (err, stdout, stderr) => { child_process.exec(cmd, { encoding: "buffer" }, (err, stdout, stderr) => {
var codec = utools.isWindows() ? 'cp936' : 'utf8' var codec = utools.isWindows() ? 'cp936' : 'utf8'
cb(iconv.decode(stdout, codec).trim()) cb(iconv.decode(stdout, codec).trim())
@ -603,6 +618,7 @@ yuQueClient = axios.create({
baseURL: 'https://www.yuque.com/api/v2/', baseURL: 'https://www.yuque.com/api/v2/',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
// 只读权限
'X-Auth-Token': 'WNrd0Z4kfCZLFrGLVAaas93DZ7sbG6PirKq7VxBL' 'X-Auth-Token': 'WNrd0Z4kfCZLFrGLVAaas93DZ7sbG6PirKq7VxBL'
} }
}); });