-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): add setting and config module
- Loading branch information
Showing
18 changed files
with
327 additions
and
134 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,40 @@ | ||
module.exports = { | ||
Netease : 'netease', | ||
consts: { | ||
Netease : { | ||
code: 'netease', | ||
label: '网易云', | ||
}, | ||
Bilibili : { | ||
code: 'bilibili', | ||
label: '哔哩哔哩', | ||
}, | ||
Douyin : { | ||
code: 'douyin', | ||
label: '抖音', | ||
}, | ||
Kugou : { | ||
code: 'kugou', | ||
label: '酷狗', | ||
}, | ||
Kuwo : { | ||
code: 'kuwo', | ||
label: '酷我', | ||
}, | ||
Migu : { | ||
code: 'migu', | ||
label: '咪咕', | ||
}, | ||
QQ : { | ||
code: 'qq', | ||
label: 'QQ', | ||
}, | ||
Youtube : { | ||
code: 'youtube', | ||
label: 'Youtube', | ||
}, | ||
Qmkg : { | ||
code: 'qmkg', | ||
label: '全民K歌', | ||
}, | ||
}, | ||
} |
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,23 @@ | ||
const ConfigService = require('../service/config_manager'); | ||
|
||
async function getGlobalConfig(req, res) { | ||
const config = await ConfigService.getGlobalConfig(); | ||
res.send({ | ||
status: 0, | ||
data: config | ||
}); | ||
} | ||
|
||
async function setGlobalConfig(req, res) { | ||
const config = req.body; | ||
await ConfigService.setGlobalConfig(config); | ||
res.send({ | ||
status: 0, | ||
data: config | ||
}); | ||
} | ||
|
||
module.exports = { | ||
getGlobalConfig, | ||
setGlobalConfig, | ||
} |
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
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,42 @@ | ||
const asyncFs = require('../../utils/fs'); | ||
|
||
const DataPath = `${__dirname}/../../../.profile/data`; | ||
const ConfigPath = `${DataPath}/config`; | ||
const GlobalConfig = `${ConfigPath}/global.json`; | ||
const sourceConsts = require('../../consts/source').consts; | ||
|
||
async function init() { | ||
if (!await asyncFs.asyncFileExisted(ConfigPath)) { | ||
await asyncFs.asyncMkdir(ConfigPath); | ||
} | ||
} | ||
init(); | ||
|
||
const GlobalDefaultConfig = { | ||
localDownloadPath: '', | ||
// don't search youtube by default | ||
sources: Object.values(sourceConsts).map(i => i.code).filter(s => s !== sourceConsts.Youtube.code), | ||
sourceConsts, | ||
}; | ||
|
||
async function setGlobalConfig(config) { | ||
await asyncFs.asyncWriteFile(GlobalConfig, JSON.stringify(config)); | ||
} | ||
|
||
async function getGlobalConfig() { | ||
if (!await asyncFs.asyncFileExisted(GlobalConfig)) { | ||
return GlobalDefaultConfig; | ||
} | ||
const config = JSON.parse(await asyncFs.asyncReadFile(GlobalConfig)); | ||
if (!config.sources) { | ||
config.sources = GlobalDefaultConfig.sources; | ||
} | ||
config.sourceConsts = GlobalDefaultConfig.sourceConsts; | ||
return config; | ||
} | ||
|
||
|
||
module.exports = { | ||
setGlobalConfig, | ||
getGlobalConfig, | ||
} |
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
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,23 @@ | ||
const httpsGet = require('../../utils/network').asyncHttpsGet; | ||
const logger = require('consola'); | ||
|
||
|
||
async function getRemoteConfig() { | ||
const fallbackConfig = { | ||
githubProxy: 'https://mirror.ghproxy.com/', | ||
} | ||
const remoteConfigUrl = 'https://foamzou.com/tools/melody-config.php'; | ||
const remoteConfig = await httpsGet(remoteConfigUrl); | ||
if (remoteConfig === null) { | ||
logger.error('get remote config failed, use fallback config'); | ||
return fallbackConfig; | ||
} | ||
const config = JSON.parse(remoteConfig); | ||
return { | ||
githubProxy: config.githubProxy, | ||
} | ||
} | ||
|
||
module.exports = { | ||
getRemoteConfig: getRemoteConfig, | ||
} |
File renamed without changes.
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,19 @@ | ||
const https = require('https'); | ||
|
||
function asyncHttpsGet(url) { | ||
return new Promise((resolve) => { | ||
https.get(url, res => { | ||
res.on('data', data => { | ||
resolve(data.toString()); | ||
}) | ||
res.on('error', err => { | ||
l(err); | ||
resolve(null); | ||
}) | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
asyncHttpsGet | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
NODE_ENV = 'development' | ||
VITE_APP_MODE = 'development' | ||
VITE_APP_API_URL = 'http://172.16.9.215:5566/api' | ||
VITE_APP_API_URL = 'http://172.16.252.1:5566/api' | ||
VITE_APP_API_URL = 'http://10.0.0.2:5566/api' | ||
VITE_APP_API_URL = 'http://127.0.0.1:5566/api' |
Oops, something went wrong.