Skip to content

Commit

Permalink
Reduce lazy static error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Jun 30, 2022
1 parent a4152be commit cd25344
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
11 changes: 9 additions & 2 deletions server/lib/files-cache/videos-caption-cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { join } from 'path'
import { logger } from '@server/helpers/logger'
import { doRequestAndSaveToFile } from '@server/helpers/requests'
import { CONFIG } from '../../initializers/config'
import { FILES_CACHE } from '../../initializers/constants'
Expand Down Expand Up @@ -41,9 +42,15 @@ class VideosCaptionCache extends AbstractVideoStaticFileCache <string> {
const remoteUrl = videoCaption.getFileUrl(video)
const destPath = join(FILES_CACHE.VIDEO_CAPTIONS.DIRECTORY, videoCaption.filename)

await doRequestAndSaveToFile(remoteUrl, destPath)
try {
await doRequestAndSaveToFile(remoteUrl, destPath)

return { isOwned: false, path: destPath }
return { isOwned: false, path: destPath }
} catch (err) {
logger.info('Cannot fetch remote caption file %s.', remoteUrl, { err })

return undefined
}
}
}

Expand Down
14 changes: 10 additions & 4 deletions server/lib/files-cache/videos-preview-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache <string> {

const preview = video.getPreview()
const destPath = join(FILES_CACHE.PREVIEWS.DIRECTORY, preview.filename)

const remoteUrl = preview.getFileUrl(video)
await doRequestAndSaveToFile(remoteUrl, destPath)

logger.debug('Fetched remote preview %s to %s.', remoteUrl, destPath)
try {
await doRequestAndSaveToFile(remoteUrl, destPath)

logger.debug('Fetched remote preview %s to %s.', remoteUrl, destPath)

return { isOwned: false, path: destPath }
} catch (err) {
logger.info('Cannot fetch remote preview file %s.', remoteUrl, { err })

return { isOwned: false, path: destPath }
return undefined
}
}
}

Expand Down
15 changes: 11 additions & 4 deletions server/lib/files-cache/videos-torrent-cache.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { join } from 'path'
import { logger } from '@server/helpers/logger'
import { doRequestAndSaveToFile } from '@server/helpers/requests'
import { VideoFileModel } from '@server/models/video/video-file'
import { MVideo, MVideoFile } from '@server/types/models'
import { CONFIG } from '../../initializers/config'
import { FILES_CACHE } from '../../initializers/constants'
import { VideoModel } from '../../models/video/video'
import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache'
import { MVideo, MVideoFile } from '@server/types/models'

class VideosTorrentCache extends AbstractVideoStaticFileCache <string> {

Expand Down Expand Up @@ -46,11 +47,17 @@ class VideosTorrentCache extends AbstractVideoStaticFileCache <string> {
const remoteUrl = file.getRemoteTorrentUrl(video)
const destPath = join(FILES_CACHE.TORRENTS.DIRECTORY, file.torrentFilename)

await doRequestAndSaveToFile(remoteUrl, destPath)
try {
await doRequestAndSaveToFile(remoteUrl, destPath)

const downloadName = this.buildDownloadName(video, file)
const downloadName = this.buildDownloadName(video, file)

return { isOwned: false, path: destPath, downloadName }
return { isOwned: false, path: destPath, downloadName }
} catch (err) {
logger.info('Cannot fetch remote torrent file %s.', remoteUrl, { err })

return undefined
}
}

private buildDownloadName (video: MVideo, file: MVideoFile) {
Expand Down

0 comments on commit cd25344

Please sign in to comment.