Compare commits

..

6 Commits

6 changed files with 140 additions and 41 deletions

1
.idea/gradle.xml generated
View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>

1
.idea/misc.xml generated
View File

@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration"> <component name="FrameworkDetectionExcludesConfiguration">

79
.idea/workspace.xml generated
View File

@@ -5,20 +5,15 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="ceecbd3e-6a84-488d-ae73-a0b5b3f4010e" name="Changes" comment=""> <list default="true" id="ceecbd3e-6a84-488d-ae73-a0b5b3f4010e" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/gradle.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/gradle.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/gradle.xml" afterDir="false" /> <<<<<<< HEAD
<change afterPath="$PROJECT_DIR$/.idea/jarRepositories.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" /> =======
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/build.gradle" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/tech/nevets/ngxinstaller/Server.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/tech/nevets/ngxinstaller/Server.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/gradle/wrapper/gradle-wrapper.jar" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/tech/nevets/ngxinstaller/TextStorage.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/tech/nevets/ngxinstaller/TextStorage.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/gradle/wrapper/gradle-wrapper.properties" afterDir="false" /> >>>>>>> a954dc49f4c6943f06c97c50957ac1b1ac48088b
<change afterPath="$PROJECT_DIR$/gradlew" afterDir="false" />
<change afterPath="$PROJECT_DIR$/gradlew.bat" afterDir="false" />
<change afterPath="$PROJECT_DIR$/settings.gradle" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/tech/nevets/ngxinstaller/Server.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/tech/nevets/ngxinstaller/TextStorage.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -38,23 +33,7 @@
</task> </task>
<projects_view> <projects_view>
<tree_state> <tree_state>
<expand> <expand />
<path>
<item name="" type="6a2764b6:ExternalProjectsStructure$RootNode" />
<item name="NginxInstallerBackend" type="f1a62948:ProjectNode" />
</path>
<path>
<item name="" type="6a2764b6:ExternalProjectsStructure$RootNode" />
<item name="NginxInstallerBackend" type="f1a62948:ProjectNode" />
<item name="Tasks" type="e4a08cd1:TasksNode" />
</path>
<path>
<item name="" type="6a2764b6:ExternalProjectsStructure$RootNode" />
<item name="NginxInstallerBackend" type="f1a62948:ProjectNode" />
<item name="Tasks" type="e4a08cd1:TasksNode" />
<item name="shadow" type="c8890929:TasksNode$1" />
</path>
</expand>
<select /> <select />
</tree_state> </tree_state>
</projects_view> </projects_view>
@@ -74,9 +53,9 @@
<component name="MarkdownSettingsMigration"> <component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" /> <option name="stateVersion" value="1" />
</component> </component>
<component name="ProjectColorInfo"><![CDATA[{ <component name="ProjectColorInfo">{
"associatedIndex": 0 &quot;associatedIndex&quot;: 0
}]]></component> }</component>
<component name="ProjectId" id="2Zm8KgH0I3o9715Y3ZzBs94Smav" /> <component name="ProjectId" id="2Zm8KgH0I3o9715Y3ZzBs94Smav" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true"> <component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" /> <ConfirmationsSetting value="2" id="Add" />
@@ -85,14 +64,36 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<<<<<<< HEAD
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;Gradle.NginxInstallerBackend [:Server.main()].executor&quot;: &quot;Debug&quot;,
&quot;Gradle.NginxInstallerBackend [shadowJar].executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}</component>
<component name="RunManager" selected="Gradle.NginxInstallerBackend [shadowJar]">
=======
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent"><![CDATA[{
"keyToString": { "keyToString": {
"Gradle.NginxInstallerBackend [:Server.main()].executor": "Debug", "Gradle.NginxInstallerBackend [:Server.main()].executor": "Debug",
"Gradle.NginxInstallerBackend [shadowJar].executor": "Run", "Gradle.NginxInstallerBackend [shadowJar].executor": "Run",
"RunOnceActivity.OpenProjectViewOnStart": "true", "RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true", "RunOnceActivity.ShowReadmeOnStart": "true",
"WebServerToolWindowFactoryState": "false",
"git-widget-placeholder": "master",
"ignore.virus.scanning.warn.message": "true", "ignore.virus.scanning.warn.message": "true",
"kotlin-language-version-configured": "true", "kotlin-language-version-configured": "true",
"last_opened_file_path": "F:/Projects/Web/NginxInstallerBackend",
"node.js.detected.package.eslint": "true", "node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true", "node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)", "node.js.selected.package.eslint": "(autodetect)",
@@ -101,7 +102,8 @@
"vue.rearranger.settings.migration": "true" "vue.rearranger.settings.migration": "true"
} }
}]]></component> }]]></component>
<component name="RunManager" selected="Gradle.NginxInstallerBackend [shadowJar]"> <component name="RunManager" selected="Application.Server">
>>>>>>> a954dc49f4c6943f06c97c50957ac1b1ac48088b
<configuration name="Server" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true"> <configuration name="Server" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="tech.nevets.ngxinstaller.Server" /> <option name="MAIN_CLASS_NAME" value="tech.nevets.ngxinstaller.Server" />
<module name="NginxInstallerBackend.main" /> <module name="NginxInstallerBackend.main" />
@@ -159,7 +161,14 @@
<option name="number" value="Default" /> <option name="number" value="Default" />
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1703015833777</updated> <updated>1703015833777</updated>
<<<<<<< HEAD
<workItem from="1703015834937" duration="11923000" />
<workItem from="1703098848808" duration="606000" />
<workItem from="1704314407897" duration="15000" />
=======
<workItem from="1703015834937" duration="5516000" /> <workItem from="1703015834937" duration="5516000" />
<workItem from="1703185574324" duration="1576000" />
>>>>>>> a954dc49f4c6943f06c97c50957ac1b1ac48088b
</task> </task>
<servers /> <servers />
</component> </component>

View File

@@ -4,7 +4,7 @@ plugins {
} }
group = 'tech.nevets' group = 'tech.nevets'
version = '0.1.0' version = '0.1.1'
repositories { repositories {
mavenCentral() mavenCentral()

View File

@@ -4,6 +4,12 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import java.net.URLDecoder;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
@@ -11,17 +17,82 @@ import static spark.Spark.*;
public class Server { public class Server {
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public static String cachedNginxSite = "";
public static void main(String[] args) { public static void main(String[] args) {
port(8080); if (args.length >= 1) {
port(Integer.parseInt(args[0]));
} else {
port(8080);
}
try {
cachedNginxSite = getHTML("https://nginx.org/download/");
} catch (Exception e) {
throw new RuntimeException(e);
}
options("/*",
(request, response) -> {
String accessControlRequestHeaders = request
.headers("Access-Control-Request-Headers");
if (accessControlRequestHeaders != null) {
response.header("Access-Control-Allow-Headers",
accessControlRequestHeaders);
}
String accessControlRequestMethod = request
.headers("Access-Control-Request-Method");
if (accessControlRequestMethod != null) {
response.header("Access-Control-Allow-Methods",
accessControlRequestMethod);
}
return "OK";
});
before((request, response) -> response.header("Access-Control-Allow-Origin", "*"));
post("/ngx/dhv", (req, res) -> {
System.out.println(req.body());
JsonObject jsonObject = GSON.fromJson(req.body(), JsonObject.class);
String version = jsonObject.get("version").getAsString();
System.out.println(version);
try {
if (cachedNginxSite.contains(version + ".tar.gz")) {
System.out.println("true");
return "{ \"url\":\"true\" }";
}
} catch (Exception ignore) {
System.out.println("false");
return "{ \"url\":\"false\" }";
}
System.out.println("false");
return "{ \"url\":\"false\" }";
});
post("/ngx/create", (req, res) -> { post("/ngx/create", (req, res) -> {
JsonObject jsonObject = GSON.fromJson(req.body(), JsonObject.class); JsonObject jsonObject = GSON.fromJson(req.body(), JsonObject.class);
TextStorage ts = TextStorage.createPaste(jsonObject.get("content").getAsString()); TextStorage ts = TextStorage.createPaste(java.net.URLDecoder.decode(jsonObject.get("content").getAsString(), StandardCharsets.UTF_8));
return "{ \"url\":\"https://api.nevets.tech/ngx/raw/" + ts.getId() + "\" }"; return "{ \"url\":\"https://api.nevets.tech/ngx/raw/" + ts.getId() + "\" }";
}); });
get("/ngx/raw/*", (req, res) -> { get("/ngx/raw/*", (req, res) -> {
String id = req.splat()[0]; String id = req.splat()[0];
TextStorage ts = TextStorage.getPaste(id); TextStorage ts = TextStorage.getPaste(id);
return GSON.toJson(ts); res.type("text/plain");
if (ts == null) {
res.status(404);
return "Content Not Found!";
}
return URLDecoder.decode(ts.getText(), StandardCharsets.UTF_8);
});
get("/ngx/json/*", (req, res) -> {
String id = req.splat()[0];
TextStorage ts = TextStorage.getPaste(id);
res.type("application/json");
if (ts == null) {
res.status(404);
return "{\"error\":\"content not found\"}";
}
res.type("raw");
return ts.getText();
}); });
@@ -30,6 +101,21 @@ public class Server {
timer.schedule(tt, 0, 60000); timer.schedule(tt, 0, 60000);
} }
public static String getHTML(String urlToRead) throws Exception {
StringBuilder result = new StringBuilder();
URL url = new URL(urlToRead);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(conn.getInputStream()))) {
for (String line; (line = reader.readLine()) != null; ) {
result.append(line);
}
}
return result.toString();
}
static class GCTask extends TimerTask { static class GCTask extends TimerTask {
@Override @Override
public void run() { public void run() {

View File

@@ -23,6 +23,10 @@ public class TextStorage {
return this.id; return this.id;
} }
public String getText() {
return this.text;
}
public static TextStorage getPaste(String id) { public static TextStorage getPaste(String id) {
for (TextStorage ts : DB) { for (TextStorage ts : DB) {
if (ts.id.equals(id)) { if (ts.id.equals(id)) {
@@ -33,7 +37,7 @@ public class TextStorage {
} }
public static TextStorage createPaste(String text) { public static TextStorage createPaste(String text) {
TextStorage ts = new TextStorage(generateId(), text, System.currentTimeMillis() + 3600000); TextStorage ts = new TextStorage(generateId(), text, System.currentTimeMillis() + 1800000);
DB.add(ts); DB.add(ts);
return ts; return ts;
} }