aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/lib/files-cache/avatar-permanent-file-cache.ts
blob: 0c508b0636a7a2ab6878cdc0f9de9283e17638cf (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                    



                                                                  
 
                                                                                       

                  
                                          
















                                                                                  
import { CONFIG } from '@server/initializers/config'
import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants'
import { ActorImageModel } from '@server/models/actor/actor-image'
import { MActorImage } from '@server/types/models'
import { AbstractPermanentFileCache } from './shared'

export class AvatarPermanentFileCache extends AbstractPermanentFileCache<MActorImage> {

  constructor () {
    super(CONFIG.STORAGE.ACTOR_IMAGES_DIR)
  }

  protected loadModel (filename: string) {
    return ActorImageModel.loadByName(filename)
  }

  protected getImageSize (image: MActorImage): { width: number, height: number } {
    if (image.width && image.height) {
      return {
        height: image.height,
        width: image.width
      }
    }

    return ACTOR_IMAGES_SIZE[image.type][0]
  }
}