Skip to content

Commit

Permalink
all changes by bratelefant
Browse files Browse the repository at this point in the history
for comparison with migration branch
  • Loading branch information
dr-dimitru committed Jan 19, 2025
1 parent 978e31a commit 86b00dc
Show file tree
Hide file tree
Showing 11 changed files with 1,596 additions and 471 deletions.
8 changes: 7 additions & 1 deletion client.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,13 @@ class FilesCollection extends FilesCollectionCore {
Meteor._debug('[FilesCollection] [insert()] Upload is disabled with [disableUpload]!');
return {};
}
return (new UploadInstance(config, this))[autoStart ? 'start' : 'manual']();
const uploadInstance = new UploadInstance(config, this);
if (autoStart) {
uploadInstance.start().catch((error) => {
console.error('[FilesCollection] [insert] Error starting upload:', error);

Check warning on line 261 in client.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
});
}
return uploadInstance;
}

/**
Expand Down
21 changes: 11 additions & 10 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export default class FilesCollectionCore extends EventEmitter {
*/
_debug() {
if (this.debug) {
(console.info || console.log || function () { }).apply(void 0, arguments);
// eslint-disable-next-line no-console
(console.info || console.log || function () {}).apply(void 0, arguments);
}
}

Expand Down Expand Up @@ -203,18 +204,18 @@ export default class FilesCollectionCore extends EventEmitter {
/*
* @locus Anywhere
* @memberOf FilesCollectionCore
* @name findOne
* @name findOneAsync
* @param {String|Object} selector - Mongo-Style selector (http://docs.meteor.com/api/collections.html#selectors)
* @param {Object} options - Mongo-Style selector Options (http://docs.meteor.com/api/collections.html#sortspecifiers)
* @summary Find and return Cursor for matching document Object
* @returns {FileCursor} Instance
* @returns {Promise<FileCursor>} Instance
*/
findOne(selector = {}, options) {
this._debug(`[FilesCollection] [findOne(${JSON.stringify(selector)}, ${JSON.stringify(options)})]`);
async findOneAsync(selector = {}, options) {
this._debug(`[FilesCollection] [findOneAsync(${JSON.stringify(selector)}, ${JSON.stringify(options)})]`);
check(selector, Match.Optional(Match.OneOf(Object, String, Boolean, Number, null)));

Check failure on line 215 in core.js

View workflow job for this annotation

GitHub Actions / lint

A function with a name starting with an uppercase letter should only be used as a constructor

Check failure on line 215 in core.js

View workflow job for this annotation

GitHub Actions / lint

A function with a name starting with an uppercase letter should only be used as a constructor
check(options, Match.Optional(Object));

Check failure on line 216 in core.js

View workflow job for this annotation

GitHub Actions / lint

A function with a name starting with an uppercase letter should only be used as a constructor

const doc = this.collection.findOne(selector, options);
const doc = await this.collection.findOneAsync(selector, options);
if (doc) {
return new FileCursor(doc, this);
}
Expand All @@ -241,13 +242,13 @@ export default class FilesCollectionCore extends EventEmitter {
/*
* @locus Anywhere
* @memberOf FilesCollectionCore
* @name update
* @name updateAsync
* @see http://docs.meteor.com/#/full/update
* @summary link Mongo.Collection update method
* @returns {Mongo.Collection} Instance
* @returns {Promise<Mongo.Collection>} Instance
*/
update() {
this.collection.update.apply(this.collection, arguments);
async updateAsync() {
await this.collection.updateAsync.apply(this.collection, arguments);
return this.collection;
}

Expand Down
129 changes: 64 additions & 65 deletions cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ export class FileCursor {
/*
* @locus Anywhere
* @memberOf FileCursor
* @name remove
* @param callback {Function} - Triggered asynchronously after item is removed or failed to be removed
* @name removeAsync
* @throws {Meteor.Error} - If no file reference is provided
* @summary Remove document
* @returns {FileCursor}
* @returns {Promise<FileCursor>}
*/
remove(callback) {
this._collection._debug('[FilesCollection] [FileCursor] [remove()]');
async removeAsync() {
this._collection._debug('[FilesCollection] [FileCursor] [removeAsync()]');
if (this._fileRef) {
this._collection.remove(this._fileRef._id, callback);
await this._collection.removeAsync(this._fileRef._id);
} else {
callback && callback(new Meteor.Error(404, 'No such file'));
throw new Meteor.Error(404, 'No such file');
}
return this;
}
Expand Down Expand Up @@ -113,11 +113,11 @@ export class FilesCursor {
* @memberOf FilesCursor
* @name get
* @summary Returns all matching document(s) as an Array. Alias of `.fetch()`
* @returns {[Object]}
* @returns {Promise<[Object]>}
*/
get() {
this._collection._debug('[FilesCollection] [FilesCursor] [get()]');
return this.cursor.fetch();
async get() {
this._collection._debug('[FilesCollection] [FilesCursor] [getAsync()]');
return this.cursor.fetchAsync();
}

/*
Expand All @@ -127,21 +127,21 @@ export class FilesCursor {
* @summary Returns `true` if there is next item available on Cursor
* @returns {Boolean}
*/
hasNext() {
this._collection._debug('[FilesCollection] [FilesCursor] [hasNext()]');
return this._current < (this.cursor.count() - 1);
async hasNext() {
this._collection._debug('[FilesCollection] [FilesCursor] [hasNextAsync()]');
return this._current < (await this.cursor.countAsync()) - 1;
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name next
* @summary Returns next item on Cursor, if available
* @returns {Object|undefined}
* @returns {Promise<Object|undefined>}
*/
next() {
this._collection._debug('[FilesCollection] [FilesCursor] [next()]');
this.cursor.fetch()[++this._current];
async next() {
this._collection._debug('[FilesCollection] [FilesCursor] [nextAsync()]');
return (await this.cursor.fetchAsync())[++this._current];
}

/*
Expand All @@ -161,89 +161,88 @@ export class FilesCursor {
* @memberOf FilesCursor
* @name previous
* @summary Returns previous item on Cursor, if available
* @returns {Object|undefined}
* @returns {Promise<Object|undefined>}
*/
previous() {
this._collection._debug('[FilesCollection] [FilesCursor] [previous()]');
this.cursor.fetch()[--this._current];
async previous() {
this._collection._debug('[FilesCollection] [FilesCursor] [previousAsync()]');
return (this.cursor.fetchAsync())[--this._current];
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name fetch
* @name fetchAsync
* @summary Returns all matching document(s) as an Array.
* @returns {[Object]}
* @returns {Promise<[Object]>}
*/
fetch() {
this._collection._debug('[FilesCollection] [FilesCursor] [fetch()]');
return this.cursor.fetch() || [];
async fetchAsync() {
this._collection._debug('[FilesCollection] [FilesCursor] [fetchAsync()]');
return (await this.cursor.fetchAsync()) || [];
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name first
* @summary Returns first item on Cursor, if available
* @returns {Object|undefined}
* @returns {Promise<Object|undefined>}
*/
first() {
this._collection._debug('[FilesCollection] [FilesCursor] [first()]');
async first() {
this._collection._debug('[FilesCollection] [FilesCursor] [firstAsync()]');
this._current = 0;
return this.fetch()[this._current];
return (await this.fetchAsync())[this._current];
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name last
* @summary Returns last item on Cursor, if available
* @returns {Object|undefined}
* @returns {Promise<Object|undefined>}
*/
last() {
async last() {
this._collection._debug('[FilesCollection] [FilesCursor] [last()]');
this._current = this.count() - 1;
return this.fetch()[this._current];
this._current = (await this.countAsync()) - 1;
return (await this.fetchAsync())[this._current];
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name count
* @name countAsync
* @summary Returns the number of documents that match a query
* @returns {Number}
* @returns {Promise<Number>}
*/
count() {
this._collection._debug('[FilesCollection] [FilesCursor] [count()]');
return this.cursor.count();
async countAsync() {
this._collection._debug('[FilesCollection] [FilesCursor] [countAsync()]');
return this.cursor.countAsync();
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name remove
* @param callback {Function} - Triggered asynchronously after item is removed or failed to be removed
* @name removeAsync
* @summary Removes all documents that match a query
* @returns {FilesCursor}
* @returns {Promise<FilesCursor>}
*/
remove(callback) {
this._collection._debug('[FilesCollection] [FilesCursor] [remove()]');
this._collection.remove(this._selector, callback);
async removeAsync() {
this._collection._debug('[FilesCollection] [FilesCursor] [removeAsync()]');
await this._collection.removeAsync(this._selector);
return this;
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name forEach
* @name forEachAsync
* @param callback {Function} - Function to call. It will be called with three arguments: the `file`, a 0-based index, and cursor itself
* @param context {Object} - An object which will be the value of `this` inside `callback`
* @summary Call `callback` once for each matching document, sequentially and synchronously.
* @returns {undefined}
* @returns {Promise<undefined>}
*/
forEach(callback, context = {}) {
this._collection._debug('[FilesCollection] [FilesCursor] [forEach()]');
this.cursor.forEach(callback, context);
async forEachAsync(callback, context = {}) {
this._collection._debug('[FilesCollection] [FilesCursor] [forEachAsync()]');
await this.cursor.forEachAsync(callback, context);
}

/*
Expand All @@ -252,41 +251,41 @@ export class FilesCursor {
* @name each
* @summary Returns an Array of FileCursor made for each document on current cursor
* Useful when using in {{#each FilesCursor#each}}...{{/each}} block template helper
* @returns {[FileCursor]}
* @returns {Promise<[FileCursor]>}
*/
each() {
return this.map((file) => {
async each() {
return this.mapAsync((file) => {
return new FileCursor(file, this._collection);
});
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name map
* @name mapAsync
* @param callback {Function} - Function to call. It will be called with three arguments: the `file`, a 0-based index, and cursor itself
* @param context {Object} - An object which will be the value of `this` inside `callback`
* @summary Map `callback` over all matching documents. Returns an Array.
* @returns {Array}
* @returns {Promise<Array>}
*/
map(callback, context = {}) {
this._collection._debug('[FilesCollection] [FilesCursor] [map()]');
return this.cursor.map(callback, context);
async mapAsync(callback, context = {}) {
this._collection._debug('[FilesCollection] [FilesCursor] [mapAsync()]');
return this.cursor.mapAsync(callback, context);
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name current
* @summary Returns current item on Cursor, if available
* @returns {Object|undefined}
* @returns {Promise<Object|undefined>}
*/
current() {
this._collection._debug('[FilesCollection] [FilesCursor] [current()]');
async current() {
this._collection._debug('[FilesCollection] [FilesCursor] [currentAsync()]');
if (this._current < 0) {
this._current = 0;
}
return this.fetch()[this._current];
return (await this.fetchAsync())[this._current];
}

/*
Expand All @@ -296,9 +295,9 @@ export class FilesCursor {
* @param callbacks {Object} - Functions to call to deliver the result set as it changes
* @summary Watch a query. Receive callbacks as the result set changes.
* @url http://docs.meteor.com/api/collections.html#Mongo-Cursor-observe
* @returns {Object} - live query handle
* @returns {Promise<Object>} - live query handle
*/
observe(callbacks) {
async observe(callbacks) {
this._collection._debug('[FilesCollection] [FilesCursor] [observe()]');
return this.cursor.observe(callbacks);
}
Expand Down
2 changes: 2 additions & 0 deletions lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,14 @@ const fixJSONStringify = function(obj) {
* @summary Returns formatted URL for file
* @returns {String} Downloadable link
*/
// eslint-disable-next-line camelcase, no-undef
const formatFleURL = (fileRef, version = 'original', _uriBase = (__meteor_runtime_config__ || {}).ROOT_URL) => {
check(fileRef, Object);
check(version, String);
let uriBase = _uriBase;

if (!helpers.isString(uriBase)) {
// eslint-disable-next-line camelcase, no-undef
uriBase = (__meteor_runtime_config__ || {}).ROOT_URL || '/';
}

Expand Down
11 changes: 7 additions & 4 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Package.describe({
name: 'ostrio:files',
version: '2.3.3',
version: '3.0.0',
summary: 'Upload files to a server or 3rd party storage: AWS:S3, GridFS, DropBox, and other',
git: 'https://github.com/veliovgroup/Meteor-Files',
documentation: 'README.md'
});

Package.onUse((api) => {
api.versionsFrom('1.9');
api.versionsFrom(['3.0']);
api.use('webapp', 'server');
api.use(['reactive-var', 'tracker', 'ddp-client'], 'client');
api.use(['mongo', 'check', 'random', 'ecmascript', 'fetch', 'ostrio:cookies@2.7.2'], ['client', 'server']);
api.use(['mongo', 'check', 'random', 'ecmascript', 'fetch', 'ostrio:cookies@2.9.0'], ['client', 'server']);
api.addAssets('worker.min.js', 'client');
api.mainModule('server.js', 'server');
api.mainModule('client.js', 'client');
Expand All @@ -19,11 +19,14 @@ Package.onUse((api) => {

Package.onTest((api) => {
api.use('tinytest');
api.use('meteortesting:mocha');
api.use(['ecmascript', 'ostrio:files'], ['client', 'server']);
api.addFiles('tests/helpers.js', ['client', 'server']);
api.mainModule('tests/server.js', 'server');
});

Npm.depends({
eventemitter3: '4.0.7',
'fs-extra': '11.2.0',
eventemitter3: '5.0.1',
'abort-controller': '3.0.0'
});
Loading

0 comments on commit 86b00dc

Please sign in to comment.