|
1 | 1 | import * as types from '../constants/ActionTypes'; |
2 | 2 |
|
| 3 | +const obfuscationWorker = new Worker('../workers/obfuscation-worker.js'); |
| 4 | + |
3 | 5 | export const updateCode = (code) => ({ |
4 | 6 | 'type': types.UPDATE_CODE, |
5 | 7 | code |
6 | 8 | }); |
7 | 9 |
|
8 | 10 | export const obfuscateCode = (code, options) => { |
9 | | - |
10 | | - const body = { |
11 | | - code, |
12 | | - options |
| 11 | + return (dispatch) => { |
| 12 | + const message = { |
| 13 | + code, |
| 14 | + options |
| 15 | + }; |
| 16 | + |
| 17 | + if (!options.sourceMap) { |
| 18 | + delete options.sourceMapMode |
| 19 | + } |
| 20 | + |
| 21 | + // options.stringArrayEncoding come from the client as strings, but the |
| 22 | + // obfuscator expects it to be a boolean or a string if 'base64'/'rc4' |
| 23 | + if (['false', 'true'].indexOf(options.stringArrayEncoding) !== -1) { |
| 24 | + options.stringArrayEncoding = options.stringArrayEncoding === 'true'; |
| 25 | + } |
| 26 | + |
| 27 | + obfuscationWorker.postMessage(message); |
| 28 | + |
| 29 | + dispatch({ |
| 30 | + type: types.OBFUSCATE, |
| 31 | + payload: new Promise((resolve) => { |
| 32 | + obfuscationWorker.onmessage = function (event) { |
| 33 | + const result = JSON.parse(event.data); |
| 34 | + |
| 35 | + resolve(result); |
| 36 | + }; |
| 37 | + }), |
| 38 | + }); |
| 39 | + |
| 40 | + /** |
| 41 | + const request = new Request('/obfuscate', { |
| 42 | + method: 'POST', |
| 43 | + credentials: 'same-origin', |
| 44 | + headers: { |
| 45 | + 'Accept': 'application/json', |
| 46 | + 'Content-Type': 'application/json' |
| 47 | + }, |
| 48 | + body: JSON.stringify(body), |
| 49 | + }); |
| 50 | +
|
| 51 | + return { |
| 52 | + type: types.OBFUSCATE, |
| 53 | + payload: fetch(request).then((response) => response.json()), |
| 54 | + } |
| 55 | + */ |
13 | 56 | }; |
14 | | - |
15 | | - const request = new Request('/obfuscate', { |
16 | | - method: 'POST', |
17 | | - credentials: 'same-origin', |
18 | | - headers: { |
19 | | - 'Accept': 'application/json', |
20 | | - 'Content-Type': 'application/json' |
21 | | - }, |
22 | | - body: JSON.stringify(body), |
23 | | - }); |
24 | | - |
25 | | - return { |
26 | | - type: types.OBFUSCATE, |
27 | | - payload: fetch(request).then((response) => response.json()), |
28 | | - } |
29 | | - |
30 | 57 | }; |
31 | 58 |
|
32 | 59 | export const toggleOption = (optionType) => ({ |
|
0 commit comments