Skip to content

Commit 5ff5ad2

Browse files
committed
version 1.6.0
☞ Supports plugin ☞ Console can log html code ☞ Updated FTP library. ☞ Updated SFTP functionality. ☞ Separated all hardcoded modifications in ace editor. ☞ Improved clipboard actions. ☞ Updated Ace editor. ☞ Added horizontal padding. ☞ Changed syntax highlighting is saved. ☞ Various fixes.
1 parent 065a327 commit 5ff5ad2

97 files changed

Lines changed: 1798 additions & 554 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/plugins.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"plugins":["cordova-clipboard","cordova-plugin-vibration","cordova-plugin-buildinfo","cordova-plugin-device","cordova-plugin-whitelist","cordova-plugin-ftp","cordova-plugin-webserver","cordova-plugin-iap","cordova-plugin-sdcard","cordova-plugin-sftp","cordova-plugin-system","cordova-plugin-file"]}
1+
{"plugins":["cordova-clipboard","cordova-plugin-vibration","cordova-plugin-buildinfo","cordova-plugin-device","cordova-plugin-whitelist","cordova-plugin-iap","cordova-plugin-sftp","cordova-plugin-system","cordova-plugin-sdcard","cordova-plugin-ftp","cordova-plugin-file","cordova-plugin-server"]}

config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version='1.0' encoding='utf-8' ?>
2-
<widget id="com.foxdebug.acode" android-versionCode="185" version="1.5.6"
2+
<widget id="com.foxdebug.acode" android-versionCode="186" version="1.5.6"
33
xmlns="http://www.w3.org/ns/widgets"
44
xmlns:android="http://schemas.android.com/apk/res/android"
55
xmlns:cdv="http://cordova.apache.org/ns/1.0">

package.json

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
"cordova-plugin-buildinfo": {},
2828
"cordova-plugin-device": {},
2929
"cordova-plugin-whitelist": {},
30-
"cordova-plugin-webserver": {},
3130
"cordova-plugin-iap": {},
3231
"cordova-plugin-sftp": {},
3332
"cordova-plugin-system": {},
3433
"cordova-plugin-sdcard": {},
35-
"cordova-plugin-ftp": {}
34+
"cordova-plugin-ftp": {},
35+
"cordova-plugin-server": {}
3636
},
3737
"platforms": [
3838
"android"
@@ -52,8 +52,8 @@
5252
],
5353
"devDependencies": {
5454
"@babel/cli": "^7.17.6",
55-
"@babel/plugin-transform-runtime": "^7.17.0",
56-
"@babel/preset-env": "^7.16.11",
55+
"@babel/plugin-transform-runtime": "^7.18.2",
56+
"@babel/preset-env": "^7.18.2",
5757
"@types/ace": "0.0.48",
5858
"@types/url-parse": "^1.4.8",
5959
"autoprefixer": "^10.4.4",
@@ -69,34 +69,33 @@
6969
"cordova-plugin-sftp": "file:src/plugins/sftp",
7070
"cordova-plugin-system": "file:src/plugins/system",
7171
"cordova-plugin-vibration": "^3.1.1",
72-
"cordova-plugin-webserver": "file:src/plugins/webserver",
72+
"cordova-plugin-webserver": "file:src/plugins/server",
7373
"cordova-plugin-whitelist": "^1.3.5",
7474
"css-loader": "^6.7.1",
7575
"mini-css-extract-plugin": "^2.6.0",
7676
"node-sass": "^7.0.1",
7777
"path-browserify": "^1.0.1",
78-
"postcss-loader": "^6.2.1",
78+
"postcss-loader": "^7.0.0",
7979
"prettier": "2.6.2",
80-
"prettier-plugin-java": "^1.6.1",
80+
"prettier-plugin-java": "^1.6.2",
8181
"raw-loader": "^4.0.2",
82-
"sass-loader": "^12.6.0",
82+
"sass-loader": "^13.0.0",
8383
"style-loader": "^3.1.0",
84-
"webpack": "^5.71.0",
84+
"webpack": "^5.73.0",
8585
"webpack-cli": "^4.9.2"
8686
},
8787
"dependencies": {
88-
"@babel/core": "^7.17.8",
89-
"@babel/runtime": "^7.17.8",
88+
"@babel/core": "^7.18.2",
89+
"@babel/runtime": "^7.18.3",
9090
"@deadlyjack/ajax": "^1.0.9",
9191
"ace-builds": "^1.6.0",
9292
"autosize": "^5.0.0",
93-
"axios": "^0.26.1",
94-
"core-js": "^3.21.1",
93+
"axios": "^0.27.2",
94+
"core-js": "^3.22.8",
9595
"crypto": "^1.0.1",
9696
"crypto-js": "^4.0.0",
9797
"esprima": "^4.0.1",
98-
"filesize": "^8.0.7",
99-
"glob": "^7.2.0",
98+
"filesize": "^9.0.2",
10099
"html-tag-js": "^1.0.4",
101100
"irid": "^2.0.2",
102101
"marked": "^4.0.12",
@@ -110,4 +109,4 @@
110109
"resolutions": {
111110
"dummy": "^0.1.5"
112111
}
113-
}
112+
}

plugins/android.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,28 @@
1919
"cordova-plugin-file": {
2020
"PACKAGE_NAME": "com.foxdebug.acode"
2121
},
22-
"cordova-plugin-iap": {
22+
"cordova-plugin-ftp": {
2323
"PACKAGE_NAME": "com.foxdebug.acode"
2424
},
25-
"cordova-plugin-sftp": {
25+
"cordova-plugin-iap": {
2626
"PACKAGE_NAME": "com.foxdebug.acode"
2727
},
28-
"cordova-plugin-system": {
28+
"cordova-plugin-sdcard": {
2929
"PACKAGE_NAME": "com.foxdebug.acode"
3030
},
31-
"cordova-plugin-vibration": {
31+
"cordova-plugin-server": {
3232
"PACKAGE_NAME": "com.foxdebug.acode"
3333
},
34-
"cordova-plugin-webserver": {
34+
"cordova-plugin-sftp": {
3535
"PACKAGE_NAME": "com.foxdebug.acode"
3636
},
37-
"cordova-plugin-whitelist": {
37+
"cordova-plugin-system": {
3838
"PACKAGE_NAME": "com.foxdebug.acode"
3939
},
40-
"cordova-plugin-sdcard": {
40+
"cordova-plugin-vibration": {
4141
"PACKAGE_NAME": "com.foxdebug.acode"
4242
},
43-
"cordova-plugin-ftp": {
43+
"cordova-plugin-whitelist": {
4444
"PACKAGE_NAME": "com.foxdebug.acode"
4545
}
4646
},
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface Server{
2+
stop(onSuccess: () => void, onError: (error: any) => void): void;
3+
send(id: string, data: any, onSuccess: () => void, onError: (error: any) => void): void;
4+
port: number;
5+
}
6+
7+
declare var CreateServer: (port: number, onSuccess: (msg: any) => void, onError: (err: any) => void) => Server;
File renamed without changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
3+
xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-server" version="1.1.0">
4+
<engines>
5+
<engine name="cordova" version=">=6.5.0" />
6+
</engines>
7+
8+
<name>Webserver for Cordova Apps</name>
9+
<keywords>HTTP server, webserver</keywords>
10+
11+
<js-module src="www/server.js" name="CreateServer">
12+
<clobbers target="window.CreateServer" />
13+
</js-module>
14+
15+
<platform name="android">
16+
<framework src="org.nanohttpd:nanohttpd:+" />
17+
<framework src="androidx.documentfile:documentfile:1.0.1" />
18+
<source-file src="src/android/com/foxdebug/server/Server.java" target-dir="src/com/foxdebug/server"/>
19+
<source-file src="src/android/com/foxdebug/server/NanoHTTPDWebserver.java" target-dir="src/com/foxdebug/server"/>
20+
<config-file target="config.xml" parent="/*">
21+
<feature name="Server">
22+
<param name="android-package" value="com.foxdebug.server.Server"/>
23+
</feature>
24+
</config-file>
25+
</platform>
26+
</plugin>

src/plugins/webserver/src/android/NanoHTTPDWebserver.java renamed to plugins/cordova-plugin-server/src/android/com/foxdebug/server/NanoHTTPDWebserver.java

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package org.apache.cordova.plugin;
1+
package com.foxdebug.server;
22

33
import android.content.ContentResolver;
44
import android.content.Context;
55
import android.net.Uri;
6+
import android.util.Log;
67
import androidx.documentfile.provider.DocumentFile;
78
import fi.iki.elonen.NanoHTTPD;
89
import java.io.File;
@@ -15,19 +16,21 @@
1516
import java.util.Iterator;
1617
import java.util.Map;
1718
import java.util.UUID;
19+
import org.apache.cordova.CallbackContext;
1820
import org.apache.cordova.PluginResult;
1921
import org.json.JSONException;
2022
import org.json.JSONObject;
2123

2224
public class NanoHTTPDWebserver extends NanoHTTPD {
2325

24-
Webserver webserver;
26+
public HashMap<String, Object> responses;
27+
public CallbackContext onRequestCallbackContext;
2528
Context context;
2629

27-
public NanoHTTPDWebserver(int port, Webserver webserver, Context context) {
30+
public NanoHTTPDWebserver(int port, Context context) {
2831
super(port);
29-
this.webserver = webserver;
3032
this.context = context;
33+
this.responses = new HashMap<String, Object>();
3134
}
3235

3336
private String getBodyText(IHTTPSession session) {
@@ -172,10 +175,10 @@ Response serveFile(
172175
);
173176
res.addHeader("Accept-Ranges", "bytes");
174177
res.addHeader("Content-Length", "" + newLen);
175-
res.addHeader(
176-
"Content-Range",
177-
"bytes " + startFrom + "-" + endAt + "/" + fileLen
178-
);
178+
179+
String contentRange =
180+
"bytes " + startFrom + "-" + endAt + "/" + fileLen;
181+
res.addHeader("Content-Range", contentRange);
179182
res.addHeader("ETag", etag);
180183
}
181184
} else {
@@ -217,6 +220,7 @@ Response serveFile(
217220
}
218221
}
219222
} catch (Exception e) {
223+
Log.d("ServeFileError", e.getMessage());
220224
String type = e.getClass().getName();
221225
if (type.equals("FileNotFoundException")) res =
222226
newFixedLengthResponse(
@@ -249,19 +253,17 @@ public Response serve(IHTTPSession session) {
249253
e.printStackTrace();
250254
}
251255
pluginResult.setKeepCallback(true);
252-
this.webserver.onRequestCallbackContext.sendPluginResult(pluginResult);
256+
this.onRequestCallbackContext.sendPluginResult(pluginResult);
253257

254-
while (!this.webserver.responses.containsKey(requestUUID)) {
258+
while (!this.responses.containsKey(requestUUID)) {
255259
try {
256260
Thread.sleep(1);
257261
} catch (InterruptedException e) {
258262
e.printStackTrace();
259263
}
260264
}
261265

262-
JSONObject responseObject = (JSONObject) this.webserver.responses.get(
263-
requestUUID
264-
);
266+
JSONObject responseObject = (JSONObject) this.responses.get(requestUUID);
265267
Response response = null;
266268

267269
if (responseObject.has("path")) {
@@ -270,13 +272,17 @@ public Response serve(IHTTPSession session) {
270272
DocumentFile file = getFile(path);
271273
String mimeType = URLConnection.guessContentTypeFromName(path);
272274
Response res = serveFile(session.getHeaders(), file, mimeType);
273-
Iterator<?> keys = responseObject.getJSONObject("headers").keys();
274-
while (keys.hasNext()) {
275-
String key = (String) keys.next();
276-
res.addHeader(
277-
key,
278-
responseObject.getJSONObject("headers").getString(key)
279-
);
275+
JSONObject headers = getJSONObject(responseObject, "headers");
276+
// JSONObject headers = responseObject.getJSONObject("headers");
277+
if (headers != null) {
278+
Iterator<String> keys = headers.keys();
279+
while (keys.hasNext()) {
280+
String key = (String) keys.next();
281+
res.addHeader(
282+
key,
283+
responseObject.getJSONObject("headers").getString(key)
284+
);
285+
}
280286
}
281287
return res;
282288
} catch (JSONException e) {
@@ -327,4 +333,12 @@ private InputStream getInputStream(DocumentFile file)
327333
ContentResolver contentResolver = context.getContentResolver();
328334
return contentResolver.openInputStream(uri);
329335
}
336+
337+
private JSONObject getJSONObject(JSONObject ob, String key) {
338+
JSONObject jsonObject = null;
339+
try {
340+
jsonObject = ob.getJSONObject(key);
341+
} catch (JSONException e) {}
342+
return jsonObject;
343+
}
330344
}

0 commit comments

Comments
 (0)