diff --git a/fmhub.js b/fmhub.js index 9ac7f4e..863fb27 100644 --- a/fmhub.js +++ b/fmhub.js @@ -1,9 +1,20 @@ import interrelated from './interrelated.js' import level from 'level' -import tools from './tools.js' +import path from 'path' +import fs from 'fs' // 检查并创建文件夹 -await tools.dirExists('data/level') +function 检查并创建目录(dirname) { + if (fs.existsSync(dirname)) { + return true + } else if (检查并创建目录(path.dirname(dirname))) { + fs.mkdirSync(dirname) + return true + } + return false +} + +检查并创建目录('data/level') // 初始化 leveldb const db = level("./data/level/fmhub") diff --git a/index.js b/index.js index efdb125..d9abcf2 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ import nedb from 'nedb' -import express, { query } from 'express' +import express from 'express' import expressWs from 'express-ws' import session from 'express-session' import sessionDb from 'express-session-nedb' @@ -8,6 +8,7 @@ import formidable from 'formidable' import md5 from 'md5-node' import HUB from './fmhub.js' + const databases = new Map() // 所有数据库 const FM = new HUB() // 频道消息分发器 const messagelist = new Map() // 消息队列的nedb存储 diff --git a/package.json b/package.json index a8015cc..74b6c3d 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "string-random": "^0.1.3" }, "scripts": { - "dev": "node index", - "start": "node index" + "dev": "node index.js", + "start": "node index.js" } } diff --git a/tools.js b/tools.js deleted file mode 100644 index f1c2680..0000000 --- a/tools.js +++ /dev/null @@ -1,33 +0,0 @@ -import fs from 'fs' -import path from 'path' - -function getStat(path) { - return new Promise((resolve, reject) => { - fs.stat(path, (err, stats) => { - err ? resolve(false) : resolve(stats) - }) - }) -} - -function mkdir(dir) { - return new Promise((resolve, reject) => { - fs.mkdir(dir, err => { - err ? resolve(false) : resolve(true) - }) - }) -} - -async function dirExists(dir) { - let isExists = await getStat(dir) - if (isExists && isExists.isDirectory()) { - return true - } else if (isExists) { - return false - } - let status = await dirExists(path.parse(dir).dir) - return status ? await mkdir(dir) : null -} - -export default { - dirExists -} \ No newline at end of file