Fix:Cleaning up orphan streams on server init #2209

This commit is contained in:
advplyr 2023-10-11 17:05:56 -05:00
parent 753ae3d7dc
commit e687a3403e

View File

@ -330,14 +330,15 @@ class PlaybackSessionManager {
Logger.debug(`[PlaybackSessionManager] Removed session "${sessionId}"`) Logger.debug(`[PlaybackSessionManager] Removed session "${sessionId}"`)
} }
// Check for streams that are not in memory and remove /**
* Remove all stream folders in `/metadata/streams`
*/
async removeOrphanStreams() { async removeOrphanStreams() {
await fs.ensureDir(this.StreamsPath) await fs.ensureDir(this.StreamsPath)
try { try {
const streamsInPath = await fs.readdir(this.StreamsPath) const streamsInPath = await fs.readdir(this.StreamsPath)
for (let i = 0; i < streamsInPath.length; i++) { for (const streamId of streamsInPath) {
const streamId = streamsInPath[i] if (/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/.test(streamId)) { // Ensure is uuidv4
if (streamId.startsWith('play_')) { // Make sure to only remove folders that are a stream
const session = this.sessions.find(se => se.id === streamId) const session = this.sessions.find(se => se.id === streamId)
if (!session) { if (!session) {
const streamPath = Path.join(this.StreamsPath, streamId) const streamPath = Path.join(this.StreamsPath, streamId)