Skip to content

Commit

Permalink
Add gif support for avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
kimsible committed Nov 19, 2020
1 parent 0c392af commit 499586a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/initializers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ const CONSTRAINTS_FIELDS = {
PRIVATE_KEY: { min: 10, max: 5000 }, // Length
URL: { min: 3, max: 2000 }, // Length
AVATAR: {
EXTNAME: [ '.png', '.jpeg', '.jpg' ],
EXTNAME: [ '.png', '.jpeg', '.jpg', '.gif' ],
FILE_SIZE: {
max: 2 * 1024 * 1024 // 2MB
}
Expand Down
9 changes: 8 additions & 1 deletion server/lib/avatar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'multer'
import { move } from 'fs-extra'
import { sendUpdateActor } from './activitypub/send'
import { AVATARS_SIZE, LRU_CACHE, QUEUE_CONCURRENCY } from '../initializers/constants'
import { updateActorAvatarInstance } from './activitypub/actor'
Expand All @@ -20,7 +21,13 @@ async function updateActorAvatarFile (
const extension = extname(avatarPhysicalFile.filename)
const avatarName = uuidv4() + extension
const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName)
await processImage(avatarPhysicalFile.path, destination, AVATARS_SIZE)

// For gif do not resize, just move
if (extension === '.gif') {
await move(avatarPhysicalFile.path, destination)
} else {
await processImage(avatarPhysicalFile.path, destination, AVATARS_SIZE)
}

return retryTransactionWrapper(() => {
return sequelizeTypescript.transaction(async t => {
Expand Down

0 comments on commit 499586a

Please sign in to comment.