video-miniature-permanent-file-cache.ts 898 B

12345678910111213141516171819202122232425262728
  1. import { CONFIG } from '@server/initializers/config.js'
  2. import { THUMBNAILS_SIZE } from '@server/initializers/constants.js'
  3. import { ThumbnailModel } from '@server/models/video/thumbnail.js'
  4. import { MThumbnail } from '@server/types/models/index.js'
  5. import { ThumbnailType } from '@peertube/peertube-models'
  6. import { AbstractPermanentFileCache } from './shared/index.js'
  7. export class VideoMiniaturePermanentFileCache extends AbstractPermanentFileCache<MThumbnail> {
  8. constructor () {
  9. super(CONFIG.STORAGE.THUMBNAILS_DIR)
  10. }
  11. protected loadModel (filename: string) {
  12. return ThumbnailModel.loadByFilename(filename, ThumbnailType.MINIATURE)
  13. }
  14. protected getImageSize (image: MThumbnail): { width: number, height: number } {
  15. if (image.width && image.height) {
  16. return {
  17. height: image.height,
  18. width: image.width
  19. }
  20. }
  21. return THUMBNAILS_SIZE
  22. }
  23. }