Skip to content

Commit

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

__Changes:__

- πŸ‘¨β€πŸ’» Improve `createIndex` helper
- πŸ‘¨β€πŸ’» Improve error output when FileSystem destination not writable; Related to #857, thanks to @Leekao
- 🐞 Fix custom `allowedOrigins` option for CORS; Closing #850, thanks to @djlogan2;

__Notes:__

- πŸ‘¨β€πŸ”¬ Tested with latest release of `[email protected]`
  • Loading branch information
dr-dimitru authored Nov 3, 2022
2 parents 00ab6f7 + a4a127b commit 7d4796e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
18 changes: 9 additions & 9 deletions .versions
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ [email protected]
[email protected]
[email protected]
[email protected]
ddp-client@2.5.0
ddp-client@2.6.0
[email protected]
ddp-server@2.5.0
ddp-server@2.6.0
[email protected]
[email protected]
[email protected]
Expand All @@ -21,21 +21,21 @@ [email protected]
[email protected]
[email protected]
[email protected]
local-test:ostrio:[email protected].0
local-test:ostrio:[email protected].1
[email protected]
[email protected].0
minimongo@1.8.0
[email protected].1
minimongo@1.9.0
[email protected]
modules@0.18.0
modules@0.19.0
[email protected]
mongo@1.15.0
mongo@1.16.0
[email protected]
[email protected]
[email protected]
npm-mongo@4.3.1
npm-mongo@4.9.0
[email protected]
ostrio:[email protected]
ostrio:[email protected].0
ostrio:[email protected].1
[email protected]
[email protected]
[email protected]
Expand Down
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'ostrio:files',
version: '2.3.0',
version: '2.3.1',
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'
Expand Down
21 changes: 12 additions & 9 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ const noop = function noop () {};
* @param {object} opts - Set of options that controls the creation of the index
* @returns {void 0}
*/
const createIndex = async (collection, keys, opts) => {
const createIndex = async (_collection, keys, opts) => {
const collection = _collection.rawCollection();

try {
await collection.rawCollection().createIndex(keys, opts);
await collection.createIndex(keys, opts);
} catch (e) {
if (e.code === 85) {
let indexName;
const indexes = await collection.rawCollection().indexes();
const indexes = await collection.indexes();
for (const index of indexes) {
let allMatch = true;
for (const indexKey of Object.keys(keys)) {
Expand All @@ -60,11 +62,11 @@ const createIndex = async (collection, keys, opts) => {
}

if (indexName) {
await collection.rawCollection().dropIndex(indexName);
await collection.rawCollection().createIndex(keys, opts);
await collection.dropIndex(indexName);
await collection.createIndex(keys, opts);
}
} else {
Meteor._debug(`Can not set ${Object.keys(keys).join(' + ')} index on "${collection._name}" collection`, { keys, opts, details: e });
Meteor._debug(`Can not set ${Object.keys(keys).join(' + ')} index on "${_collection._name}" collection`, { keys, opts, details: e });
}
}
};
Expand Down Expand Up @@ -274,7 +276,7 @@ class FilesCollection extends FilesCollectionCore {
this.disableDownload = false;
}

if (!helpers.isBoolean(this.allowedOrigins) || this.allowedOrigins === true) {
if (this.allowedOrigins === true || this.allowedOrigins === void 0) {
this.allowedOrigins = /^http:\/\/localhost:12[0-9]{3}$/;
}

Expand Down Expand Up @@ -370,6 +372,7 @@ class FilesCollection extends FilesCollectionCore {
check(this.interceptDownload, Match.OneOf(false, Function));
check(this.continueUploadTTL, Number);
check(this.responseHeaders, Match.OneOf(Object, Function));
check(this.allowedOrigins, Match.OneOf(Boolean, RegExp));
check(this.allowQueryStringCookies, Boolean);

this._cookies = new Cookies({
Expand Down Expand Up @@ -1734,9 +1737,9 @@ class FilesCollection extends FilesCollectionCore {
http.response.writeHead(404, {
'Content-Type': 'text/plain',
'Content-Length': text.length
}
);
});
}

if (!http.response.finished) {
http.response.end(text);
}
Expand Down
15 changes: 12 additions & 3 deletions write-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,24 @@ export default class WriteStream {
if (statError || !stats.isFile()) {
const paths = this.path.split('/');
paths.pop();
fs.mkdirSync(paths.join('/'), { recursive: true });
fs.writeFileSync(this.path, '');
try {
fs.mkdirSync(paths.join('/'), { recursive: true });
} catch (mkdirError) {
throw new Meteor.Error(500, `[FilesCollection] [writeStream] [constructor] [mkdirSync] ERROR: can not make/ensure directory ${paths.join('/')}`, mkdirError);
}

try {
fs.writeFileSync(this.path, '');
} catch (writeFileError) {
throw new Meteor.Error(500, `[FilesCollection] [writeStream] [constructor] [writeFileSync] ERROR: can not write file ${this.path}`, writeFileError);
}
}

fs.open(this.path, 'r+', this.permissions, (oError, fd) => {
bound(() => {
if (oError) {
this.abort();
throw new Meteor.Error(500, '[FilesCollection] [writeStream] [ensureFile] [open] [Error:]', oError);
throw new Meteor.Error(500, '[FilesCollection] [writeStream] [constructor] [open] [Error:]', oError);
} else {
this.fd = fd;
fdCache[this.path] = this;
Expand Down

0 comments on commit 7d4796e

Please sign in to comment.