use of org.pdown.gui.extension.ExtensionInfo in project proxyee-down by monkeyWie.
the class NativeController method updateExtensionSetting.
@RequestMapping("updateExtensionSetting")
public FullHttpResponse updateExtensionSetting(Channel channel, FullHttpRequest request) throws Exception {
Map<String, Object> map = getJSONParams(request);
String path = (String) map.get("path");
Map<String, Object> setting = (Map<String, Object>) map.get("setting");
ExtensionInfo extensionInfo = ExtensionContent.get().stream().filter(e -> e.getMeta().getPath().equals(path)).findFirst().get();
extensionInfo.getMeta().setSettings(setting).save();
return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
}
use of org.pdown.gui.extension.ExtensionInfo in project proxyee-down by monkeyWie.
the class ScriptIntercept method handelResponse.
@Override
public void handelResponse(HttpRequest httpRequest, FullHttpResponse httpResponse, HttpProxyInterceptPipeline pipeline) {
List<ExtensionInfo> extensionInfoList = ExtensionContent.get();
if (isEmpty(extensionInfoList)) {
return;
}
for (ExtensionInfo extensionInfo : extensionInfoList) {
if (isEmpty(extensionInfo.getContentScripts())) {
continue;
}
for (ContentScript contentScript : extensionInfo.getContentScripts()) {
// 扩展注入正则表达式与当前访问的url匹配则注入脚本
String url = HttpDownUtil.getUrl(httpRequest);
if (contentScript.isMatch(url)) {
String apiTemplate = readInsertTemplate(extensionInfo);
StringBuilder scriptsBuilder = new StringBuilder();
for (String script : contentScript.getScripts()) {
File scriptFile = new File(extensionInfo.getMeta().getFullPath() + File.separator + script);
if (scriptFile.exists() && scriptFile.isFile()) {
try {
scriptsBuilder.append(new String(Files.readAllBytes(scriptFile.toPath()), "UTF-8"));
} catch (IOException e) {
}
}
}
apiTemplate = apiTemplate.replace("${content}", scriptsBuilder.toString());
int index = ByteUtil.findText(httpResponse.content(), INSERT_TOKEN);
ByteUtil.insertText(httpResponse.content(), index == -1 ? 0 : index - INSERT_TOKEN.length(), apiTemplate, Charset.forName("UTF-8"));
}
}
}
}
Aggregations