This commit is contained in:
Celeste Madeline Samuel Nokto Dur Grossiord
2026-08-29 13:20:16 +02:00
commit 894ac6525e
156 changed files with 5433 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="/home/Kotama_Chio/libs/sqlite-jdbc-3.53.2.1.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/Kotama_Chio/libs/json-20250107.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>sillyblahaj.org.api</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=21
Binary file not shown.
View File
+12
View File
@@ -0,0 +1,12 @@
/**
*
*/
/**
*
*/
module sillyblahaj.org.api {
requires java.sql;
requires java.net.http;
requires org.json;
requires jdk.httpserver;
}
@@ -0,0 +1,25 @@
package org.sillyjirafe.api;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import org.sillyjirafe.uoapi.element;
public class Json {
public static String JSONConvert(List<element> elements) {
JSONArray tableau = new JSONArray();
for (element e : elements) {
JSONObject obj = new JSONObject();
obj.put("title", e.title());
obj.put("url", e.url());
obj.put("licence", e.licence());
obj.put("source", e.source());
obj.put("type", e.type());
tableau.put(obj);
}
return tableau.toString();
}
}
@@ -0,0 +1,11 @@
package org.sillyjirafe.api;
import java.sql.Connection;
import java.sql.DriverManager;
public class Main {
public static void main(String[] args) throws Exception {
Connection conn = DriverManager.getConnection("jdbc:sqlite:elements.db");
Start.API(conn);
}
}
@@ -0,0 +1,44 @@
package org.sillyjirafe.api;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.sillyjirafe.uoapi.element;
public class Search {
public static List<element> search(Connection conn, Map<String, String> settings) throws SQLException {
List<element> results = new ArrayList<>();
String sql = """
SELECT * FROM creations
WHERE (? = '' OR title LIKE ?)
AND (? = '' OR licence = ?)
AND (? = '' OR type = ?)
""";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, settings.getOrDefault("q", ""));
ps.setString(2, "%" + settings.getOrDefault("q", "") + "%");
ps.setString(3, settings.getOrDefault("licence", ""));
ps.setString(4, settings.getOrDefault("licence", ""));
ps.setString(5, settings.getOrDefault("type", ""));
ps.setString(6, settings.getOrDefault("type", ""));
ResultSet rs = ps.executeQuery();
while (rs.next()) {
results.add(new element(
rs.getString("title"),
rs.getString("url"),
rs.getString("licence"),
rs.getString("source"),
rs.getString("type")
));
}
}
return results;
}
}
@@ -0,0 +1,58 @@
package org.sillyjirafe.api;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.sillyjirafe.uoapi.element;
import com.sun.net.httpserver.HttpServer;
public class Start {
public static void API(Connection conn) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(8081), 0);
server.createContext("/search", exchange -> {
String query = exchange.getRequestURI().getQuery();
Map<String, String> settings = parseQuery(query);
try {
List<element> results = Search.search(conn, settings);
String json = Json.JSONConvert(results);
exchange.getResponseHeaders().set("Content-Type", "application/json");
exchange.sendResponseHeaders(200, json.getBytes().length);
exchange.getResponseBody().write(json.getBytes());
exchange.getResponseBody().close();
} catch (Exception e) {
e.printStackTrace();
exchange.sendResponseHeaders(500, 0);
exchange.getResponseBody().close();
}
});
server.start();
System.out.println("Search API run on 8081 port");
}
public static Map<String, String> parseQuery(String query) {
Map<String, String> params = new HashMap<>();
if (query == null) return params;
String[] paires = query.split("&");
for (String paire : paires) {
String[] cle_valeur = paire.split("=", 2);
if (cle_valeur.length == 2) {
params.put(cle_valeur[0], cle_valeur[1]);
}
}
return params;
}
}
@@ -0,0 +1,3 @@
package org.sillyjirafe.uoapi;
public record element(String title, String url, String licence, String source, String type) {}