DEBUG
This commit is contained in:
parent
7dc2f78b47
commit
0afe7c9f7c
15
fmhub.js
15
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")
|
||||
|
3
index.js
3
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存储
|
||||
|
@ -21,7 +21,7 @@
|
||||
"string-random": "^0.1.3"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "node index",
|
||||
"start": "node index"
|
||||
"dev": "node index.js",
|
||||
"start": "node index.js"
|
||||
}
|
||||
}
|
||||
|
33
tools.js
33
tools.js
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user