Fix: correctly setup line audio directory, routing, and upload handling
This commit is contained in:
+34
-1
@@ -43,6 +43,7 @@ const uploadDir = path.join(__dirname, 'public', 'uploads');
|
||||
const audioRootDir = path.join(appRootDir, 'Audio');
|
||||
const audioMusicDir = path.join(audioRootDir, 'music');
|
||||
const audioVoiceDir = path.join(audioRootDir, 'voice');
|
||||
const audioLineDir = path.join(audioRootDir, 'line');
|
||||
const audioBeepDir = path.join(audioRootDir, 'beep');
|
||||
const audioGeneralLegacyDir = path.join(audioRootDir, 'general');
|
||||
const audioStationDir = path.join(audioRootDir, 'station');
|
||||
@@ -55,6 +56,7 @@ if (!fs.existsSync(uploadDir)) fs.mkdirSync(uploadDir, { recursive: true });
|
||||
if (!fs.existsSync(audioRootDir)) fs.mkdirSync(audioRootDir, { recursive: true });
|
||||
if (!fs.existsSync(audioMusicDir)) fs.mkdirSync(audioMusicDir, { recursive: true });
|
||||
if (!fs.existsSync(audioVoiceDir)) fs.mkdirSync(audioVoiceDir, { recursive: true });
|
||||
if (!fs.existsSync(audioLineDir)) fs.mkdirSync(audioLineDir, { recursive: true });
|
||||
if (!fs.existsSync(audioBeepDir)) fs.mkdirSync(audioBeepDir, { recursive: true });
|
||||
if (!fs.existsSync(audioStationDir)) fs.mkdirSync(audioStationDir, { recursive: true });
|
||||
if (!fs.existsSync(tempBroadcastDir)) fs.mkdirSync(tempBroadcastDir, { recursive: true });
|
||||
@@ -85,6 +87,8 @@ const storage = multer.diskStorage({
|
||||
cb(null, audioMusicDir);
|
||||
} else if (file.fieldname === 'voiceAudioFiles') {
|
||||
cb(null, audioVoiceDir);
|
||||
} else if (file.fieldname === 'lineAudioFiles') {
|
||||
cb(null, audioLineDir);
|
||||
} else if (file.fieldname === 'generalAudioFiles') {
|
||||
cb(null, audioBeepDir);
|
||||
} else if (file.fieldname === 'stationAudioFiles') {
|
||||
@@ -146,6 +150,10 @@ app.get('/media/audio/voice/:file', (req, res) => {
|
||||
const name = path.basename(String(req.params.file || ''));
|
||||
sendBinaryFile(res, path.join(audioVoiceDir, name));
|
||||
});
|
||||
app.get('/media/audio/line/:file', (req, res) => {
|
||||
const name = path.basename(String(req.params.file || ''));
|
||||
sendBinaryFile(res, path.join(audioLineDir, name));
|
||||
});
|
||||
|
||||
app.get('/media/audio/station/:file', (req, res) => {
|
||||
const name = path.basename(String(req.params.file || ''));
|
||||
@@ -164,6 +172,7 @@ app.get('/media', (req, res) => {
|
||||
routes: [
|
||||
'/media/audio/music/:file',
|
||||
'/media/audio/voice/:file',
|
||||
'/media/audio/line/:file',
|
||||
'/media/audio/beep/:file',
|
||||
'/media/audio/general/:file',
|
||||
'/media/audio/station/:file',
|
||||
@@ -949,6 +958,24 @@ function getManagedFiles() {
|
||||
});
|
||||
}
|
||||
|
||||
if (fs.existsSync(audioLineDir)) {
|
||||
fs.readdirSync(audioLineDir).forEach(file => {
|
||||
if (file.endsWith('.dfpwm')) {
|
||||
const wavName = file.replace(/\.dfpwm$/, '.wav');
|
||||
if (fs.existsSync(path.join(audioLineDir, wavName))) return;
|
||||
}
|
||||
const filePath = path.join(audioLineDir, file);
|
||||
const stats = fs.statSync(filePath);
|
||||
files.push({
|
||||
name: file,
|
||||
path: `Audio/line/${file}`,
|
||||
type: 'line',
|
||||
size: stats.size,
|
||||
mtime: stats.mtimeMs
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const beepSeen = new Set();
|
||||
for (const dir of getBeepAudioDirs()) {
|
||||
if (!fs.existsSync(dir)) continue;
|
||||
@@ -2171,6 +2198,12 @@ app.post('/api/upload/voice-audio', upload.array('voiceAudioFiles'), (req, res)
|
||||
res.json({ success: true, message: `${files.length} voice audio files uploaded` });
|
||||
});
|
||||
|
||||
app.post('/api/upload/line-audio', upload.array('lineAudioFiles'), (req, res) => {
|
||||
const files = req.files || [];
|
||||
log('SUCCESS', `Uploaded ${files.length} line audio files`);
|
||||
res.json({ success: true, message: `${files.length} line audio files uploaded` });
|
||||
});
|
||||
|
||||
app.post('/api/upload/station-audio', upload.array('stationAudioFiles'), (req, res) => {
|
||||
const files = req.files || [];
|
||||
log('SUCCESS', `Uploaded ${files.length} station audio files`);
|
||||
@@ -2603,7 +2636,7 @@ app.post('/api/tts/import', express.json(), (req, res) => {
|
||||
const jaSource = path.join(uploadDir, jaTemp);
|
||||
const safeStationCode = String(stationCode).replace(/\//g, '-');
|
||||
|
||||
const targetDir = type === 'line' ? audioVoiceDir : audioStationDir;
|
||||
const targetDir = type === 'line' ? audioLineDir : audioStationDir;
|
||||
const zhDest = path.join(targetDir, `ch-${safeStationCode}.wav`);
|
||||
const jaDest = path.join(targetDir, `ja-${safeStationCode}.wav`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user