PeerTube/server/core/lib/files-cache/avatar-permanent-file-cache.ts

28 lines
831 B
TypeScript
Raw Normal View History

import { CONFIG } from '@server/initializers/config.js'
import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants.js'
import { ActorImageModel } from '@server/models/actor/actor-image.js'
import { MActorImage } from '@server/types/models/index.js'
import { AbstractPermanentFileCache } from './shared/index.js'
2023-06-06 15:59:51 +02:00
export class AvatarPermanentFileCache extends AbstractPermanentFileCache<MActorImage> {
2023-06-06 15:59:51 +02:00
constructor () {
2023-07-11 11:23:51 +02:00
super(CONFIG.STORAGE.ACTOR_IMAGES_DIR)
2023-06-06 15:59:51 +02:00
}
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]
}
}