Skip to content

Commit

Permalink
[javascript] Fixed fs files support for Electron
Browse files Browse the repository at this point in the history
  • Loading branch information
frol committed Jun 2, 2017
1 parent 034fc44 commit 85aef6d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,15 @@ export default class ApiClient {
*/
{{/emitJSDoc}}
isFileParam(param) {
// fs.ReadStream in Node.js (but not in runtime like browserify)
if (typeof window === 'undefined' && typeof require === 'function' && require('fs') && param instanceof require('fs').ReadStream) {
return true;
// fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
if (typeof require === 'function') {
let fs
try {
fs = require('fs')
} catch (err) {}
if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
return true;
}
}

// Buffer in Node.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,15 @@
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
*/
{{/emitJSDoc}} exports.prototype.isFileParam = function(param) {
// fs.ReadStream in Node.js (but not in runtime like browserify)
if (typeof window === 'undefined' &&
typeof require === 'function' &&
require('fs') &&
param instanceof require('fs').ReadStream) {
return true;
// fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
if (typeof require === 'function') {
var fs
try {
fs = require('fs')
} catch (err) {}
if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
return true;
}
}
// Buffer in Node.js
if (typeof Buffer === 'function' && param instanceof Buffer) {
Expand Down
15 changes: 9 additions & 6 deletions samples/client/petstore/javascript-es6/src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,15 @@
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
*/
exports.prototype.isFileParam = function(param) {
// fs.ReadStream in Node.js (but not in runtime like browserify)
if (typeof window === 'undefined' &&
typeof require === 'function' &&
require('fs') &&
param instanceof require('fs').ReadStream) {
return true;
// fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
if (typeof require === 'function') {
var fs
try {
fs = require('fs')
} catch (err) {}
if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
return true;
}
}
// Buffer in Node.js
if (typeof Buffer === 'function' && param instanceof Buffer) {
Expand Down
15 changes: 9 additions & 6 deletions samples/client/petstore/javascript-promise-es6/src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,15 @@
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
*/
exports.prototype.isFileParam = function(param) {
// fs.ReadStream in Node.js (but not in runtime like browserify)
if (typeof window === 'undefined' &&
typeof require === 'function' &&
require('fs') &&
param instanceof require('fs').ReadStream) {
return true;
// fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
if (typeof require === 'function') {
var fs
try {
fs = require('fs')
} catch (err) {}
if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
return true;
}
}
// Buffer in Node.js
if (typeof Buffer === 'function' && param instanceof Buffer) {
Expand Down
15 changes: 9 additions & 6 deletions samples/client/petstore/javascript-promise/src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,15 @@
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
*/
exports.prototype.isFileParam = function(param) {
// fs.ReadStream in Node.js (but not in runtime like browserify)
if (typeof window === 'undefined' &&
typeof require === 'function' &&
require('fs') &&
param instanceof require('fs').ReadStream) {
return true;
// fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
if (typeof require === 'function') {
var fs
try {
fs = require('fs')
} catch (err) {}
if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
return true;
}
}
// Buffer in Node.js
if (typeof Buffer === 'function' && param instanceof Buffer) {
Expand Down
15 changes: 9 additions & 6 deletions samples/client/petstore/javascript/src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,15 @@
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
*/
exports.prototype.isFileParam = function(param) {
// fs.ReadStream in Node.js (but not in runtime like browserify)
if (typeof window === 'undefined' &&
typeof require === 'function' &&
require('fs') &&
param instanceof require('fs').ReadStream) {
return true;
// fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
if (typeof require === 'function') {
var fs
try {
fs = require('fs')
} catch (err) {}
if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
return true;
}
}
// Buffer in Node.js
if (typeof Buffer === 'function' && param instanceof Buffer) {
Expand Down

0 comments on commit 85aef6d

Please sign in to comment.