MCPcopy
hub / github.com/pqina/filepond / createRevertFunction

Function createRevertFunction

src/js/app/utils/createRevertFunction.js:10–58  ·  view source on GitHub ↗
(apiUrl = '', action)

Source from the content-addressed store, hash-verified

8 (uniqueFileId, load, error) => { }
9 */
10export const createRevertFunction = (apiUrl = '', action) => {
11 // is custom implementation
12 if (typeof action === 'function') {
13 return action;
14 }
15
16 // no action supplied, return stub function, interface will work, but file won't be removed
17 if (!action || !isString(action.url)) {
18 return (uniqueFileId, load) => load();
19 }
20
21 // set onload hanlder
22 const onload = action.onload || (res => res);
23 const onerror = action.onerror || (res => null);
24
25 // internal implementation
26 return (uniqueFileId, load, error) => {
27 const request = sendRequest(
28 uniqueFileId,
29 apiUrl + action.url,
30 action // contains method, headers and withCredentials properties
31 );
32 request.onload = (xhr) => {
33 load(
34 createResponse(
35 'load',
36 xhr.status,
37 onload(xhr.response),
38 xhr.getAllResponseHeaders()
39 )
40 )
41 };
42
43 request.onerror = (xhr) => {
44 error(
45 createResponse(
46 'error',
47 xhr.status,
48 onerror(xhr.response) || xhr.statusText,
49 xhr.getAllResponseHeaders()
50 )
51 );
52 };
53
54 request.ontimeout = createTimeoutResponse(error);
55
56 return request;
57 };
58};

Callers 2

revertFunction · 0.90
actionsFunction · 0.90

Calls 6

isStringFunction · 0.90
sendRequestFunction · 0.90
createResponseFunction · 0.90
createTimeoutResponseFunction · 0.90
loadFunction · 0.70
errorFunction · 0.70

Tested by

no test coverage detected