Skip to content

Commit

Permalink
Merge branch 'master' into feature/files-synchronization-5x
Browse files Browse the repository at this point in the history
  • Loading branch information
roma-formio committed Oct 24, 2023
2 parents 022a3d2 + 8fdc035 commit 877b2c7
Show file tree
Hide file tree
Showing 12 changed files with 404 additions and 160 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- FIO-6370: Fixes issues with PasswordStrength Addon settings
- FIO-7146: formiojs-circleci-to-ghactions
- FIO-6859: update-s3-to-accept-headers-from-signer-presign
- FIO 7239: support for AWS S3 Multipart Upload
- FIO-7239: add polyfill and include token in abort and complete requests for multipart upload

## 5.0.0-rc.26
### Changed
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"@formio/core": "1.3.0-rc.16",
"@formio/text-mask-addons": "^3.8.0-formio.2",
"@formio/vanilla-text-mask": "^5.1.1-formio.1",
"abortcontroller-polyfill": "^1.7.5",
"autocompleter": "^8.0.4",
"bootstrap": "^5.3.0",
"browser-cookies": "^1.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/Formio.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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) {
Formio.prototype.uploadFile = function(storage, file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, uploadStartCallback, abortCallback, multipartOptions) {
const requestArgs = {
provider: storage,
method: 'upload',
Expand All @@ -26,7 +26,7 @@ Formio.prototype.uploadFile = function(storage, file, fileName, dir, progressCal
if (uploadStartCallback) {
uploadStartCallback();
}
return provider.uploadFile(file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, abortCallback);
return provider.uploadFile(file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, abortCallback, multipartOptions);
}
else {
throw ('Storage provider not found');
Expand Down
25 changes: 11 additions & 14 deletions src/Wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -897,30 +897,27 @@ export default class Wizard extends Webform {
}

setValue(submission, flags = {}, ignoreEstablishment) {
const changed = this.getPages({ all: true }).reduce((changed, page) => {
return this.setNestedValue(page, submission.data, flags, changed) || changed;
}, false);

if (!flags.sanitize ||
this._submission = submission;
if (
(flags && flags.fromSubmission && (this.options.readOnly || this.editMode) && !this.isHtmlRenderMode()) ||
(flags && flags.fromSubmission && (this.prefixComps.length || this.suffixComps.length) && submission._id) ||
(this.options.server && (this.prefixComps.length || this.suffixComps.length))
) {
this.mergeData(this.data, submission.data);
this._data = submission.data;
}

if (!ignoreEstablishment) {
this.establishPages(submission.data);
}
const changed = this.getPages({ all: true }).reduce((changed, page) => {
return this.setNestedValue(page, submission.data, flags, changed) || changed;
}, false);

if (changed) {
this.pageFieldLogic(this.page);
}

this.setEditMode(submission);

submission.data = this.data;
this._submission = submission;

if (!ignoreEstablishment) {
this.establishPages(submission.data);
}

return changed;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Wizard.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('Wizard tests', () => {
}, 'Should contain correct submission data');

done();
}, 500);
}, 200);
}, 200);
}, 200);
}, 200);
Expand Down
40 changes: 40 additions & 0 deletions src/components/file/editForm/File.edit.file.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,46 @@ export default [
}
}
},
{
type: 'checkbox',
input: true,
key: 'useMultipartUpload',
label: 'Use the S3 Multipart Upload API',
tooltip: "The <a href='https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpuoverview.html'>S3 Multipart Upload API</a> is designed to improve the upload experience for larger objects (> 5GB).",
conditional: {
json: { '===': [{ var: 'data.storage' }, 's3'] }
},
},
{
label: 'Multipart Upload',
tableView: false,
key: 'multipart',
type: 'container',
input: true,
components: [
{
label: 'Part Size (MB)',
applyMaskOn: 'change',
mask: false,
tableView: false,
delimiter: false,
requireDecimal: false,
inputFormat: 'plain',
truncateMultipleSpaces: false,
validate: {
min: 5,
max: 5000,
},
key: 'partSize',
type: 'number',
input: true,
defaultValue: 500,
},
],
conditional: {
json: { '===': [{ var: 'data.useMultipartUpload' }, true] }
},
},
{
type: 'textfield',
input: true,
Expand Down
104 changes: 53 additions & 51 deletions src/providers/storage/dropbox.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,67 @@
import { setXhrHeaders } from './xhr';
const dropbox = (formio) => ({
uploadFile(file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, abortCallback) {
return new Promise(((resolve, reject) => {
// Send the file with data.
const xhr = new XMLHttpRequest();
function dropbox(formio) {
return {
uploadFile(file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, abortCallback) {
return new Promise(((resolve, reject) => {
// Send the file with data.
const xhr = new XMLHttpRequest();

if (typeof progressCallback === 'function') {
xhr.upload.onprogress = progressCallback;
}
if (typeof progressCallback === 'function') {
xhr.upload.onprogress = progressCallback;
}

if (typeof abortCallback === 'function') {
abortCallback(() => xhr.abort());
}
if (typeof abortCallback === 'function') {
abortCallback(() => xhr.abort());
}

const fd = new FormData();
fd.append('name', fileName);
fd.append('dir', dir);
fd.append('file', file);
const fd = new FormData();
fd.append('name', fileName);
fd.append('dir', dir);
fd.append('file', file);

// Fire on network error.
xhr.onerror = (err) => {
err.networkError = true;
reject(err);
};
// Fire on network error.
xhr.onerror = (err) => {
err.networkError = true;
reject(err);
};

xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) {
const response = JSON.parse(xhr.response);
response.storage = 'dropbox';
response.size = file.size;
response.type = file.type;
response.groupId = groupId;
response.groupPermissions = groupPermissions;
response.url = response.path_lower;
resolve(response);
}
else {
reject(xhr.response || 'Unable to upload file');
}
};
xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) {
const response = JSON.parse(xhr.response);
response.storage = 'dropbox';
response.size = file.size;
response.type = file.type;
response.groupId = groupId;
response.groupPermissions = groupPermissions;
response.url = response.path_lower;
resolve(response);
}
else {
reject(xhr.response || 'Unable to upload file');
}
};

xhr.onabort = reject;
xhr.onabort = reject;

xhr.open('POST', `${formio.formUrl}/storage/dropbox`);
xhr.open('POST', `${formio.formUrl}/storage/dropbox`);

setXhrHeaders(formio, xhr);
setXhrHeaders(formio, xhr);

const token = formio.getToken();
if (token) {
xhr.setRequestHeader('x-jwt-token', token);
}
xhr.send(fd);
}));
},
downloadFile(file) {
const token = formio.getToken();
if (token) {
xhr.setRequestHeader('x-jwt-token', token);
}
xhr.send(fd);
}));
},
downloadFile(file) {
const token = formio.getToken();
file.url =
`${formio.formUrl}/storage/dropbox?path_lower=${file.path_lower}${token ? `&x-jwt-token=${token}` : ''}`;
return Promise.resolve(file);
}
});
file.url =
`${formio.formUrl}/storage/dropbox?path_lower=${file.path_lower}${token ? `&x-jwt-token=${token}` : ''}`;
return Promise.resolve(file);
}
};
}

dropbox.title = 'Dropbox';
export default dropbox;
Loading

0 comments on commit 877b2c7

Please sign in to comment.