1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 18:29:27 +02:00

Implement avatar miniatures (#4639)

* client: remove unused file

* refactor(client/my-actor-avatar): size from input

Read size from component input instead of scss, to make it possible to
use smaller avatar images when implemented.

* implement avatar miniatures

close #4560

* fix(test): max file size

* fix(search-index): normalize res acc to avatarMini

* refactor avatars to an array

* client/search: resize channel avatar to 120

* refactor(client/videos): remove unused function

* client(actor-avatar): set default size

* fix tests and avatars full result

When findOne is used only an array containting one avatar is returned.

* update migration version and version notations

* server/search: harmonize normalizing

* Cleanup avatar miniature PR

Co-authored-by: Chocobozzz <me@florianbigard.com>
This commit is contained in:
kontrollanten 2022-02-28 08:34:43 +01:00 committed by GitHub
parent 5cad2ca9db
commit d0800f7661
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
150 changed files with 2027 additions and 1276 deletions

View file

@ -4,7 +4,7 @@ import { ActorModel } from '@server/models/actor/actor'
import { FilteredModelAttributes } from '@server/types'
import { getLowercaseExtension } from '@shared/core-utils'
import { buildUUID } from '@shared/extra-utils'
import { ActivityPubActor, ActorImageType } from '@shared/models'
import { ActivityIconObject, ActivityPubActor, ActorImageType } from '@shared/models'
function getActorAttributesFromObject (
actorObject: ActivityPubActor,
@ -30,33 +30,36 @@ function getActorAttributesFromObject (
}
}
function getImageInfoFromObject (actorObject: ActivityPubActor, type: ActorImageType) {
const mimetypes = MIMETYPES.IMAGE
const icon = type === ActorImageType.AVATAR
? actorObject.icon
function getImagesInfoFromObject (actorObject: ActivityPubActor, type: ActorImageType) {
const iconsOrImages = type === ActorImageType.AVATAR
? actorObject.icons || actorObject.icon
: actorObject.image
if (!icon || icon.type !== 'Image' || !isActivityPubUrlValid(icon.url)) return undefined
return normalizeIconOrImage(iconsOrImages).map(iconOrImage => {
const mimetypes = MIMETYPES.IMAGE
let extension: string
if (iconOrImage.type !== 'Image' || !isActivityPubUrlValid(iconOrImage.url)) return undefined
if (icon.mediaType) {
extension = mimetypes.MIMETYPE_EXT[icon.mediaType]
} else {
const tmp = getLowercaseExtension(icon.url)
let extension: string
if (mimetypes.EXT_MIMETYPE[tmp] !== undefined) extension = tmp
}
if (iconOrImage.mediaType) {
extension = mimetypes.MIMETYPE_EXT[iconOrImage.mediaType]
} else {
const tmp = getLowercaseExtension(iconOrImage.url)
if (!extension) return undefined
if (mimetypes.EXT_MIMETYPE[tmp] !== undefined) extension = tmp
}
return {
name: buildUUID() + extension,
fileUrl: icon.url,
height: icon.height,
width: icon.width,
type
}
if (!extension) return undefined
return {
name: buildUUID() + extension,
fileUrl: iconOrImage.url,
height: iconOrImage.height,
width: iconOrImage.width,
type
}
})
}
function getActorDisplayNameFromObject (actorObject: ActivityPubActor) {
@ -65,6 +68,15 @@ function getActorDisplayNameFromObject (actorObject: ActivityPubActor) {
export {
getActorAttributesFromObject,
getImageInfoFromObject,
getImagesInfoFromObject,
getActorDisplayNameFromObject
}
// ---------------------------------------------------------------------------
function normalizeIconOrImage (icon: ActivityIconObject | ActivityIconObject[]): ActivityIconObject[] {
if (Array.isArray(icon)) return icon
if (icon) return [ icon ]
return []
}