The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/app/utils/server/functions/normalizeMessageFileUpload.ts

30 lines
910 B

import { Uploads } from '@rocket.chat/models';
import type { IMessage } from '@rocket.chat/core-typings';
import { getURL } from '../getURL';
import { FileUpload } from '../../../file-upload/server';
export const normalizeMessageFileUpload = async (message: Omit<IMessage, '_updatedAt'>): Promise<Omit<IMessage, '_updatedAt'>> => {
if (message.file && !message.fileUpload) {
const jwt = FileUpload.generateJWTToFileUrls({
rid: message.rid,
userId: message.u._id,
fileId: message.file._id,
});
const file = await Uploads.findOne({ _id: message.file._id });
if (!file) {
return message;
}
message.fileUpload = {
publicFilePath: file.name
? getURL(`${FileUpload.getPath(`${file._id}/${encodeURI(file.name)}`).substring(1)}${jwt ? `?token=${jwt}` : ''}`, {
cdn: false,
full: true,
})
: '',
type: file.type,
size: file.size,
};
}
return message;
};