mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2026-09-03 20:53:09 -05:00
Prevent get video duration unhandled crash
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user