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/app/file-upload/lib/FileUploadBase.js

87 lines
2.1 KiB

import path from 'path';
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { UploadFS } from 'meteor/jalik:ufs';
import _ from 'underscore';
import { canAccessRoom, hasPermission } from '../../authorization';
import { settings } from '../../settings';
10 years ago
// set ufs temp dir to $TMPDIR/ufs instead of /tmp/ufs if the variable is set
if ('TMPDIR' in process.env) {
UploadFS.config.tmpDir = path.join(process.env.TMPDIR, 'ufs');
}
9 years ago
UploadFS.config.defaultStorePermissions = new UploadFS.StorePermissions({
insert(userId, doc) {
if (userId) {
return true;
}
// allow inserts from slackbridge (message_id = slack-timestamp-milli)
if (doc && doc.message_id && doc.message_id.indexOf('slack-') === 0) {
return true;
}
// allow inserts to the UserDataFiles store
if (doc && doc.store && doc.store.split(':').pop() === 'UserDataFiles') {
return true;
}
Convert rocketchat-file-upload to main module structure (#13094) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Merge branch 'develop' into globals/move-rocketchat-callbacks * Fix missed export * Fix canBeDeleted and canBeCreated function, remove async
7 years ago
if (canAccessRoom(null, null, doc)) {
return true;
}
return false;
9 years ago
},
update(userId, doc) {
Convert rocketchat-file-upload to main module structure (#13094) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Merge branch 'develop' into globals/move-rocketchat-callbacks * Fix missed export * Fix canBeDeleted and canBeCreated function, remove async
7 years ago
return hasPermission(Meteor.userId(), 'delete-message', doc.rid) || (settings.get('Message_AllowDeleting') && userId === doc.userId);
9 years ago
},
remove(userId, doc) {
Convert rocketchat-file-upload to main module structure (#13094) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Merge branch 'develop' into globals/move-rocketchat-callbacks * Fix missed export * Fix canBeDeleted and canBeCreated function, remove async
7 years ago
return hasPermission(Meteor.userId(), 'delete-message', doc.rid) || (settings.get('Message_AllowDeleting') && userId === doc.userId);
},
9 years ago
});
export class FileUploadBase {
constructor(store, meta, file) {
this.id = Random.id();
this.meta = meta;
this.file = file;
this.store = store;
}
getProgress() {}
getFileName() {
return this.meta.name;
}
start(callback) {
this.handler = new UploadFS.Uploader({
store: this.store,
data: this.file,
file: this.meta,
onError: (err) => callback(err),
onComplete: (fileData) => {
const file = _.pick(fileData, '_id', 'type', 'size', 'name', 'identify', 'description');
file.url = fileData.url.replace(Meteor.absoluteUrl(), '/');
return callback(null, file, this.store.options.name);
},
});
this.handler.onProgress = (file, progress) => {
this.onProgress(progress);
};
return this.handler.start();
}
onProgress() {}
stop() {
return this.handler.stop();
}
}