-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
346 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
/** | ||
* 删除文件夹下所有文件及文件夹下所有文件 | ||
* @param {*} path | ||
*/ | ||
function emptyDir(path) { | ||
const files = fs.readdirSync(path); | ||
files.forEach(file => { | ||
const filePath = `${path}/${file}`; | ||
const stats = fs.statSync(filePath); | ||
if (stats.isDirectory()) { | ||
emptyDir(filePath); | ||
} else { | ||
fs.unlinkSync(filePath); | ||
} | ||
}); | ||
} | ||
exports.emptyDir = emptyDir; | ||
|
||
/** | ||
* 删除指定路径下的所有空文件夹 | ||
* @param {*} path | ||
*/ | ||
function rmEmptyDir(path, level = 0) { | ||
const files = fs.readdirSync(path); | ||
if (files.length > 0) { | ||
let tempFile = 0; | ||
files.forEach(file => { | ||
tempFile++; | ||
rmEmptyDir(`${path}/${file}`, 1); | ||
}); | ||
if (tempFile === files.length && level !== 0) { | ||
fs.rmdirSync(path); | ||
} | ||
} | ||
else { | ||
level !== 0 && fs.rmdirSync(path); | ||
} | ||
} | ||
exports.rmEmptyDir = rmEmptyDir; | ||
|
||
/** | ||
* 清空指定路径下的所有文件及文件夹 | ||
* @param {*} path | ||
*/ | ||
function clearDir(path) { | ||
emptyDir(path); | ||
rmEmptyDir(path); | ||
} | ||
exports.clearDir = clearDir; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const path = require("path"); | ||
const musicListDir = path.join(__dirname, "../../config-template/config"); | ||
const { _readFileSync } = require("../../lib/file"); | ||
const fs = require("fs"); | ||
|
||
class Data { | ||
|
||
constructor() { | ||
this._music_list = {}; | ||
this.load() | ||
} | ||
|
||
load = () => { | ||
try { | ||
this._music_list = _readFileSync(musicListDir, "musicList"); | ||
} catch (error) { | ||
console.log(error.message); | ||
} | ||
} | ||
|
||
dump = () => { | ||
_readFileSync(musicListDir, "musicList"); // 没有则创建配置文件 | ||
fs.writeFileSync(musicListDir + "/musicList.json", JSON.stringify(this._music_list, null, '\t')); | ||
} | ||
|
||
getMusicList = () => { | ||
let musicList = this._music_list; | ||
return musicList; | ||
} | ||
|
||
updateMusic = (uname = null, music = null) => { | ||
let musicList = this.getMusicList(); | ||
if (typeof musicList[uname] === "undefined") musicList[uname] = music; | ||
this._music_list = musicList; | ||
this.dump(); | ||
} | ||
|
||
getMusicName = () => { | ||
let musicList = this._music_list; | ||
return Object.keys(musicList); | ||
} | ||
|
||
getMusic = (uname = null) => { | ||
let musicList = this._music_list; | ||
return musicList[uname]; | ||
} | ||
} | ||
|
||
exports.Data = Data; |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.