Skip to content

Commit

Permalink
Merge pull request #527 from VeliovGroup/dev
Browse files Browse the repository at this point in the history
v1.9.2
  • Loading branch information
dr-dimitru authored Dec 2, 2017
2 parents 26453bc + bc4557f commit 1d823fb
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 102 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Give an expressive description
- Version of `Meteor-Files` you're experiencing this issue
- Version of `Meteor` you're experiencing this issue
- Where this issue appears? OS (Mac/Win/Linux)? Browser name and its version?
- Is it *Client* or *Server* issue?
- Post *Client* and/or *Server* logs with enabled `debug` option, you can enable "debug" mode in [*Constructor*](https://github.com/VeliovGroup/Meteor-Files/wiki/Constructor)

Expand Down
18 changes: 9 additions & 9 deletions .npm/package/npm-shrinkwrap.json

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

2 changes: 1 addition & 1 deletion .versions
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ [email protected]
[email protected]
[email protected]
ostrio:[email protected]
ostrio:[email protected].1
ostrio:[email protected].2
[email protected]
[email protected]
[email protected]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FVDSXRFW9VGA2)
[![Mentioned in Awesome ostrio:files](https://awesome.re/mentioned-badge.svg)](https://project-awesome.org/Urigo/awesome-meteor#files)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/VeliovGroup/Meteor-Files)
[![GitHub issues](https://img.shields.io/github/issues/VeliovGroup/Meteor-Files.svg)](https://github.com/VeliovGroup/Meteor-Files/issues)
[![GitHub forks](https://img.shields.io/github/forks/VeliovGroup/Meteor-Files.svg)](https://github.com/VeliovGroup/Meteor-Files/network)
Expand Down
2 changes: 1 addition & 1 deletion cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class FileCursor {
constructor(_fileRef, _collection) {
this._fileRef = _fileRef;
this._collection = _collection;
Object.assign(this, _fileRef);
_.extend(this, _fileRef);
}

/*
Expand Down
6 changes: 3 additions & 3 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'ostrio:files',
version: '1.9.1',
version: '1.9.2',
summary: 'File upload via DDP/HTTP to server FS, AWS, GridFS, DropBox, Google Drive or other 3rd party storage',
git: 'https://github.com/VeliovGroup/Meteor-Files',
documentation: 'README.md'
Expand All @@ -9,8 +9,8 @@ Package.describe({
Npm.depends({
'fs-extra': '4.0.2',
'request': '2.83.0',
'file-type': '7.2.0',
'eventemitter3': '2.0.3'
'file-type': '7.4.0',
'eventemitter3': '3.0.0'
});

Package.onUse(function(api) {
Expand Down
130 changes: 46 additions & 84 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ export class FilesCollection extends FilesCollectionCore {

self._debug(`[FilesCollection] [File Start Method] ${opts.file.name} - ${opts.fileId}`);
opts.___s = true;
const {result} = self._prepareUpload(_.clone(opts), this.userId, 'DDP Start Method');
const { result } = self._prepareUpload(_.clone(opts), this.userId, 'DDP Start Method');

if (self.collection.findOne(result._id)) {
throw new Meteor.Error(400, 'Can\'t start upload, data substitution detected!');
Expand Down Expand Up @@ -1256,6 +1256,7 @@ export class FilesCollection extends FilesCollectionCore {
* @param {String} opts - [Optional] Object with file-data
* @param {String} opts.type - [Optional] File mime-type
* @param {Object} opts.meta - [Optional] File additional meta-data
* @param {String} opts.fileId - _id, default *null*
* @param {Object} opts.fileName - [Optional] File name, if not specified file name and extension will be taken from path
* @param {String} opts.userId - [Optional] UserId, default *null*
* @param {Function} callback - [Optional] function(error, fileObj){...}
Expand Down Expand Up @@ -1654,46 +1655,9 @@ export class FilesCollection extends FilesCollectionCore {
}
}

let stream;

switch (responseType) {
case '400':
this._debug(`[FilesCollection] [serve(${vRef.path}, ${version})] [400] Content-Length mismatch!`);
var text = 'Content-Length mismatch!';

if (!http.response.headersSent) {
http.response.writeHead(400, {
'Content-Type': 'text/plain',
'Content-Length': text.length
});
}

if (!http.response.finished) {
http.response.end(text);
}
break;
case '404':
this._404(http);
break;
case '416':
this._debug(`[FilesCollection] [serve(${vRef.path}, ${version})] [416] Content-Range is not specified!`);
if (!http.response.headersSent) {
http.response.writeHead(416);
}
if (!http.response.finished) {
http.response.end();
}
break;
case '206':
this._debug(`[FilesCollection] [serve(${vRef.path}, ${version})] [206]`);
if (!http.response.headersSent) {
http.response.setHeader('Content-Range', `bytes ${reqRange.start}-${reqRange.end}/${vRef.size}`);
}
stream = readableStream || fs.createReadStream(vRef.path, {start: reqRange.start, end: reqRange.end});
if (!http.response.headersSent) {
if (readableStream) {
http.response.writeHead(206);
}
const respond = (stream, code) => {
if (!http.response.headersSent && readableStream) {
http.response.writeHead(code);
}

http.response.on('close', () => {
Expand All @@ -1705,7 +1669,8 @@ export class FilesCollection extends FilesCollectionCore {
}
});

http.request.on('abort', () => {
http.request.on('aborted', () => {
http.request.aborted = true;
if (typeof stream.abort === 'function') {
stream.abort();
}
Expand All @@ -1716,64 +1681,61 @@ export class FilesCollection extends FilesCollectionCore {

stream.on('open', () => {
if (!http.response.headersSent) {
http.response.writeHead(206);
http.response.writeHead(code);
}
}).on('abort', () => {
if (!http.response.finished) {
http.response.end();
}
if (!http.request.aborted) {
http.request.abort();
http.request.destroy();
}
}).on('error', streamErrorHandler
).on('end', () => {
if (!http.response.finished) {
http.response.end();
}
}).pipe(http.response);
break;
default:
this._debug(`[FilesCollection] [serve(${vRef.path}, ${version})] [200]`);
stream = readableStream || fs.createReadStream(vRef.path);
if (!http.response.headersSent) {
if (readableStream) { http.response.writeHead(200); }
}
};

http.response.on('close', () => {
if (typeof stream.abort === 'function') {
stream.abort();
}
if (typeof stream.end === 'function') {
stream.end();
}
});
switch (responseType) {
case '400':
this._debug(`[FilesCollection] [serve(${vRef.path}, ${version})] [400] Content-Length mismatch!`);
var text = 'Content-Length mismatch!';

http.request.on('abort', () => {
if (typeof stream.abort === 'function') {
stream.abort();
}
if (typeof stream.end === 'function') {
stream.end();
}
});
if (!http.response.headersSent) {
http.response.writeHead(400, {
'Content-Type': 'text/plain',
'Content-Length': text.length
});
}

stream.on('open', () => {
if (!http.response.headersSent) {
http.response.writeHead(200);
}
}).on('abort', () => {
if (!http.response.finished) {
http.response.end();
}
if (!http.request.aborted) {
http.request.abort();
}
}).on('error', streamErrorHandler
).on('end', () => {
if (!http.response.finished) {
http.response.end();
}
}).pipe(http.response);
if (!http.response.finished) {
http.response.end(text);
}
break;
case '404':
this._404(http);
break;
case '416':
this._debug(`[FilesCollection] [serve(${vRef.path}, ${version})] [416] Content-Range is not specified!`);
if (!http.response.headersSent) {
http.response.writeHead(416);
}
if (!http.response.finished) {
http.response.end();
}
break;
case '206':
this._debug(`[FilesCollection] [serve(${vRef.path}, ${version})] [206]`);
if (!http.response.headersSent) {
http.response.setHeader('Content-Range', `bytes ${reqRange.start}-${reqRange.end}/${vRef.size}`);
}
respond(readableStream || fs.createReadStream(vRef.path, {start: reqRange.start, end: reqRange.end}), 206);
break;
default:
this._debug(`[FilesCollection] [serve(${vRef.path}, ${version})] [200]`);
respond(readableStream || fs.createReadStream(vRef.path), 200);
break;
}
}
Expand Down
17 changes: 13 additions & 4 deletions upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ export class UploadInstance extends EventEmitter {
allowWebWorkers: Boolean
});

if (!this.config.fileName && !this.config.file.name) {
throw new Meteor.Error(400, '"fileName" must me specified for base64 upload!');
}

if (this.config.isBase64 === true) {
check(this.config.file, String);

if (!this.config.fileName) {
throw new Meteor.Error(400, '"fileName" must me specified for base64 upload!');
}

if (!!~this.config.file.indexOf('data:')) {
this.config.file = this.config.file.replace('data:', '');
}
Expand Down Expand Up @@ -109,6 +110,14 @@ export class UploadInstance extends EventEmitter {

if (this.config.file) {
if (!this.config.isBase64) {
try {
if (!this.config.file.name || !this.config.file.size) {
throw new Meteor.Error(500, 'Not a File!');
}
} catch (e) {
throw new Meteor.Error(500, '[FilesCollection] [insert] Insert method accepts File, not a FileList. You need to provide a real File. File must have `.name` property, and its size must be larger than zero.');
}

this.fileData = {
size: this.config.file.size,
type: this.config.type || this.config.file.type,
Expand Down

0 comments on commit 1d823fb

Please sign in to comment.