mirror of
https://mirror.ghproxy.com/https://github.com/CxJuice/ScWeb_Chinese_Translate.git
synced 2024-12-23 07:23:46 +08:00
Update index.js
This commit is contained in:
parent
a572d8bafb
commit
2c9b8688e3
31
index.js
31
index.js
@ -24,37 +24,6 @@ function transformKeysToLowerCase(obj) {
|
|||||||
return newObj;
|
return newObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取文件夹内的所有 JSON 文件
|
|
||||||
app.get('/json-files', (req, res) => {
|
|
||||||
fs.readdir(JSON_FOLDER_PATH, (err, files) => {
|
|
||||||
if (err) {
|
|
||||||
return res.status(500).send('Server error.');
|
|
||||||
}
|
|
||||||
const jsonFiles = files.filter(file => file.endsWith('.json'));
|
|
||||||
res.json(jsonFiles);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// 获取特定的 JSON 文件
|
|
||||||
app.get('/json-files/:filename', (req, res) => {
|
|
||||||
const filePath = path.join(JSON_FOLDER_PATH, req.params.filename);
|
|
||||||
|
|
||||||
fs.readFile(filePath, 'utf8', (err, data) => {
|
|
||||||
if (err) {
|
|
||||||
if (err.code === 'ENOENT') {
|
|
||||||
return res.status(404).send('File not found.');
|
|
||||||
}
|
|
||||||
return res.status(500).send('Server error.');
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const jsonData = JSON.parse(data);
|
|
||||||
res.json(transformKeysToLowerCase(jsonData));
|
|
||||||
} catch (parseErr) {
|
|
||||||
res.status(500).send('Error parsing JSON.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// 获取locales目录下的特定的 JSON 文件
|
// 获取locales目录下的特定的 JSON 文件
|
||||||
app.get('/json-files/locales/:filename', (req, res) => {
|
app.get('/json-files/locales/:filename', (req, res) => {
|
||||||
const filePath = path.join(LOCALES_JSON_FOLDER_PATH, req.params.filename);
|
const filePath = path.join(LOCALES_JSON_FOLDER_PATH, req.params.filename);
|
||||||
|
Loading…
Reference in New Issue
Block a user