添加了NEON硬件编码器选项,并增加了刷新列表、清空下载缓存和清空转码缓存的按钮。
This commit is contained in:
64
server.js
64
server.js
@@ -148,20 +148,51 @@ wss.on('connection', (ws) => {
|
||||
ws.on('close', () => removeWsClient(ws));
|
||||
});
|
||||
|
||||
const clearMp4Cache = () => {
|
||||
const mp4Dir = path.join(__dirname, 'public', 'mp4');
|
||||
if (!fs.existsSync(mp4Dir)) return;
|
||||
const mp4BaseDir = path.join(__dirname, 'public', 'mp4');
|
||||
|
||||
const ensureDirectoryExists = (dirPath) => {
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
};
|
||||
|
||||
const clearDownloadCache = () => {
|
||||
const tmpDir = os.tmpdir();
|
||||
try {
|
||||
fs.rmSync(mp4Dir, { recursive: true, force: true });
|
||||
if (!fs.existsSync(tmpDir)) return;
|
||||
const files = fs.readdirSync(tmpDir);
|
||||
for (const file of files) {
|
||||
if (file.startsWith('s3-input-') && file.endsWith('.tmp')) {
|
||||
const filePath = path.join(tmpDir, file);
|
||||
fs.rmSync(filePath, { force: true });
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to clear download cache:', err);
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
const clearMp4Cache = () => {
|
||||
if (!fs.existsSync(mp4BaseDir)) return;
|
||||
try {
|
||||
fs.rmSync(mp4BaseDir, { recursive: true, force: true });
|
||||
} catch (err) {
|
||||
if (typeof fs.rmdirSync === 'function') {
|
||||
fs.rmdirSync(mp4Dir, { recursive: true });
|
||||
fs.rmdirSync(mp4BaseDir, { recursive: true });
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const clearTranscodeCache = () => {
|
||||
clearMp4Cache();
|
||||
Object.keys(progressMap).forEach((key) => delete progressMap[key]);
|
||||
};
|
||||
|
||||
ensureDirectoryExists(mp4BaseDir);
|
||||
|
||||
// Endpoint to list available buckets
|
||||
app.get('/api/buckets', async (req, res) => {
|
||||
try {
|
||||
@@ -228,8 +259,7 @@ app.get('/api/config', (req, res) => {
|
||||
|
||||
app.post('/api/reset-cache', (req, res) => {
|
||||
try {
|
||||
clearMp4Cache();
|
||||
Object.keys(progressMap).forEach((key) => delete progressMap[key]);
|
||||
clearTranscodeCache();
|
||||
res.json({ message: 'Cache reset' });
|
||||
} catch (error) {
|
||||
console.error('Error resetting cache:', error);
|
||||
@@ -237,6 +267,26 @@ app.post('/api/reset-cache', (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/clear-download-cache', (req, res) => {
|
||||
try {
|
||||
clearDownloadCache();
|
||||
res.json({ message: 'Download cache cleared' });
|
||||
} catch (error) {
|
||||
console.error('Error clearing download cache:', error);
|
||||
res.status(500).json({ error: 'Failed to clear download cache', detail: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/clear-transcode-cache', (req, res) => {
|
||||
try {
|
||||
clearTranscodeCache();
|
||||
res.json({ message: 'Transcode cache cleared' });
|
||||
} catch (error) {
|
||||
console.error('Error clearing transcode cache:', error);
|
||||
res.status(500).json({ error: 'Failed to clear transcode cache', detail: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Endpoint to transcode S3 video streaming to MP4
|
||||
app.post('/api/transcode', async (req, res) => {
|
||||
const { bucket, key, codec, encoder } = req.body;
|
||||
|
||||
Reference in New Issue
Block a user