添加清空缓存按钮
This commit is contained in:
25
server.js
25
server.js
@@ -113,6 +113,20 @@ wss.on('connection', (ws) => {
|
||||
ws.on('close', () => removeWsClient(ws));
|
||||
});
|
||||
|
||||
const clearMp4Cache = () => {
|
||||
const mp4Dir = path.join(__dirname, 'public', 'mp4');
|
||||
if (!fs.existsSync(mp4Dir)) return;
|
||||
try {
|
||||
fs.rmSync(mp4Dir, { recursive: true, force: true });
|
||||
} catch (err) {
|
||||
if (typeof fs.rmdirSync === 'function') {
|
||||
fs.rmdirSync(mp4Dir, { recursive: true });
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Endpoint to list videos in the bucket
|
||||
app.get('/api/videos', async (req, res) => {
|
||||
try {
|
||||
@@ -154,6 +168,17 @@ app.get('/api/videos', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/reset-cache', (req, res) => {
|
||||
try {
|
||||
clearMp4Cache();
|
||||
Object.keys(progressMap).forEach((key) => delete progressMap[key]);
|
||||
res.json({ message: 'Cache reset' });
|
||||
} catch (error) {
|
||||
console.error('Error resetting cache:', error);
|
||||
res.status(500).json({ error: 'Failed to reset cache', detail: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Endpoint to transcode S3 video streaming to MP4
|
||||
app.post('/api/transcode', async (req, res) => {
|
||||
const { key, codec, encoder } = req.body;
|
||||
|
||||
Reference in New Issue
Block a user