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/packages/rocketchat-file-upload/client/lib/FileUploadFileSystem.js

62 lines
1.5 KiB

/* globals FileUploadBase, UploadFS, FileUpload:true, FileSystemStore:true */
FileSystemStore = new UploadFS.store.Local({
collection: RocketChat.models.Uploads.model,
name: 'fileSystem',
filter: new UploadFS.Filter({
onCheck: FileUpload.validateFileUpload
})
});
FileUpload.FileSystem = class FileUploadFileSystem extends FileUploadBase {
constructor(meta, file) {
super(meta, file);
this.handler = new UploadFS.Uploader({
store: FileSystemStore,
data: file,
file: meta,
onError: (err) => {
var uploading = Session.get('uploading');
if (uploading != null) {
let item = _.findWhere(uploading, {
id: this.id
});
if (item != null) {
item.error = err.reason;
item.percentage = 0;
}
return Session.set('uploading', uploading);
}
},
onComplete: (fileData) => {
var file = _.pick(fileData, '_id', 'type', 'size', 'name', 'identify');
file.url = fileData.url.replace(Meteor.absoluteUrl(), '/');
Meteor.call('sendFileMessage', this.meta.rid, null, file, () => {
Meteor.setTimeout(() => {
var uploading = Session.get('uploading');
if (uploading != null) {
let item = _.findWhere(uploading, {
id: this.id
});
return Session.set('uploading', _.without(uploading, item));
}
}, 2000);
});
}
});
}
start() {
return this.handler.start();
}
getProgress() {
return this.handler.getProgress();
}
stop() {
return this.handler.stop();
}
};