Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ecf3f06

Browse files
committed
Fix avatar update
1 parent 211239e commit ecf3f06

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

server/lib/avatar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { AccountModel } from '../models/account/account'
77
import { VideoChannelModel } from '../models/video/video-channel'
88
import { extname, join } from 'path'
99
import { retryTransactionWrapper } from '../helpers/database-utils'
10+
import * as uuidv4 from 'uuid/v4'
1011

1112
async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, accountOrChannel: AccountModel | VideoChannelModel) {
1213
const extension = extname(avatarPhysicalFile.filename)
13-
const avatarName = accountOrChannel.Actor.uuid + extension
14+
const avatarName = uuidv4() + extension
1415
const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName)
1516
await processImage(avatarPhysicalFile, destination, AVATARS_SIZE)
1617

server/models/avatar/avatar.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export class AvatarModel extends Model<AvatarModel> {
2323
@AfterDestroy
2424
static removeFilesAndSendDelete (instance: AvatarModel) {
2525
logger.info('Removing avatar file %s.', instance.filename)
26-
return instance.removeAvatar()
26+
27+
// Don't block the transaction
28+
instance.removeAvatar()
29+
.catch(err => logger.error('Cannot remove avatar file %s.', instance.filename, err))
2730
}
2831

2932
toFormattedJSON (): Avatar {

0 commit comments

Comments
 (0)