This commit is contained in:
桜華 2022-09-25 00:11:49 +08:00
parent 7dc2f78b47
commit 0afe7c9f7c
4 changed files with 17 additions and 38 deletions

View File

@ -1,9 +1,20 @@
import interrelated from './interrelated.js' import interrelated from './interrelated.js'
import level from 'level' 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 // 初始化 leveldb
const db = level("./data/level/fmhub") const db = level("./data/level/fmhub")

View File

@ -1,5 +1,5 @@
import nedb from 'nedb' import nedb from 'nedb'
import express, { query } from 'express' import express from 'express'
import expressWs from 'express-ws' import expressWs from 'express-ws'
import session from 'express-session' import session from 'express-session'
import sessionDb from 'express-session-nedb' import sessionDb from 'express-session-nedb'
@ -8,6 +8,7 @@ import formidable from 'formidable'
import md5 from 'md5-node' import md5 from 'md5-node'
import HUB from './fmhub.js' import HUB from './fmhub.js'
const databases = new Map() // 所有数据库 const databases = new Map() // 所有数据库
const FM = new HUB() // 频道消息分发器 const FM = new HUB() // 频道消息分发器
const messagelist = new Map() // 消息队列的nedb存储 const messagelist = new Map() // 消息队列的nedb存储

View File

@ -21,7 +21,7 @@
"string-random": "^0.1.3" "string-random": "^0.1.3"
}, },
"scripts": { "scripts": {
"dev": "node index", "dev": "node index.js",
"start": "node index" "start": "node index.js"
} }
} }

View File

@ -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
}