Skip to content

Commit

Permalink
Fixing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
travist committed Oct 16, 2023
1 parent afad846 commit 259b165
Showing 1 changed file with 93 additions and 112 deletions.
205 changes: 93 additions & 112 deletions src/Formio.js
Original file line number Diff line number Diff line change
@@ -1,125 +1,106 @@
import { Formio as CoreFormio } from '@formio/core/sdk';
import { Formio } from '@formio/core/sdk';
import { Formio as FormioEmbed } from './Embed';
import CDN from './CDN';
import Providers from './providers';
Formio.cdn = new CDN();
Formio.Providers = Providers;
Formio.version = 'FORMIO_VERSION';

const isNil = (val) => val === null || val === undefined;
Formio.prototype.uploadFile = function(storage, file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, uploadStartCallback, abortCallback, multipartOptions) {
const requestArgs = {
provider: storage,
method: 'upload',
file: file,
fileName: fileName,
dir: dir
};
fileKey = fileKey || 'file';
const request = Formio.pluginWait('preRequest', requestArgs)
.then(() => {
return Formio.pluginGet('fileRequest', requestArgs)
.then((result) => {
if (storage && isNil(result)) {
const Provider = Providers.getProvider('storage', storage);
if (Provider) {
const provider = new Provider(this);
if (uploadStartCallback) {
uploadStartCallback();
}
return provider.uploadFile(file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, abortCallback, multipartOptions);
}
else {
throw ('Storage provider not found');
}
}
return result || { url: '' };
});
});

export class Formio extends CoreFormio {
static cdn = new CDN();
static Providers = Providers;
static version = 'FORMIO_VERSION';
static Promise = Promise;
static formioReady = FormioEmbed.formioReady;
static config = FormioEmbed.config;
static builder = FormioEmbed.builder;
static Form = FormioEmbed.Form;
static FormBuilder = FormioEmbed.FormBuilder;
static use = FormioEmbed.use;
static createForm = FormioEmbed.createForm;
static setBaseUrl(url) {
CoreFormio.setBaseUrl(url);
FormioEmbed.setBaseUrl(url, true);
}
return Formio.pluginAlter('wrapFileRequestPromise', request, requestArgs);
};

static setApiUrl(url) {
CoreFormio.setApiUrl(url);
FormioEmbed.setApiUrl(url, true);
}
Formio.prototype.downloadFile = function(file, options) {
const requestArgs = {
method: 'download',
file: file
};

static setAppUrl(url) {
CoreFormio.setAppUrl(url);
FormioEmbed.setAppUrl(url, true);
}
const request = Formio.pluginWait('preRequest', requestArgs)
.then(() => {
return Formio.pluginGet('fileRequest', requestArgs)
.then((result) => {
if (file.storage && isNil(result)) {
const Provider = Providers.getProvider('storage', file.storage);
if (Provider) {
const provider = new Provider(this);
return provider.downloadFile(file, options);
}
else {
throw ('Storage provider not found');
}
}
return result || { url: '' };
});
});

static setProjectUrl(url) {
CoreFormio.setProjectUrl(url);
FormioEmbed.setProjectUrl(url, true);
}
return Formio.pluginAlter('wrapFileRequestPromise', request, requestArgs);
};

static setPathType(type) {
CoreFormio.setPathType(type);
FormioEmbed.setPathType(type, true);
}
Formio.prototype.deleteFile = function(file, options) {
const requestArgs = {
method: 'delete',
file: file
};

uploadFile(storage, file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, uploadStartCallback, abortCallback) {
const requestArgs = {
provider: storage,
method: 'upload',
file: file,
fileName: fileName,
dir: dir
};
fileKey = fileKey || 'file';
const request = Formio.pluginWait('preRequest', requestArgs)
.then(() => {
return Formio.pluginGet('fileRequest', requestArgs)
.then((result) => {
if (storage && isNil(result)) {
const Provider = Providers.getProvider('storage', storage);
if (Provider) {
const provider = new Provider(this);
if (uploadStartCallback) {
uploadStartCallback();
}
return provider.uploadFile(file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, abortCallback);
}
else {
throw ('Storage provider not found');
}
const request = Formio.pluginWait('preRequest', requestArgs)
.then(() => {
return Formio.pluginGet('fileRequest', requestArgs)
.then((result) => {
if (file.storage && isNil(result)) {
const Provider = Providers.getProvider('storage', file.storage);
if (Provider) {
const provider = new Provider(this);
return provider.deleteFile(file, options);
}
return result || { url: '' };
});
});
return Formio.pluginAlter('wrapFileRequestPromise', request, requestArgs);
}

downloadFile(file, options) {
const requestArgs = {
method: 'download',
file: file
};
const request = Formio.pluginWait('preRequest', requestArgs)
.then(() => {
return Formio.pluginGet('fileRequest', requestArgs)
.then((result) => {
if (file.storage && isNil(result)) {
const Provider = Providers.getProvider('storage', file.storage);
if (Provider) {
const provider = new Provider(this);
return provider.downloadFile(file, options);
}
else {
throw ('Storage provider not found');
}
else {
throw ('Storage provider not found');
}
return result || { url: '' };
});
});
return Formio.pluginAlter('wrapFileRequestPromise', request, requestArgs);
}
}
return result || { url: '' };
});
});

deleteFile(file, options) {
const requestArgs = {
method: 'delete',
file: file
};
const request = Formio.pluginWait('preRequest', requestArgs)
.then(() => {
return Formio.pluginGet('fileRequest', requestArgs)
.then((result) => {
if (file.storage && isNil(result)) {
const Provider = Providers.getProvider('storage', file.storage);
if (Provider) {
const provider = new Provider(this);
return provider.deleteFile(file, options);
}
else {
throw ('Storage provider not found');
}
}
return result || { url: '' };
});
});
return Formio.pluginAlter('wrapFileRequestPromise', request, requestArgs);
}
}
return Formio.pluginAlter('wrapFileRequestPromise', request, requestArgs);
};

// For reverse compatability.
Formio.Promise = Promise;
Formio.formioReady = FormioEmbed.formioReady;
Formio.config = FormioEmbed.config;
Formio.builder = FormioEmbed.builder;
Formio.Form = FormioEmbed.Form;
Formio.FormBuilder = FormioEmbed.FormBuilder;
Formio.use = FormioEmbed.use;
Formio.createForm = FormioEmbed.createForm;
export { Formio };

0 comments on commit 259b165

Please sign in to comment.