Save avatars to le cloud in beforeSave hooks
Added encryption to uploads Updated icon for team settings
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
// @flow
|
||||
import uuid from 'uuid';
|
||||
import { DataTypes, sequelize, Op } from '../sequelize';
|
||||
import { publicS3Endpoint, uploadToS3FromUrl } from '../utils/s3';
|
||||
import Collection from './Collection';
|
||||
import User from './User';
|
||||
|
||||
@@ -33,6 +35,18 @@ Team.associate = models => {
|
||||
Team.hasMany(models.User, { as: 'users' });
|
||||
};
|
||||
|
||||
const uploadAvatar = async model => {
|
||||
const endpoint = publicS3Endpoint();
|
||||
|
||||
if (model.avatarUrl && !model.avatarUrl.startsWith(endpoint)) {
|
||||
const newUrl = await uploadToS3FromUrl(
|
||||
model.avatarUrl,
|
||||
`avatars/${model.id}/${uuid.v4()}`
|
||||
);
|
||||
if (newUrl) model.avatarUrl = newUrl;
|
||||
}
|
||||
};
|
||||
|
||||
Team.prototype.createFirstCollection = async function(userId) {
|
||||
return await Collection.create({
|
||||
name: 'General',
|
||||
@@ -82,4 +96,6 @@ Team.prototype.activateUser = async function(user: User, admin: User) {
|
||||
});
|
||||
};
|
||||
|
||||
Team.beforeSave(uploadAvatar);
|
||||
|
||||
export default Team;
|
||||
|
||||
Reference in New Issue
Block a user