Skip to content

Commit a8b4547

Browse files
committed
Rebuild assets
1 parent 135077d commit a8b4547

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/LiveComponent/assets/dist/Backend/Backend.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export interface BackendInterface {
1010
[key: string]: any;
1111
}, children: ChildrenFingerprints, updatedPropsFromParent: {
1212
[key: string]: any;
13+
}, files: {
14+
[key: string]: FileList;
1315
}): BackendRequest;
1416
}
1517
export interface BackendAction {
@@ -23,5 +25,7 @@ export default class implements BackendInterface {
2325
[key: string]: any;
2426
}, children: ChildrenFingerprints, updatedPropsFromParent: {
2527
[key: string]: any;
28+
}, files: {
29+
[key: string]: FileList;
2630
}): BackendRequest;
2731
}

src/LiveComponent/assets/dist/Backend/RequestBuilder.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export default class {
77
[key: string]: any;
88
}, children: ChildrenFingerprints, updatedPropsFromParent: {
99
[key: string]: any;
10+
}, files: {
11+
[key: string]: FileList;
1012
}): {
1113
url: string;
1214
fetchOptions: RequestInit;

src/LiveComponent/assets/dist/live_controller.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,7 @@ class Component {
18991899
const thisPromiseResolve = this.nextRequestPromiseResolve;
19001900
this.resetPromise();
19011901
this.unsyncedInputsTracker.resetUnsyncedFields();
1902-
this.backendRequest = this.backend.makeRequest(this.valueStore.getOriginalProps(), this.pendingActions, this.valueStore.getDirtyProps(), this.getChildrenFingerprints(), this.valueStore.getUpdatedPropsFromParent());
1902+
this.backendRequest = this.backend.makeRequest(this.valueStore.getOriginalProps(), this.pendingActions, this.valueStore.getDirtyProps(), this.getChildrenFingerprints(), this.valueStore.getUpdatedPropsFromParent(), {});
19031903
this.hooks.triggerHook('loading.state:started', this.element, this.backendRequest);
19041904
this.pendingActions = [];
19051905
this.valueStore.flushDirtyPropsToPending();
@@ -2129,7 +2129,7 @@ class RequestBuilder {
21292129
this.url = url;
21302130
this.csrfToken = csrfToken;
21312131
}
2132-
buildRequest(props, actions, updated, children, updatedPropsFromParent) {
2132+
buildRequest(props, actions, updated, children, updatedPropsFromParent, files) {
21332133
const splitUrl = this.url.split('?');
21342134
let [url] = splitUrl;
21352135
const [, queryString] = splitUrl;
@@ -2138,8 +2138,10 @@ class RequestBuilder {
21382138
fetchOptions.headers = {
21392139
Accept: 'application/vnd.live-component+html',
21402140
};
2141+
const totalFiles = Object.entries(files).reduce((total, current) => total + current.length, 0);
21412142
const hasFingerprints = Object.keys(children).length > 0;
21422143
if (actions.length === 0 &&
2144+
totalFiles === 0 &&
21432145
this.willDataFitInUrl(JSON.stringify(props), JSON.stringify(updated), params, JSON.stringify(children), JSON.stringify(updatedPropsFromParent))) {
21442146
params.set('props', JSON.stringify(props));
21452147
params.set('updated', JSON.stringify(updated));
@@ -2153,18 +2155,18 @@ class RequestBuilder {
21532155
}
21542156
else {
21552157
fetchOptions.method = 'POST';
2156-
fetchOptions.headers['Content-Type'] = 'application/json';
21572158
const requestData = { props, updated };
21582159
if (Object.keys(updatedPropsFromParent).length > 0) {
21592160
requestData.propsFromParent = updatedPropsFromParent;
21602161
}
21612162
if (hasFingerprints) {
21622163
requestData.children = children;
21632164
}
2165+
if (this.csrfToken &&
2166+
(actions.length || totalFiles)) {
2167+
fetchOptions.headers['X-CSRF-TOKEN'] = this.csrfToken;
2168+
}
21642169
if (actions.length > 0) {
2165-
if (this.csrfToken) {
2166-
fetchOptions.headers['X-CSRF-TOKEN'] = this.csrfToken;
2167-
}
21682170
if (actions.length === 1) {
21692171
requestData.args = actions[0].args;
21702172
url += `/${encodeURIComponent(actions[0].name)}`;
@@ -2174,7 +2176,15 @@ class RequestBuilder {
21742176
requestData.actions = actions;
21752177
}
21762178
}
2177-
fetchOptions.body = JSON.stringify(requestData);
2179+
const formData = new FormData();
2180+
formData.append('data', JSON.stringify(requestData));
2181+
for (const [key, value] of Object.entries(files)) {
2182+
const length = value.length;
2183+
for (let i = 0; i < length; ++i) {
2184+
formData.append(key, value[i]);
2185+
}
2186+
}
2187+
fetchOptions.body = formData;
21782188
}
21792189
const paramsString = params.toString();
21802190
return {
@@ -2192,8 +2202,8 @@ class Backend {
21922202
constructor(url, csrfToken = null) {
21932203
this.requestBuilder = new RequestBuilder(url, csrfToken);
21942204
}
2195-
makeRequest(props, actions, updated, children, updatedPropsFromParent) {
2196-
const { url, fetchOptions } = this.requestBuilder.buildRequest(props, actions, updated, children, updatedPropsFromParent);
2205+
makeRequest(props, actions, updated, children, updatedPropsFromParent, files) {
2206+
const { url, fetchOptions } = this.requestBuilder.buildRequest(props, actions, updated, children, updatedPropsFromParent, files);
21972207
return new BackendRequest(fetch(url, fetchOptions), actions.map((backendAction) => backendAction.name), Object.keys(updated));
21982208
}
21992209
}

0 commit comments

Comments
 (0)