Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/file-upload/server/lib/FileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { fileUploadIsValidContentType } from '../../../utils/lib/fileUploadRestr
import { isValidJWT, generateJWT } from '../../../utils/server/lib/JWTHelper';
import { Messages } from '../../../models/server';
import { AppEvents, Apps } from '../../../apps/server';
import { streamToBuffer } from './streamToBuffer';

const cookie = new Cookies();
let maxFileSize = 0;
Expand Down Expand Up @@ -57,7 +58,7 @@ export const FileUpload = {
}, options, FileUpload[`default${ type }`]()));
},

validateFileUpload({ file, stream }) {
validateFileUpload({ file, content }) {
if (!Match.test(file.rid, String)) {
return false;
}
Expand Down Expand Up @@ -97,7 +98,7 @@ export const FileUpload = {

// App IPreFileUpload event hook
try {
Promise.await(Apps.triggerEvent(AppEvents.IPreFileUpload, { file, stream }));
Promise.await(Apps.triggerEvent(AppEvents.IPreFileUpload, { file, content }));
} catch (error) {
if (error instanceof AppsEngineException) {
throw new Meteor.Error('error-app-prevented', error.message);
Expand Down Expand Up @@ -596,12 +597,14 @@ export class FileUploadClass {
}

insert(fileData, streamOrBuffer, cb) {
fileData.size = parseInt(fileData.size) || 0;
if (streamOrBuffer instanceof stream) {
streamOrBuffer = Promise.await(streamToBuffer(streamOrBuffer));
}

// Check if the fileData matches store filter
const filter = this.store.getFilter();
if (filter && filter.check) {
filter.check({ file: fileData, stream: streamOrBuffer });
filter.check({ file: fileData, content: streamOrBuffer });
}

return this._doInsert(fileData, streamOrBuffer, cb);
Expand Down
11 changes: 11 additions & 0 deletions app/file-upload/server/lib/streamToBuffer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Readable } from 'stream';

export const streamToBuffer = (stream: Readable): Promise<Buffer> => new Promise((resolve) => {
const chunks: Array<Buffer> = [];

stream
.on('data', (data) => chunks.push(data))
.on('end', () => resolve(Buffer.concat(chunks)))
// force stream to resume data flow in case it was explicitly paused before
.resume();
});
2 changes: 1 addition & 1 deletion client/views/admin/apps/AppPermissionsReviewModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const AppPermissionsReviewModal = ({
? appPermissions.map((permission) =>
<li key={permission.name}>
<b>{ t(`Apps_Permissions_${ permission.name.replace('.', '_') }`) }</b>
{ permission.required && <span style={{ color: 'red' }}> ({ t('Required') })</span> }
{ permission.required && <span style={{ color: 'red' }}> ({ t('required') })</span> }
</li>)
: t('Apps_Permissions_No_Permissions_Required')
}
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"@nivo/heatmap": "^0.61.0",
"@nivo/line": "^0.61.1",
"@nivo/pie": "^0.61.1",
"@rocket.chat/apps-engine": "1.22.0-alpha.4545",
"@rocket.chat/apps-engine": "1.22.1",
"@rocket.chat/css-in-js": "^0.21.0",
"@rocket.chat/emitter": "^0.21.0",
"@rocket.chat/fuselage": "^0.21.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,6 @@
"Apps_Permissions_persistence": "Store internal data in the database",
"Apps_Permissions_scheduler": "Register and maintain scheduled jobs",
"Apps_Permissions_ui_interact": "Interact with the UI",
"Required": "required",

"Apps_Settings": "App's Settings",
"Apps_User_Already_Exists": "The username \"__username__\" is already being used. Rename or remove the user using it to install this App",
"Apps_WhatIsIt": "Apps: What Are They?",
Expand Down Expand Up @@ -3209,6 +3207,8 @@
"Requested_At": "Requested At",
"Requested_By": "Requested By",
"Require": "Require",
"Required": "Required",
"required": "required",
"Require_all_tokens": "Require all tokens",
"Require_any_token": "Require any token",
"Require_password_change": "Require password change",
Expand Down