Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Prevent get video duration unhandled crash

Chocobozzz39e0c06f4a4b
diff --git a/server/core/helpers/geo-ip.ts b/server/core/helpers/geo-ip.ts
index d9833dbcb2..5061d74ea5 100644
--- a/server/core/helpers/geo-ip.ts
+++ b/server/core/helpers/geo-ip.ts
@@ -15,7 +15,7 @@ export class GeoIP {
private countryReader: Reader<CountryResponse>
private cityReader: Reader<CityResponse>
- private lastInitTry: Date
+ private lastFailedTry: Date
private initReadersPromise: Promise<any>
private readonly INIT_READERS_RETRY_INTERVAL = 1000 * 60 * 10 // 10 minutes
@@ -48,6 +48,8 @@ export class GeoIP {
logger.error('Cannot get country/city information from IP.', { err })
return emptyResult
+ } finally {
+ this.initReadersPromise = undefined
}
}
@@ -119,31 +121,36 @@ export class GeoIP {
// ---------------------------------------------------------------------------
private async initReadersIfNeeded () {
- if (this.lastInitTry && this.lastInitTry.getTime() > Date.now() - this.INIT_READERS_RETRY_INTERVAL) return
- this.lastInitTry = new Date()
+ if (this.lastFailedTry && this.lastFailedTry.getTime() > Date.now() - this.INIT_READERS_RETRY_INTERVAL) return
- if (!this.countryReader) {
- let open = true
+ try {
+ if (!this.countryReader) {
+ let open = true
- if (!await pathExists(this.countryDBPath)) {
- open = await this.updateCountryDatabase()
- }
+ if (!await pathExists(this.countryDBPath)) {
+ open = await this.updateCountryDatabase()
+ }
- if (open) {
- this.countryReader = await maxmind.open(this.countryDBPath)
+ if (open) {
+ this.countryReader = await maxmind.open(this.countryDBPath)
+ }
}
- }
- if (!this.cityReader) {
- let open = true
+ if (!this.cityReader) {
+ let open = true
- if (!await pathExists(this.cityDBPath)) {
- open = await this.updateCityDatabase()
- }
+ if (!await pathExists(this.cityDBPath)) {
+ open = await this.updateCityDatabase()
+ }
- if (open) {
- this.cityReader = await maxmind.open(this.cityDBPath)
+ if (open) {
+ this.cityReader = await maxmind.open(this.cityDBPath)
+ }
}
+ } catch (err) {
+ this.lastFailedTry = new Date()
+
+ throw err
}
}
diff --git a/server/core/lib/video.ts b/server/core/lib/video.ts
index 2fa9680e21..0f8e7bc102 100644
--- a/server/core/lib/video.ts
+++ b/server/core/lib/video.ts
@@ -26,6 +26,7 @@ export async function setVideoTags (options: {
async function getVideoDuration (videoId: number | string) {
const video = await VideoModel.load(videoId)
+ if (!video) throw new Error(`Video with id ${videoId} not found`)
const duration = video.isLive
? undefined