1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 10:49:28 +02:00

Use async/await in lib and initializers

This commit is contained in:
Chocobozzz 2017-10-25 16:03:33 +02:00
parent eb08047657
commit f5028693a8
No known key found for this signature in database
GPG key ID: 583A612D890159BE
21 changed files with 721 additions and 751 deletions

View file

@ -1,7 +1,6 @@
import * as asyncLRU from 'async-lru'
import { join } from 'path'
import { createWriteStream } from 'fs'
import * as Promise from 'bluebird'
import { database as db, CONFIG, CACHE } from '../../initializers'
import { logger, unlinkPromise } from '../../helpers'
@ -43,15 +42,15 @@ class VideosPreviewCache {
})
}
private loadPreviews (key: string) {
return db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(key)
.then(video => {
if (!video) return undefined
private async loadPreviews (key: string) {
const video = await db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(key)
if (!video) return undefined
if (video.isOwned()) return join(CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName())
if (video.isOwned()) return join(CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName())
return this.saveRemotePreviewAndReturnPath(video)
})
const res = await this.saveRemotePreviewAndReturnPath(video)
return res
}
private saveRemotePreviewAndReturnPath (video: VideoInstance) {