Prevent get video duration unhandled crash

This commit is contained in:
Chocobozzz
2026-07-13 15:45:29 +02:00
parent 1580662b7b
commit 39e0c06f4a
2 changed files with 26 additions and 18 deletions
+25 -18
View File
@@ -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)
}
}
} catch (err) {
this.lastFailedTry = new Date()
if (open) {
this.cityReader = await maxmind.open(this.cityDBPath)
}
throw err
}
}
+1
View File
@@ -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