forked from loafle/openapi-generator-original
[javascript] Fixed fs
files support for Electron (#5765)
This commit is contained in:
parent
6239ec0807
commit
6a986975e4
@ -160,10 +160,16 @@ export default class ApiClient {
|
|||||||
*/
|
*/
|
||||||
{{/emitJSDoc}}
|
{{/emitJSDoc}}
|
||||||
isFileParam(param) {
|
isFileParam(param) {
|
||||||
// fs.ReadStream in Node.js (but not in runtime like browserify)
|
// fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
|
||||||
if (typeof window === 'undefined' && typeof require === 'function' && require('fs') && param instanceof require('fs').ReadStream) {
|
if (typeof require === 'function') {
|
||||||
|
let fs;
|
||||||
|
try {
|
||||||
|
fs = require('fs');
|
||||||
|
} catch (err) {}
|
||||||
|
if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Buffer in Node.js
|
// Buffer in Node.js
|
||||||
if (typeof Buffer === 'function' && param instanceof Buffer) {
|
if (typeof Buffer === 'function' && param instanceof Buffer) {
|
||||||
|
@ -168,13 +168,16 @@
|
|||||||
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
|
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
|
||||||
*/
|
*/
|
||||||
{{/emitJSDoc}} exports.prototype.isFileParam = function(param) {
|
{{/emitJSDoc}} exports.prototype.isFileParam = function(param) {
|
||||||
// fs.ReadStream in Node.js (but not in runtime like browserify)
|
// fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
|
||||||
if (typeof window === 'undefined' &&
|
if (typeof require === 'function') {
|
||||||
typeof require === 'function' &&
|
var fs;
|
||||||
require('fs') &&
|
try {
|
||||||
param instanceof require('fs').ReadStream) {
|
fs = require('fs');
|
||||||
|
} catch (err) {}
|
||||||
|
if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Buffer in Node.js
|
// Buffer in Node.js
|
||||||
if (typeof Buffer === 'function' && param instanceof Buffer) {
|
if (typeof Buffer === 'function' && param instanceof Buffer) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -174,13 +174,16 @@
|
|||||||
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
|
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
|
||||||
*/
|
*/
|
||||||
exports.prototype.isFileParam = function(param) {
|
exports.prototype.isFileParam = function(param) {
|
||||||
// fs.ReadStream in Node.js (but not in runtime like browserify)
|
// fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
|
||||||
if (typeof window === 'undefined' &&
|
if (typeof require === 'function') {
|
||||||
typeof require === 'function' &&
|
var fs;
|
||||||
require('fs') &&
|
try {
|
||||||
param instanceof require('fs').ReadStream) {
|
fs = require('fs');
|
||||||
|
} catch (err) {}
|
||||||
|
if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Buffer in Node.js
|
// Buffer in Node.js
|
||||||
if (typeof Buffer === 'function' && param instanceof Buffer) {
|
if (typeof Buffer === 'function' && param instanceof Buffer) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -174,13 +174,16 @@
|
|||||||
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
|
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
|
||||||
*/
|
*/
|
||||||
exports.prototype.isFileParam = function(param) {
|
exports.prototype.isFileParam = function(param) {
|
||||||
// fs.ReadStream in Node.js (but not in runtime like browserify)
|
// fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
|
||||||
if (typeof window === 'undefined' &&
|
if (typeof require === 'function') {
|
||||||
typeof require === 'function' &&
|
var fs;
|
||||||
require('fs') &&
|
try {
|
||||||
param instanceof require('fs').ReadStream) {
|
fs = require('fs');
|
||||||
|
} catch (err) {}
|
||||||
|
if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Buffer in Node.js
|
// Buffer in Node.js
|
||||||
if (typeof Buffer === 'function' && param instanceof Buffer) {
|
if (typeof Buffer === 'function' && param instanceof Buffer) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -174,13 +174,16 @@
|
|||||||
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
|
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
|
||||||
*/
|
*/
|
||||||
exports.prototype.isFileParam = function(param) {
|
exports.prototype.isFileParam = function(param) {
|
||||||
// fs.ReadStream in Node.js (but not in runtime like browserify)
|
// fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
|
||||||
if (typeof window === 'undefined' &&
|
if (typeof require === 'function') {
|
||||||
typeof require === 'function' &&
|
var fs;
|
||||||
require('fs') &&
|
try {
|
||||||
param instanceof require('fs').ReadStream) {
|
fs = require('fs');
|
||||||
|
} catch (err) {}
|
||||||
|
if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Buffer in Node.js
|
// Buffer in Node.js
|
||||||
if (typeof Buffer === 'function' && param instanceof Buffer) {
|
if (typeof Buffer === 'function' && param instanceof Buffer) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -174,13 +174,16 @@
|
|||||||
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
|
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
|
||||||
*/
|
*/
|
||||||
exports.prototype.isFileParam = function(param) {
|
exports.prototype.isFileParam = function(param) {
|
||||||
// fs.ReadStream in Node.js (but not in runtime like browserify)
|
// fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
|
||||||
if (typeof window === 'undefined' &&
|
if (typeof require === 'function') {
|
||||||
typeof require === 'function' &&
|
var fs;
|
||||||
require('fs') &&
|
try {
|
||||||
param instanceof require('fs').ReadStream) {
|
fs = require('fs');
|
||||||
|
} catch (err) {}
|
||||||
|
if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Buffer in Node.js
|
// Buffer in Node.js
|
||||||
if (typeof Buffer === 'function' && param instanceof Buffer) {
|
if (typeof Buffer === 'function' && param instanceof Buffer) {
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user