Compare commits
1 Commits
master
...
dependabot
Author | SHA1 | Date | |
---|---|---|---|
|
0d36ff7590 |
12
package-lock.json
generated
12
package-lock.json
generated
@ -7019,9 +7019,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/systeminformation": {
|
||||
"version": "5.12.1",
|
||||
"resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-5.12.1.tgz",
|
||||
"integrity": "sha512-qAV0xSeSJlg0ZHmQ1T2rLrL54SATalBx6v4T8Sd5s17pEm6saX3LKzlPhfPx+EfT91y9yhRYnKhnMoLTFkxbqw==",
|
||||
"version": "5.21.8",
|
||||
"resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-5.21.8.tgz",
|
||||
"integrity": "sha512-Xf1KDMUTQHLOT9Z7MjpSpsbaICOHcm4OZ9c9qqpkCoXuxq5MoyDrgu5GIQYpoiralXNPrqxDz3ND8MdllpXeQA==",
|
||||
"dev": true,
|
||||
"os": [
|
||||
"darwin",
|
||||
@ -13419,9 +13419,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"systeminformation": {
|
||||
"version": "5.12.1",
|
||||
"resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-5.12.1.tgz",
|
||||
"integrity": "sha512-qAV0xSeSJlg0ZHmQ1T2rLrL54SATalBx6v4T8Sd5s17pEm6saX3LKzlPhfPx+EfT91y9yhRYnKhnMoLTFkxbqw==",
|
||||
"version": "5.21.8",
|
||||
"resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-5.21.8.tgz",
|
||||
"integrity": "sha512-Xf1KDMUTQHLOT9Z7MjpSpsbaICOHcm4OZ9c9qqpkCoXuxq5MoyDrgu5GIQYpoiralXNPrqxDz3ND8MdllpXeQA==",
|
||||
"dev": true
|
||||
},
|
||||
"tar": {
|
||||
|
@ -27,8 +27,6 @@
|
||||
</platform>
|
||||
|
||||
<platform name="ios">
|
||||
<hook type="after_platform_add" src="scripts/re-add.js" />
|
||||
<hook type="after_plugin_add" src="scripts/re-add.js" />
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="Webserver">
|
||||
<param name="ios-package" value="Webserver" />
|
||||
@ -44,10 +42,10 @@
|
||||
|
||||
<podspec>
|
||||
<config>
|
||||
<source url="https://m.shuto.cn:8681/github/CocoaPods-Specs.git"/>
|
||||
<source url="https://github.com/CocoaPods/Specs.git"/>
|
||||
</config>
|
||||
<pods use-frameworks="true">
|
||||
<pod name="GCDWebServer" git="https://m.shuto.cn:8681/github/GCDWebServer.git"/>
|
||||
<pod name="GCDWebServer" spec="~> 3.5.2"/>
|
||||
</pods>
|
||||
</podspec>
|
||||
|
||||
|
@ -1,37 +0,0 @@
|
||||
/**
|
||||
* ~ Copyright (c) 2023 Beijing Shuto Technology Co,. Ltd. All rights reserved.
|
||||
*/
|
||||
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
var child_process = require("child_process");
|
||||
|
||||
/**
|
||||
* 读取文件内容,然后替换部分内容后写回
|
||||
* @param file
|
||||
* @param callback
|
||||
*/
|
||||
function replaceContents(file, callback) {
|
||||
var data = fs.readFileSync(file, 'utf8');
|
||||
data = callback(data);
|
||||
fs.writeFileSync(file,data,'utf8');
|
||||
}
|
||||
|
||||
/**
|
||||
* 一些自定义操作
|
||||
* @param ctx
|
||||
*/
|
||||
module.exports = function (ctx) {
|
||||
console.log('======================webServer pod re-add hook==========================');
|
||||
var rootDir = ctx.opts.projectRoot;
|
||||
var project = path.join(rootDir, 'platforms/ios');
|
||||
if (fs.existsSync(project)) {
|
||||
replaceContents(path.join(project, 'Podfile'), (content) => {
|
||||
if (content.indexOf('GCDWebServer') < 0) {
|
||||
content = content.replace("\nend", "\n pod 'GCDWebServer', :git => 'https://m.shuto.cn:8681/github/GCDWebServer.git'\nend")
|
||||
}
|
||||
return content;
|
||||
});
|
||||
child_process.execSync("pod install", { cwd: project });
|
||||
}
|
||||
};
|
@ -20,7 +20,6 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import fi.iki.elonen.NanoHTTPD;
|
||||
import fi.iki.elonen.NanoHTTPD.Response.Status;
|
||||
|
||||
public class NanoHTTPDWebserver extends NanoHTTPD {
|
||||
|
||||
@ -84,7 +83,7 @@ public class NanoHTTPDWebserver extends NanoHTTPD {
|
||||
|
||||
private Response newFixedFileResponse(File file, String mime) throws FileNotFoundException {
|
||||
Response res;
|
||||
res = newFixedLengthResponse(Status.OK, mime, new FileInputStream(file), (int) file.length());
|
||||
res = newFixedLengthResponse(Response.Status.OK, mime, new FileInputStream(file), (int) file.length());
|
||||
res.addHeader("Accept-Ranges", "bytes");
|
||||
return res;
|
||||
}
|
||||
@ -133,7 +132,7 @@ public class NanoHTTPDWebserver extends NanoHTTPD {
|
||||
// and the startFrom of the range is satisfiable
|
||||
// would return range from file
|
||||
// respond with not-modified
|
||||
res = newFixedLengthResponse(Status.NOT_MODIFIED, mime, "");
|
||||
res = newFixedLengthResponse(Response.Status.NOT_MODIFIED, mime, "");
|
||||
res.addHeader("ETag", etag);
|
||||
} else {
|
||||
if (endAt < 0) {
|
||||
@ -147,7 +146,7 @@ public class NanoHTTPDWebserver extends NanoHTTPD {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
fis.skip(startFrom);
|
||||
|
||||
res = newFixedLengthResponse(Status.PARTIAL_CONTENT, mime, fis, newLen);
|
||||
res = newFixedLengthResponse(Response.Status.PARTIAL_CONTENT, mime, fis, newLen);
|
||||
res.addHeader("Accept-Ranges", "bytes");
|
||||
res.addHeader("Content-Length", "" + newLen);
|
||||
res.addHeader("Content-Range", "bytes " + startFrom + "-" + endAt + "/" + fileLen);
|
||||
@ -158,21 +157,21 @@ public class NanoHTTPDWebserver extends NanoHTTPD {
|
||||
if (headerIfRangeMissingOrMatching && range != null && startFrom >= fileLen) {
|
||||
// return the size of the file
|
||||
// 4xx responses are not trumped by if-none-match
|
||||
res = newFixedLengthResponse(Status.RANGE_NOT_SATISFIABLE, NanoHTTPD.MIME_PLAINTEXT, "");
|
||||
res = newFixedLengthResponse(Response.Status.RANGE_NOT_SATISFIABLE, NanoHTTPD.MIME_PLAINTEXT, "");
|
||||
res.addHeader("Content-Range", "bytes */" + fileLen);
|
||||
res.addHeader("ETag", etag);
|
||||
} else if (range == null && headerIfNoneMatchPresentAndMatching) {
|
||||
// full-file-fetch request
|
||||
// would return entire file
|
||||
// respond with not-modified
|
||||
res = newFixedLengthResponse(Status.NOT_MODIFIED, mime, "");
|
||||
res = newFixedLengthResponse(Response.Status.NOT_MODIFIED, mime, "");
|
||||
res.addHeader("ETag", etag);
|
||||
} else if (!headerIfRangeMissingOrMatching && headerIfNoneMatchPresentAndMatching) {
|
||||
// range request that doesn't match current etag
|
||||
// would return entire (different) file
|
||||
// respond with not-modified
|
||||
|
||||
res = newFixedLengthResponse(Status.NOT_MODIFIED, mime, "");
|
||||
res = newFixedLengthResponse(Response.Status.NOT_MODIFIED, mime, "");
|
||||
res.addHeader("ETag", etag);
|
||||
} else {
|
||||
// supply the file
|
||||
@ -182,7 +181,7 @@ public class NanoHTTPDWebserver extends NanoHTTPD {
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
res = newFixedLengthResponse(Status.FORBIDDEN, NanoHTTPD.MIME_PLAINTEXT, ioe.getMessage());
|
||||
res = newFixedLengthResponse(Response.Status.FORBIDDEN, NanoHTTPD.MIME_PLAINTEXT, ioe.getMessage());
|
||||
}
|
||||
|
||||
return res;
|
||||
@ -251,30 +250,8 @@ public class NanoHTTPDWebserver extends NanoHTTPD {
|
||||
return response;
|
||||
} else {
|
||||
try {
|
||||
Response.IStatus status = Status.lookup(responseObject.getInt("status"));
|
||||
if(status == null){
|
||||
status = new Response.IStatus(){
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
try {
|
||||
return ""+this.getRequestStatus()+" "+responseObject.getString("body");
|
||||
} catch (JSONException e) {
|
||||
return ""+this.getRequestStatus()+" "+"Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequestStatus() {
|
||||
try {
|
||||
return responseObject.getInt("status");
|
||||
} catch (JSONException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
response = newFixedLengthResponse(status,
|
||||
response = newFixedLengthResponse(
|
||||
Response.Status.lookup(responseObject.getInt("status")),
|
||||
getContentType(responseObject),
|
||||
responseObject.getString("body")
|
||||
);
|
||||
|
@ -26,32 +26,24 @@ public class Webserver extends CordovaPlugin {
|
||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||
if ("start".equals(action)) {
|
||||
try {
|
||||
this.start(args, callbackContext);
|
||||
this.start(args, callbackContext);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if ("stop".equals(action)) {
|
||||
}
|
||||
if ("stop".equals(action)) {
|
||||
this.stop(args, callbackContext);
|
||||
return true;
|
||||
}
|
||||
if ("onRequest".equals(action)) {
|
||||
}
|
||||
if ("onRequest".equals(action)) {
|
||||
this.onRequest(args, callbackContext);
|
||||
return true;
|
||||
}
|
||||
if ("sendResponse".equals(action)) {
|
||||
}
|
||||
if ("sendResponse".equals(action)) {
|
||||
this.sendResponse(args, callbackContext);
|
||||
return true;
|
||||
}
|
||||
if ("isRunning".equals(action)) {
|
||||
if(this.nanoHTTPDWebserver!=null){
|
||||
callbackContext.success(this.nanoHTTPDWebserver.isAlive()?1:0);
|
||||
}else{
|
||||
callbackContext.success(0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false; // Returning false results in a "MethodNotFound" error.
|
||||
}
|
||||
|
||||
|
@ -167,11 +167,4 @@
|
||||
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK)
|
||||
self.commandDelegate!.send(pluginResult, callbackId: command.callbackId)
|
||||
}
|
||||
|
||||
@objc(isRunning:)
|
||||
func isRunning(_ command: CDVInvokedUrlCommand) {
|
||||
let messageAsInt = self.webServer.isRunning ? 1 : 0;
|
||||
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: messageAsInt)
|
||||
self.commandDelegate!.send(pluginResult, callbackId: command.callbackId)
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ const START_FUNCTION = 'start';
|
||||
const ONREQUEST_FUNCTION = 'onRequest';
|
||||
const SENDRESPONSE_FUNCION = 'sendResponse';
|
||||
const STOP_FUNCTION = 'stop';
|
||||
const ISRUNNING_FUNCTION = 'isRunning';
|
||||
|
||||
export function start(success_callback, error_callback, port) {
|
||||
let params = [];
|
||||
@ -55,12 +54,3 @@ export function stop(success_callback, error_callback) {
|
||||
[]
|
||||
);
|
||||
}
|
||||
export function isRunning(success_callback, error_callback) {
|
||||
exec(
|
||||
success_callback,
|
||||
error_callback,
|
||||
WEBSERVER_CLASS,
|
||||
ISRUNNING_FUNCTION,
|
||||
[]
|
||||
);
|
||||
}
|
@ -7,7 +7,6 @@ exports.start = start;
|
||||
exports.onRequest = onRequest;
|
||||
exports.sendResponse = sendResponse;
|
||||
exports.stop = stop;
|
||||
exports.isRunning = isRunning;
|
||||
|
||||
var _exec = require('cordova/exec');
|
||||
|
||||
@ -20,7 +19,6 @@ var START_FUNCTION = 'start';
|
||||
var ONREQUEST_FUNCTION = 'onRequest';
|
||||
var SENDRESPONSE_FUNCION = 'sendResponse';
|
||||
var STOP_FUNCTION = 'stop';
|
||||
var ISRUNNING_FUNCTION = 'isRunning';
|
||||
|
||||
function start(success_callback, error_callback, port) {
|
||||
var params = [];
|
||||
@ -43,6 +41,3 @@ function sendResponse(requestId, params, success_callback, error_callback) {
|
||||
function stop(success_callback, error_callback) {
|
||||
(0, _exec2.default)(success_callback, error_callback, WEBSERVER_CLASS, STOP_FUNCTION, []);
|
||||
}
|
||||
function isRunning(success_callback, error_callback) {
|
||||
(0, _exec2.default)(success_callback, error_callback, WEBSERVER_CLASS, ISRUNNING_FUNCTION, []);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user