Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #284 newly introduced Blob in nodejs not compatible with BlobClient #309

Merged
merged 14 commits into from
Apr 7, 2023
15 changes: 9 additions & 6 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ jobs:
name: testing
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: [16.x, 18.x]
node: [16, 18]
mongodb-version: [4.4]
python-version: [3.8]
redis-version: [6]

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: true
- name: Use Node.js {{ matrix.node-version }}
uses: actions/setup-node@v2
- name: Use Node.js {{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- uses: actions/setup-python@v2
node-version: ${{ matrix.node }}
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Start MongoDB ${{ matrix.mongodb-version }}
Expand All @@ -38,6 +39,8 @@ jobs:
redis-version: ${{ matrix.redis-version }}
- name: Chrome
uses: browser-actions/setup-chrome@latest
- name: node version
run: node --version
- name: NPM install
run: npm install
- name: ESLint Check
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://opensource.org/licenses/MIT)
[![Build Status](https://travis-ci.org/webgme/webgme-engine.svg?branch=master)](https://travis-ci.org/webgme/webgme-engine)
[![Build status](https://img.shields.io/github/actions/workflow/status/webgme/webgme-engine/ci.yml?branch=master&label=CI&logo=github&style=flat-square)](https://github.com/webgme/webgme-engine/actions/workflows/ci.yml)
[![Version](https://badge.fury.io/js/webgme-engine.svg)](https://www.npmjs.com/package/webgme-engine)
[![Downloads](http://img.shields.io/npm/dm/webgme-engine.svg?style=flat)](http://img.shields.io/npm/dm/webgme-engine.svg?style=flat)

Expand Down
6 changes: 4 additions & 2 deletions src/common/blob/BlobClient.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*globals define, Uint8Array, ArrayBuffer, WebGMEGlobal*/
/*eslint-env node, browser*/

/**
* Client module for accessing the blob.
*
Expand Down Expand Up @@ -280,7 +279,10 @@ define([
req;
// FIXME: in production mode do not indent the json file.
this.logger.debug('putMetadata', {metadata: metadataDescriptor});
if (typeof Blob !== 'undefined') {
if (typeof Blob !== 'undefined' && typeof window !== 'undefined') {
// This does not work using the "new" Blob class in nodejs - so make sure (for now at least) that
// we running under a brower even though Blob is defined.
// https://nodejs.org/api/buffer.html#class-blob
blob = new Blob([JSON.stringify(metadata.serialize(), null, 4)], {type: 'text/plain'});
contentLength = blob.size;
} else {
Expand Down
1 change: 0 additions & 1 deletion src/server/middleware/blob/BlobServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ function createExpressBlob(options) {
});

__app.post('/createMetadata', ensureAuthenticated, function (req, res) {

var data = '';

req.addListener('data', function (chunk) {
Expand Down
1 change: 1 addition & 0 deletions test/common/blob/Artifact.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ describe('Blob Artifact', function () {
'a.txt': 'tttt'
},
artifact = new Artifact('testartifact', bc);

bc.putFiles(filesToAdd, function (err, objHashes) {
if (err) {
done(err);
Expand Down
4 changes: 2 additions & 2 deletions test/common/blob/BlobClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,12 @@ describe('BlobClient', function () {
artifact = new BlobClient(bcParam).createArtifact('xmlAndJson');
artifact.addFiles(filesToAdd, function (err/*, hashes*/) {
if (err) {
done('Could not add files : err' + err.toString());
done(new Error('Could not add files : err' + err.toString()));
return;
}
artifact.save(function (err, hash) {
if (err) {
done('Could not save artifact : err' + err.toString());
done(new Error('Could not save artifact : err' + err.toString()));
return;
}
var agent = superagent.agent();
Expand Down