Skip to content

Commit

Permalink
Merge pull request #785 from veliovgroup/dev
Browse files Browse the repository at this point in the history
v2.0.0

Major update is out 🎉

__Major changes__:

- ⚠️ __[Deprecated]__ `streams` of `.insert()` method;
- ☝️ `http` module raplcaed with `fetch` — *As suggested* in `[email protected]` release and `http` package being deprecated;
- ☝️ `request-libcurl` replaced with `fetch` — As a fix for #781 and similar issues;
- ⚠️ __[removed]__ `file-type` library used to detect file-type (*file's mime-type*) based on "magic numbers". Now mime-type detected from data supplied by browser. __Regresion possible *upgrade with care* if your app rely on mime-type detected after file is fully uploaded to server, this change won't affect mime-type detected on the *Client* before file fully loaded to server__.

__Improved__:

- Pause/Resume logic when connection with server is interrupted (*no more missed chunks*);
- Chunks deliverability, including retries if chunk was sent only partially.

__Other changes__:

- 🤝 Compatibility with `[email protected]`;
- 📦 `ostrio:[email protected]`, *was `v2.6.1`*;
- 📦 `[email protected]`, *was `v9.0.1`*;
- 🖥 Update, refactor, and refine [demo app](https://github.com/veliovgroup/meteor-files-website);
- 👨‍💻 Update [`meteor-files-autoform`](https://github.com/VeliovGroup/meteor-autoform-file) package;
- 📋 Documentation refactoring.
  • Loading branch information
dr-dimitru authored Feb 4, 2021
2 parents 143ad19 + cd81e23 commit 2b76cc3
Show file tree
Hide file tree
Showing 21 changed files with 362 additions and 978 deletions.
701 changes: 17 additions & 684 deletions .npm/package/npm-shrinkwrap.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2020, dr.dimitru (Dmitry A.; Veliov Group, LLC)
Copyright (c) 2021, dr.dimitru (Dmitry A.; Veliov Group, LLC)
All rights reserved.

Redistribution and use in source and binary forms,
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ Stable, fast, robust, and well-maintained Meteor.js package for files management
- [Stream files](https://github.com/VeliovGroup/Meteor-Files#stream-files)
- [Download Button](https://github.com/VeliovGroup/Meteor-Files#download-button)
- [Documentation and tutorials](https://github.com/VeliovGroup/Meteor-Files/blob/master/docs/toc.md)
- [__Demo apps and examples__](https://github.com/VeliovGroup/Meteor-Files#demo-application)
- [3rd-party storage integration](https://github.com/VeliovGroup/Meteor-Files/blob/master/docs/3rd-party-storage.md) examples - AWS S3, DropBox, GridFS and Google Storage
- [TypeScript Definitions](https://github.com/VeliovGroup/Meteor-Files/blob/master/docs/typescript-definitions.md)
- [Demo apps and examples](https://github.com/VeliovGroup/Meteor-Files#demo-application)
- [Related Packages](https://github.com/VeliovGroup/Meteor-Files#related-packages)
- [Why this package?](https://github.com/VeliovGroup/Meteor-Files#why-meteor-files)
- [Help / Support](https://github.com/VeliovGroup/Meteor-Files#get-support)
Expand Down Expand Up @@ -138,7 +138,6 @@ Template.uploadForm.events({
// multiple files were selected
const upload = Images.insert({
file: e.currentTarget.files[0],
streams: 'dynamic',
chunkSize: 'dynamic'
}, false);

Expand Down Expand Up @@ -311,7 +310,7 @@ For more expressive example see [Download demo](https://github.com/VeliovGroup/M
3. __How to pause/continue upload and get progress/speed/remaining time?__: see *Object* returned from [`insert` method](https://github.com/VeliovGroup/Meteor-Files/blob/master/docs/insert.md)
4. When using any of `accounts` packages - package `accounts-base` must be explicitly added to `.meteor/packages` above `ostrio:files`
5. __cURL/POST uploads__ - Take a look on [POST-Example](https://github.com/noris666/Meteor-Files-POST-Example) by [@noris666](https://github.com/noris666)
6. In __Safari__ (Mobile and Desktop) for `DDP` upload streams are hard-coded to `1` and chunk size is reduced by algorithm, due to error thrown if too many connection is open by the browser or frame is too big. Limit simultaneous uploads to `6` is recommended for Safari. This issue should be fixed in Safari 11. Switching to `http` transport (*which has no such issue*) is recommended for Safari. See [#458](https://github.com/VeliovGroup/Meteor-Files/issues/458)
6. In __Safari__ (Mobile and Desktop) for `DDP` chunk size is reduced by algorithm, due to error thrown if frame is too big. Limit simultaneous uploads to `6` is recommended for Safari. This issue should be fixed in Safari 11. Switching to `http` transport (*which has no such issue*) is recommended for Safari. See [#458](https://github.com/VeliovGroup/Meteor-Files/issues/458)
7. Make sure you're using single domain for the Meteor app, and the same domain for hosting Meteor-Files endpoints, see [#737](https://github.com/VeliovGroup/Meteor-Files/issues/737) for details
8. When proxying requests to Meteor-Files endpoint make sure protocol `http/1.1` is used, see [#742](https://github.com/VeliovGroup/Meteor-Files/issues/742) for details

Expand All @@ -331,9 +330,7 @@ For more expressive example see [Download demo](https://github.com/VeliovGroup/M
## Demo application:

- [Live: __files.veliov.com__](https://files.veliov.com)
- [Source Code Rep](https://github.com/VeliovGroup/Meteor-Files-Demos/tree/master/demo)
- [Compiled Rep](https://github.com/VeliovGroup/Meteor-Files-Demo)
- [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/VeliovGroup/Meteor-Files-Demo)
- [Source Code Rep](https://github.com/veliovgroup/meteor-files-website#file-sharing-web-app)

## Related Packages:

Expand Down
17 changes: 8 additions & 9 deletions client.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Mongo } from 'meteor/mongo';
import { Meteor } from 'meteor/meteor';
import { DDP } from 'meteor/ddp-client';
import { Cookies } from 'meteor/ostrio:cookies';
import { check, Match } from 'meteor/check';
import { UploadInstance } from './upload.js';
import { DDP } from 'meteor/ddp-client';
import { Mongo } from 'meteor/mongo';
import { Meteor } from 'meteor/meteor';
import { Cookies } from 'meteor/ostrio:cookies';
import { check, Match } from 'meteor/check';
import { UploadInstance } from './upload.js';
import FilesCollectionCore from './core.js';
import { formatFleURL, helpers } from './lib.js';

Expand Down Expand Up @@ -130,10 +130,10 @@ export class FilesCollection extends FilesCollectionCore {
const _URL = window.URL || window.webkitURL || window.mozURL || window.msURL || window.oURL || false;
if (window.Worker && window.Blob && _URL && helpers.isFunction(_URL.createObjectURL)) {
this._supportWebWorker = true;
this._webWorkerUrl = _URL.createObjectURL(new window.Blob(['!function(a){"use strict";a.onmessage=function(b){var c=b.data.f.slice(b.data.cs*(b.data.cc-1),b.data.cs*b.data.cc);if(b.data.ib===!0)postMessage({bin:c,chunkId:b.data.cc});else{var d;a.FileReader?(d=new FileReader,d.onloadend=function(a){postMessage({bin:(d.result||a.srcElement||a.target).split(",")[1],chunkId:b.data.cc,s:b.data.s})},d.onerror=function(a){throw(a.target||a.srcElement).error},d.readAsDataURL(c)):a.FileReaderSync?(d=new FileReaderSync,postMessage({bin:d.readAsDataURL(c).split(",")[1],chunkId:b.data.cc})):postMessage({bin:null,chunkId:b.data.cc,error:"File API is not supported in WebWorker!"})}}}(this);'], {type: 'application/javascript'}));
this._webWorkerUrl = _URL.createObjectURL(new window.Blob(['!function(a){"use strict";a.onmessage=function(b){var c=b.data.f.slice(b.data.cs*(b.data.cc-1),b.data.cs*b.data.cc);if(b.data.ib===!0)postMessage({bin:c,chunkId:b.data.cc});else{var d;a.FileReader?(d=new FileReader,d.onloadend=function(a){postMessage({bin:(d.result||a.srcElement||a.target).split(",")[1],chunkId:b.data.cc,s:b.data.s})},d.onerror=function(a){throw(a.target||a.srcElement).error},d.readAsDataURL(c)):a.FileReaderSync?(d=new FileReaderSync,postMessage({bin:d.readAsDataURL(c).split(",")[1],chunkId:b.data.cc})):postMessage({bin:null,chunkId:b.data.cc,error:"File API is not supported in WebWorker!"})}}}(this);'], {type: 'application/javascript'}));
} else if (window.Worker) {
this._supportWebWorker = true;
this._webWorkerUrl = Meteor.absoluteUrl('packages/ostrio_files/worker.min.js');
this._webWorkerUrl = Meteor.absoluteUrl('packages/ostrio_files/worker.min.js');
} else {
this._supportWebWorker = false;
}
Expand Down Expand Up @@ -219,7 +219,6 @@ export class FilesCollection extends FilesCollectionCore {
* {String} fileId - Optionnal `fileId` used at insert
* {Object} meta - Additional data as object, use later for search
* {Boolean} allowWebWorkers- Allow/Deny WebWorkers usage
* {Number|dynamic} streams - Quantity of parallel upload streams, default: 2
* {Number|dynamic} chunkSize - Chunk size for upload
* {String} transport - Upload transport `http` or `ddp`
* {Object} ddp - Custom DDP connection. Object returned form `DDP.connect()`
Expand Down
18 changes: 9 additions & 9 deletions core.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventEmitter } from 'eventemitter3';
import { check, Match } from 'meteor/check';
import { formatFleURL, helpers } from './lib.js';
import { EventEmitter } from 'eventemitter3';
import { check, Match } from 'meteor/check';
import { formatFleURL, helpers } from './lib.js';
import { FilesCursor, FileCursor } from './cursor.js';

export default class FilesCollectionCore extends EventEmitter {
Expand Down Expand Up @@ -149,12 +149,12 @@ export default class FilesCollectionCore extends EventEmitter {
* @summary Internal method. Classify file based on 'type' field
*/
_updateFileTypes(data) {
data.isVideo = /^video\//i.test(data.type);
data.isAudio = /^audio\//i.test(data.type);
data.isImage = /^image\//i.test(data.type);
data.isText = /^text\//i.test(data.type);
data.isJSON = /^application\/json$/i.test(data.type);
data.isPDF = /^application\/(x-)?pdf$/i.test(data.type);
data.isVideo = /^video\//i.test(data.type);
data.isAudio = /^audio\//i.test(data.type);
data.isImage = /^image\//i.test(data.type);
data.isText = /^text\//i.test(data.type);
data.isJSON = /^application\/json$/i.test(data.type);
data.isPDF = /^application\/(x-)?pdf$/i.test(data.type);
}

/*
Expand Down
1 change: 0 additions & 1 deletion docs/about-transports.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,3 @@ The cons:

- No mobile browsers support;
- Chunk size limited to 64KB;
- Only single stream is supported (*so, it's currently uses synchronous chunk uploads*. If `RTC/DC` will be accepted by community we will implement asynchronous chunks upload).
2 changes: 1 addition & 1 deletion docs/constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
Isomorphic
</td>
<td>
Upload &amp; Serve (<em>for 206 responce</em>) chunk size
Upload &amp; Serve (<em>for 206 response</em>) chunk size
</td>
<td>
<code>272144</code>
Expand Down
30 changes: 16 additions & 14 deletions docs/dropbox-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Example below shows how to store and serve uploaded file via DropBox. This example also covers file removing from both your application and DropBox.

## Prerequisite
We will use next packages: Request (NPM), Node-fetch (NPM) and Underscore (meteor)

We will use next packages: request (NPM), Node-fetch (NPM) and Underscore (meteor)

```shell
meteor npm install request
Expand All @@ -24,17 +25,18 @@ meteor npm install dropbox@=4.0.30
```

### Step 2: Get access to DropBox API:
- Go to https://www.dropbox.com/developers (*Sign(in|up) if required*)
- Click on [Create your app](https://www.dropbox.com/developers/apps/create)
- Choose "*Dropbox API*"
- Choose "*App folder*"
- Type-in your application name
- Go to you application's *settings*
- Click on "*Enable additional users*"
- Obtain "*Generated access token*" (Click on "*Generate Access token*") for `accessToken` in `new Dropbox({})`

- Go to [DropBox Developers](https://www.dropbox.com/developers) (*Sign(in|up) if required*)
- Click on [Create your app](https://www.dropbox.com/developers/apps/create)
- Choose "*Dropbox API*"
- Choose "*App folder*"
- Type-in your application name
- Go to you application's *settings*
- Click on "*Enable additional users*"
- Obtain "*Generated access token*" (Click on "*Generate Access token*") for `accessToken` in `new Dropbox({})`

```javascript
var Dropbox, Request, bound, client, fs, Collections = {};
var Dropbox, request, bound, client, fs, Collections = {};

if(Meteor.isServer){
Dropbox = require('dropbox').Dropbox;
Expand All @@ -48,7 +50,7 @@ if(Meteor.isServer){
});
}

Request = require('request');
request = require('request');
fs = require('fs');

Collections.files = new FilesCollection({
Expand Down Expand Up @@ -84,7 +86,7 @@ Collections.files = new FilesCollection({
console.error(error);
});
};

var writeToDB = function(fileRef, version, data){
// DropBox already uses random URLs
// No need to use random file names
Expand Down Expand Up @@ -116,7 +118,7 @@ Collections.files = new FilesCollection({
readFile(fileRef, vRef, version);
});
};

sendToStorage(fileRef);
} catch(error){
// There was an error while uploading the file to Dropbox, displaying the concerned file
Expand Down Expand Up @@ -148,7 +150,7 @@ Collections.files = new FilesCollection({
// If file is moved to DropBox
// We will pipe request to DropBox
// So, original link will stay always secure
Request({
request({
url: path,
headers: _.pick(http.request.headers, 'range', 'accept-language', 'accept', 'cache-control', 'pragma', 'connection', 'upgrade-insecure-requests', 'user-agent')
}).on('response', function(response){
Expand Down
3 changes: 1 addition & 2 deletions docs/file-subversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ if (Meteor.isClient) {
} else {
return "Please upload file in next formats: 'ogg', 'mp4', 'avi', 'webm' with size less than 512 Mb. You have tried to upload file with \"" + this.ext + "\" extension and with \"" + (Math.round((this.size / (1024 * 1024)) * 100) / 100) + "\" Mb";
}
},
streams: 8
}
});
});
}
Expand Down
Loading

0 comments on commit 2b76cc3

Please sign in to comment.