Allow webp image uploads
This commit is contained in:
parent
d223dca0cd
commit
e08ff02a9f
|
@ -11,7 +11,7 @@ import { CONFIG } from '../../../initializers/config'
|
||||||
import { MIMETYPES } from '../../../initializers/constants'
|
import { MIMETYPES } from '../../../initializers/constants'
|
||||||
import { sequelizeTypescript } from '../../../initializers/database'
|
import { sequelizeTypescript } from '../../../initializers/database'
|
||||||
import { sendUpdateActor } from '../../../lib/activitypub/send'
|
import { sendUpdateActor } from '../../../lib/activitypub/send'
|
||||||
import { deleteActorAvatarFile, updateActorAvatarFile } from '../../../lib/avatar'
|
import { deleteLocalActorAvatarFile, updateLocalActorAvatarFile } from '../../../lib/avatar'
|
||||||
import { getOriginalVideoFileTotalDailyFromUser, getOriginalVideoFileTotalFromUser, sendVerifyUserEmail } from '../../../lib/user'
|
import { getOriginalVideoFileTotalDailyFromUser, getOriginalVideoFileTotalFromUser, sendVerifyUserEmail } from '../../../lib/user'
|
||||||
import {
|
import {
|
||||||
asyncMiddleware,
|
asyncMiddleware,
|
||||||
|
@ -238,7 +238,7 @@ async function updateMyAvatar (req: express.Request, res: express.Response) {
|
||||||
|
|
||||||
const userAccount = await AccountModel.load(user.Account.id)
|
const userAccount = await AccountModel.load(user.Account.id)
|
||||||
|
|
||||||
const avatar = await updateActorAvatarFile(userAccount, avatarPhysicalFile)
|
const avatar = await updateLocalActorAvatarFile(userAccount, avatarPhysicalFile)
|
||||||
|
|
||||||
return res.json({ avatar: avatar.toFormattedJSON() })
|
return res.json({ avatar: avatar.toFormattedJSON() })
|
||||||
}
|
}
|
||||||
|
@ -247,7 +247,7 @@ async function deleteMyAvatar (req: express.Request, res: express.Response) {
|
||||||
const user = res.locals.oauth.token.user
|
const user = res.locals.oauth.token.user
|
||||||
|
|
||||||
const userAccount = await AccountModel.load(user.Account.id)
|
const userAccount = await AccountModel.load(user.Account.id)
|
||||||
await deleteActorAvatarFile(userAccount)
|
await deleteLocalActorAvatarFile(userAccount)
|
||||||
|
|
||||||
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import { MIMETYPES } from '../../initializers/constants'
|
||||||
import { sequelizeTypescript } from '../../initializers/database'
|
import { sequelizeTypescript } from '../../initializers/database'
|
||||||
import { setAsyncActorKeys } from '../../lib/activitypub/actor'
|
import { setAsyncActorKeys } from '../../lib/activitypub/actor'
|
||||||
import { sendUpdateActor } from '../../lib/activitypub/send'
|
import { sendUpdateActor } from '../../lib/activitypub/send'
|
||||||
import { deleteActorAvatarFile, updateActorAvatarFile } from '../../lib/avatar'
|
import { deleteLocalActorAvatarFile, updateLocalActorAvatarFile } from '../../lib/avatar'
|
||||||
import { JobQueue } from '../../lib/job-queue'
|
import { JobQueue } from '../../lib/job-queue'
|
||||||
import { createLocalVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel'
|
import { createLocalVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel'
|
||||||
import {
|
import {
|
||||||
|
@ -140,7 +140,7 @@ async function updateVideoChannelAvatar (req: express.Request, res: express.Resp
|
||||||
const videoChannel = res.locals.videoChannel
|
const videoChannel = res.locals.videoChannel
|
||||||
const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON())
|
const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON())
|
||||||
|
|
||||||
const avatar = await updateActorAvatarFile(videoChannel, avatarPhysicalFile)
|
const avatar = await updateLocalActorAvatarFile(videoChannel, avatarPhysicalFile)
|
||||||
|
|
||||||
auditLogger.update(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannel.toFormattedJSON()), oldVideoChannelAuditKeys)
|
auditLogger.update(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannel.toFormattedJSON()), oldVideoChannelAuditKeys)
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ async function updateVideoChannelAvatar (req: express.Request, res: express.Resp
|
||||||
async function deleteVideoChannelAvatar (req: express.Request, res: express.Response) {
|
async function deleteVideoChannelAvatar (req: express.Request, res: express.Response) {
|
||||||
const videoChannel = res.locals.videoChannel
|
const videoChannel = res.locals.videoChannel
|
||||||
|
|
||||||
await deleteActorAvatarFile(videoChannel)
|
await deleteLocalActorAvatarFile(videoChannel)
|
||||||
|
|
||||||
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,7 +264,7 @@ const CONSTRAINTS_FIELDS = {
|
||||||
DESCRIPTION: { min: 3, max: 10000 }, // Length
|
DESCRIPTION: { min: 3, max: 10000 }, // Length
|
||||||
SUPPORT: { min: 3, max: 1000 }, // Length
|
SUPPORT: { min: 3, max: 1000 }, // Length
|
||||||
IMAGE: {
|
IMAGE: {
|
||||||
EXTNAME: [ '.jpg', '.jpeg' ],
|
EXTNAME: [ '.png', '.jpg', '.jpeg', '.webp' ],
|
||||||
FILE_SIZE: {
|
FILE_SIZE: {
|
||||||
max: 2 * 1024 * 1024 // 2MB
|
max: 2 * 1024 * 1024 // 2MB
|
||||||
}
|
}
|
||||||
|
@ -298,7 +298,7 @@ const CONSTRAINTS_FIELDS = {
|
||||||
PRIVATE_KEY: { min: 10, max: 5000 }, // Length
|
PRIVATE_KEY: { min: 10, max: 5000 }, // Length
|
||||||
URL: { min: 3, max: 2000 }, // Length
|
URL: { min: 3, max: 2000 }, // Length
|
||||||
AVATAR: {
|
AVATAR: {
|
||||||
EXTNAME: [ '.png', '.jpeg', '.jpg', '.gif' ],
|
EXTNAME: [ '.png', '.jpeg', '.jpg', '.gif', '.webp' ],
|
||||||
FILE_SIZE: {
|
FILE_SIZE: {
|
||||||
max: 2 * 1024 * 1024 // 2MB
|
max: 2 * 1024 * 1024 // 2MB
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,12 @@ import { queue } from 'async'
|
||||||
import { downloadImage } from '../helpers/requests'
|
import { downloadImage } from '../helpers/requests'
|
||||||
import { MAccountDefault, MChannelDefault } from '../types/models'
|
import { MAccountDefault, MChannelDefault } from '../types/models'
|
||||||
|
|
||||||
async function updateActorAvatarFile (
|
async function updateLocalActorAvatarFile (
|
||||||
accountOrChannel: MAccountDefault | MChannelDefault,
|
accountOrChannel: MAccountDefault | MChannelDefault,
|
||||||
avatarPhysicalFile: Express.Multer.File
|
avatarPhysicalFile: Express.Multer.File
|
||||||
) {
|
) {
|
||||||
const extension = extname(avatarPhysicalFile.filename)
|
const extension = extname(avatarPhysicalFile.filename)
|
||||||
|
|
||||||
const avatarName = uuidv4() + extension
|
const avatarName = uuidv4() + extension
|
||||||
const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName)
|
const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName)
|
||||||
await processImage(avatarPhysicalFile.path, destination, AVATARS_SIZE)
|
await processImage(avatarPhysicalFile.path, destination, AVATARS_SIZE)
|
||||||
|
@ -40,7 +41,7 @@ async function updateActorAvatarFile (
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteActorAvatarFile (
|
async function deleteLocalActorAvatarFile (
|
||||||
accountOrChannel: MAccountDefault | MChannelDefault
|
accountOrChannel: MAccountDefault | MChannelDefault
|
||||||
) {
|
) {
|
||||||
return retryTransactionWrapper(() => {
|
return retryTransactionWrapper(() => {
|
||||||
|
@ -78,7 +79,7 @@ const avatarPathUnsafeCache = new LRUCache<string, string>({ max: LRU_CACHE.AVAT
|
||||||
|
|
||||||
export {
|
export {
|
||||||
avatarPathUnsafeCache,
|
avatarPathUnsafeCache,
|
||||||
updateActorAvatarFile,
|
updateLocalActorAvatarFile,
|
||||||
deleteActorAvatarFile,
|
deleteLocalActorAvatarFile,
|
||||||
pushAvatarProcessInQueue
|
pushAvatarProcessInQueue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue