android: do not put js file directly
This commit is contained in:
parent
9c19a76cf8
commit
9a6ae9b6ef
@ -65,7 +65,7 @@ public class DoricSSRActivity extends AppCompatActivity {
|
||||
RootNode rootNode = new RootNode(doricContext);
|
||||
rootNode.setRootView(doricPanel);
|
||||
String filePath = getIntent().getStringExtra("file");
|
||||
String json = DoricUtils.readAssetFile("src/" + filePath);
|
||||
String json = DoricUtils.readAssetBinFile("src/" + filePath);
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
JSONObject jsonObject = new JSONObject(json);
|
||||
|
@ -63,11 +63,12 @@ import pub.doric.devkit.R;
|
||||
import pub.doric.devkit.qrcode.DisplayUtil;
|
||||
import pub.doric.devkit.qrcode.activity.CaptureActivity;
|
||||
import pub.doric.devkit.qrcode.activity.CodeUtils;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
|
||||
import static pub.doric.devkit.ui.DoricShowNodeTreeActivity.DORIC_CONTEXT_ID_KEY;
|
||||
|
||||
public class DoricDevActivity extends AppCompatActivity implements DoricDev.StatusCallback {
|
||||
private int REQUEST_CODE = 100;
|
||||
private final int REQUEST_CODE = 100;
|
||||
private ContextCellAdapter cellAdapter;
|
||||
|
||||
@Override
|
||||
@ -282,26 +283,6 @@ public class DoricDevActivity extends AppCompatActivity implements DoricDev.Stat
|
||||
}
|
||||
}
|
||||
|
||||
private static String toHex(byte[] bytes) {
|
||||
char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
char[] resultCharArray = new char[bytes.length * 2];
|
||||
int index = 0;
|
||||
for (byte b : bytes) {
|
||||
resultCharArray[index++] = hexDigits[b >>> 4 & 0xf];
|
||||
resultCharArray[index++] = hexDigits[b & 0xf];
|
||||
}
|
||||
return new String(resultCharArray);
|
||||
}
|
||||
|
||||
private static String md5(String s) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] bytes = md.digest(s.getBytes(Charset.forName("UTF-8")));
|
||||
return toHex(bytes);
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static class ContextCellAdapter extends RecyclerView.Adapter<ContextCellHolder> {
|
||||
private final ArrayList<DoricContext> contexts = new ArrayList<>();
|
||||
@ -360,11 +341,11 @@ public class DoricDevActivity extends AppCompatActivity implements DoricDev.Stat
|
||||
context.getSource()));
|
||||
String btnTitle = holder.itemView.getContext().getString(android.R.string.ok);
|
||||
builder.setMessage(
|
||||
String.format(Locale.getDefault(),
|
||||
"Size:%d\nMD5:%s\nScript:\n%s",
|
||||
context.getScript().length(),
|
||||
md5(context.getScript()),
|
||||
context.getScript()))
|
||||
String.format(Locale.getDefault(),
|
||||
"Size:%d\nMD5:%s\nScript:\n%s",
|
||||
context.getScript().length(),
|
||||
DoricUtils.md5(context.getScript()),
|
||||
context.getScript()))
|
||||
.setPositiveButton(btnTitle, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
@ -20,11 +20,6 @@ android {
|
||||
consumerProguardFiles 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
main {
|
||||
assets.srcDirs = ["../../doric-js/bundle"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -0,0 +1 @@
|
||||
蹬趕憤旬箕<EFBFBD><EFBFBD>隸<EFBFBD><EFBFBD>㫠癪葃<EFBFBD><EFBFBD>隸葔葔<EFBFBD><EFBFBD>䗩<EFBFBD><EFBFBD><EFBFBD>𡯁搌姘痀楸釓癪葔葃<EFBFBD><EFBFBD>𡚺<EFBFBD>癎<EFBFBD><EFBFBD>𣞼<EFBFBD>渘<EFBFBD><EFBFBD>𧟌<EFBFBD><EFBFBD><EFBFBD>隸葔譜<EFBFBD><EFBFBD>隸葔<EFBFBD><EFBFBD><EFBFBD>癪葔葃袜<EFBFBD><EFBFBD>孊楞眾岋<EFBFBD>隸葔譜<EFBFBD><EFBFBD>隸葔<EFBFBD><EFBFBD><EFBFBD>耂<EFBFBD><EFBFBD>蹟<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>蹟<EFBFBD><EFBFBD>瓚<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>湗謄<EFBFBD><EFBFBD><EFBFBD>夂癪葃<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>块<EFBFBD><EFBFBD>氵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>暕癪葔<EFBFBD><EFBFBD><EFBFBD><EFBFBD>鏋<EFBFBD>𨪚<EFBFBD><EFBFBD>鮍<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䬬劏<EFBFBD><EFBFBD><EFBFBD>𠵯<EFBFBD>癪葔葔<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>鮍<EFBFBD><EFBFBD><EFBFBD>葺<EFBFBD><EFBFBD><EFBFBD><EFBFBD>氺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>罒<EFBFBD><EFBFBD><EFBFBD><EFBFBD>秺癪葔葔<EFBFBD><EFBFBD><EFBFBD>鮍<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>𠾐軀<EFBFBD><EFBFBD>氵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>暊癪葔葔<EFBFBD><EFBFBD><EFBFBD>鮍<EFBFBD><EFBFBD><EFBFBD><EFBFBD>㑳軀<EFBFBD><EFBFBD><EFBFBD><EFBFBD>蘭葔葔葔<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>氺<EFBFBD>𨌘軀<EFBFBD><EFBFBD><EFBFBD>蘭葔葔葔<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>𥐙<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>𤣩蘭葔葔<EFBFBD>癪葔<EFBFBD><EFBFBD><EFBFBD><EFBFBD>鏋<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>罒<EFBFBD><EFBFBD><EFBFBD><EFBFBD>粘<EFBFBD>葔葔葔<EFBFBD><EFBFBD>耂<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>耂軀<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>嗻<EFBFBD>𥐙<EFBFBD><EFBFBD><EFBFBD><EFBFBD>秺癪葔葔<EFBFBD><EFBFBD><EFBFBD><EFBFBD>氺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>铁<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>鮍<EFBFBD><EFBFBD><EFBFBD>秺癪葔<EFBFBD>蘣葔葔<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>趼蘭葔譜<EFBFBD><EFBFBD><EFBFBD>隸譜<EFBFBD><EFBFBD>隸
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -263,7 +263,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
boolean legacy = DoricSingleton.getInstance().legacyMode;
|
||||
loadBuiltinJS(legacy ? DoricConstant.DORIC_BUNDLE_SANDBOX_ES5 : DoricConstant.DORIC_BUNDLE_SANDBOX);
|
||||
String libName = DoricConstant.DORIC_MODULE_LIB;
|
||||
String libJS = DoricUtils.readAssetFile(legacy ? DoricConstant.DORIC_BUNDLE_LIB_ES5 : DoricConstant.DORIC_BUNDLE_LIB);
|
||||
String libJS = DoricUtils.readAssetBinFile(legacy ? DoricConstant.DORIC_BUNDLE_LIB_ES5 : DoricConstant.DORIC_BUNDLE_LIB);
|
||||
mDoricJSE.loadJS(packageModuleScript(libName, libJS), "Module://" + libName);
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException(null, e);
|
||||
@ -283,7 +283,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
}
|
||||
|
||||
private void loadBuiltinJS(String assetName) {
|
||||
String script = DoricUtils.readAssetFile(assetName);
|
||||
String script = DoricUtils.readAssetBinFile(assetName);
|
||||
mDoricJSE.loadJS(script, "Assets://" + assetName);
|
||||
}
|
||||
|
||||
|
@ -279,7 +279,7 @@ public class DoricWebShellJSExecutor implements IDoricJSE {
|
||||
|
||||
@Override
|
||||
public WebResourceResponse onIntercept(String url) {
|
||||
String content = DoricUtils.readAssetFile("doric-web.html");
|
||||
String content = DoricUtils.readAssetBinFile("doric-web.html");
|
||||
InputStream inputStream = new ByteArrayInputStream(content.getBytes());
|
||||
return new WebResourceResponse("text/html", "utf-8", inputStream);
|
||||
}
|
||||
@ -292,7 +292,7 @@ public class DoricWebShellJSExecutor implements IDoricJSE {
|
||||
|
||||
@Override
|
||||
public WebResourceResponse onIntercept(String url) {
|
||||
String content = DoricUtils.readAssetFile("doric-web.js");
|
||||
String content = DoricUtils.readAssetBinFile("doric-web.js");
|
||||
InputStream inputStream = new ByteArrayInputStream(content.getBytes());
|
||||
return new WebResourceResponse("text/javascript", "utf-8", inputStream);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public class DoricWebViewJSEngine extends DoricJSEngine {
|
||||
protected void initJSEngine() {
|
||||
mDoricJSE = new DoricWebViewJSExecutor(Doric.application());
|
||||
String assetName = "doric-web.js";
|
||||
String script = DoricUtils.readAssetFile(assetName);
|
||||
String script = DoricUtils.readAssetBinFile(assetName);
|
||||
mDoricJSE.loadJS(script, "Assets://" + assetName);
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,8 @@ import java.io.InputStream;
|
||||
import java.lang.reflect.Array;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import pub.doric.Doric;
|
||||
|
||||
@ -63,6 +65,55 @@ import pub.doric.Doric;
|
||||
* @CreateDate: 2019-07-18
|
||||
*/
|
||||
public class DoricUtils {
|
||||
public static String readAssetBinFile(String assetFile) {
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
|
||||
AssetManager assetManager = Doric.application().getAssets();
|
||||
String md5Name = md5(assetFile);
|
||||
inputStream = assetManager.open(md5Name);
|
||||
int length = inputStream.available();
|
||||
byte[] buffer = new byte[length];
|
||||
inputStream.read(buffer);
|
||||
for (int i = 0; i < buffer.length; i++) {
|
||||
buffer[i] = (byte) (0xff - buffer[i]);
|
||||
}
|
||||
return new String(buffer);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static String toHex(byte[] bytes) {
|
||||
char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
char[] resultCharArray = new char[bytes.length * 2];
|
||||
int index = 0;
|
||||
for (byte b : bytes) {
|
||||
resultCharArray[index++] = hexDigits[b >>> 4 & 0xf];
|
||||
resultCharArray[index++] = hexDigits[b & 0xf];
|
||||
}
|
||||
return new String(resultCharArray);
|
||||
}
|
||||
|
||||
public static String md5(String s) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] bytes = md.digest(s.getBytes(Charset.forName("UTF-8")));
|
||||
return toHex(bytes);
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static String readAssetFile(String assetFile) {
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
|
@ -1,4 +1,6 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const crypto = require("crypto");
|
||||
|
||||
async function work() {
|
||||
const imageDts = await fs.promises.readFile("src/image.d.ts", "utf-8");
|
||||
@ -13,6 +15,24 @@ ${indexDts
|
||||
${imageDts}
|
||||
`;
|
||||
await fs.promises.writeFile("index.d.ts", content);
|
||||
const files = [
|
||||
"bundle/doric-lib.js",
|
||||
"bundle/doric-sandbox.js",
|
||||
"bundle/doric-web.js",
|
||||
"bundle/doric-web.html",
|
||||
];
|
||||
const androidAssets = "../doric-android/doric/src/main/assets";
|
||||
for (let file of files) {
|
||||
const md5 = crypto.createHash("md5");
|
||||
md5.update(path.basename(file));
|
||||
const name = md5.digest("hex").toLowerCase();
|
||||
const data = await fs.promises.readFile(file);
|
||||
const temp = new Uint8Array(data.buffer);
|
||||
for (let i = 0; i < temp.length; i++) {
|
||||
temp[i] = 0xff - temp[i];
|
||||
}
|
||||
await fs.promises.writeFile(path.resolve(androidAssets, name), data);
|
||||
}
|
||||
}
|
||||
|
||||
work();
|
||||
|
Reference in New Issue
Block a user