mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 22:50:53 +00:00
[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}}
|
||||
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) {
|
||||
// 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
|
||||
if (typeof Buffer === 'function' && param instanceof Buffer) {
|
||||
|
@ -168,13 +168,16 @@
|
||||
* @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) {
|
||||
// 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) {
|
||||
return true;
|
||||
|
@ -174,13 +174,16 @@
|
||||
* @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) {
|
||||
// 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) {
|
||||
return true;
|
||||
|
@ -174,13 +174,16 @@
|
||||
* @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) {
|
||||
// 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) {
|
||||
return true;
|
||||
|
@ -174,13 +174,16 @@
|
||||
* @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) {
|
||||
// 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) {
|
||||
return true;
|
||||
|
@ -174,13 +174,16 @@
|
||||
* @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) {
|
||||
// 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) {
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user