Skip to content

Commit e996213

Browse files
authored
Merge pull request #5 from dennisrijsdijk/fix/clear-database-missing-key
fix: clear database fails when either audio or video doesn't exist (#4)
2 parents 5fadad0 + 82fac9f commit e996213

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/media-manager.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ class MediaManager {
104104
}
105105

106106
public setAllMediaUnplayed(effect_id: string, type: MediaType): void {
107+
if (!this._db.exists(this.getPathForType(type))) {
108+
return;
109+
}
110+
107111
// Get all media from the database
108112
const media: Media[] = this.getCopy(this.getAllMedia(effect_id, type));
109113

@@ -120,19 +124,23 @@ class MediaManager {
120124
}
121125

122126
public setAllEffectsUnplayed(): void {
123-
const videoEffects: Record<string, Media[]> = this._db.getData(this.getPathForType('VIDEO'));
127+
if (this._db.exists(this.getPathForType('VIDEO'))) {
128+
const videoEffects: Record<string, Media[]> = this._db.getData(this.getPathForType('VIDEO'));
124129

125-
Object.values(videoEffects).forEach(medias => {
126-
medias.forEach(media => media.played = false);
127-
});
128-
this._db.push(this.getPathForType('VIDEO'), videoEffects, true);
130+
Object.values(videoEffects).forEach(medias => {
131+
medias.forEach(media => media.played = false);
132+
});
133+
this._db.push(this.getPathForType('VIDEO'), videoEffects, true);
134+
}
129135

130-
const audioEffects: Record<string, Media[]> = this._db.getData(this.getPathForType('AUDIO'));
136+
if (this._db.exists(this.getPathForType('AUDIO'))) {
137+
const audioEffects: Record<string, Media[]> = this._db.getData(this.getPathForType('AUDIO'));
131138

132-
Object.values(audioEffects).forEach(medias => {
133-
medias.forEach(media => media.played = false);
134-
});
135-
this._db.push(this.getPathForType('AUDIO'), audioEffects, true);
139+
Object.values(audioEffects).forEach(medias => {
140+
medias.forEach(media => media.played = false);
141+
});
142+
this._db.push(this.getPathForType('AUDIO'), audioEffects, true);
143+
}
136144
}
137145

138146
public getUnplayedMedia(effect_id: string, type: MediaType): Media {

0 commit comments

Comments
 (0)