Merge branch 'main' into lang_de
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
.idea
|
.idea
|
||||||
|
archive
|
||||||
target
|
target
|
||||||
config/config.json
|
config/config.json
|
||||||
*.sqlite3
|
*.sqlite3
|
||||||
|
|||||||
6
pom.xml
6
pom.xml
@@ -6,11 +6,7 @@
|
|||||||
|
|
||||||
<groupId>org.example</groupId>
|
<groupId>org.example</groupId>
|
||||||
<artifactId>Widerhall</artifactId>
|
<artifactId>Widerhall</artifactId>
|
||||||
<<<<<<< HEAD
|
<version>0.2.2</version>
|
||||||
<version>0.0.23</version>
|
|
||||||
=======
|
|
||||||
<version>0.2.1</version>
|
|
||||||
>>>>>>> main
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ public class Configuration {
|
|||||||
dbFile();
|
dbFile();
|
||||||
baseUrl();
|
baseUrl();
|
||||||
serverPort();
|
serverPort();
|
||||||
|
archiveDir();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +93,13 @@ public class Configuration {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File archiveDir() {
|
||||||
|
var locations = locations();
|
||||||
|
if (!locations.containsKey(ARCHIVE)) locations.put(ARCHIVE, String.join(File.separator,baseDir(),"archive"));
|
||||||
|
return new File((String) locations.get(ARCHIVE));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public int serverPort() {
|
public int serverPort() {
|
||||||
if (!data.containsKey(PORT)) data.put(PORT,80L);
|
if (!data.containsKey(PORT)) data.put(PORT,80L);
|
||||||
var o = data.get(PORT);
|
var o = data.get(PORT);
|
||||||
@@ -107,4 +115,5 @@ public class Configuration {
|
|||||||
public File file() {
|
public File file() {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package de.srsoftware.widerhall;
|
package de.srsoftware.widerhall;
|
||||||
|
|
||||||
public class Constants {
|
public class Constants {
|
||||||
|
public static final String ARCHIVE = "archive";
|
||||||
public static final String BASE = "base";
|
public static final String BASE = "base";
|
||||||
public static final String BASE_URL = "base_url";
|
public static final String BASE_URL = "base_url";
|
||||||
public static final String CONFIG = "configuration";
|
public static final String CONFIG = "configuration";
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ public class Database {
|
|||||||
private final StringBuilder sql; // buffer the sql to be built
|
private final StringBuilder sql; // buffer the sql to be built
|
||||||
private final HashMap<String, List<Object>> where = new HashMap<>(); // buffer condition statements for select
|
private final HashMap<String, List<Object>> where = new HashMap<>(); // buffer condition statements for select
|
||||||
private final HashMap<String,Object> values = new HashMap<>(); // buffer values for insert/update statements
|
private final HashMap<String,Object> values = new HashMap<>(); // buffer values for insert/update statements
|
||||||
|
private final List<String> sortFields = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start to create a new request with the initial SQL
|
* Start to create a new request with the initial SQL
|
||||||
@@ -126,6 +127,10 @@ public class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void applySorting(){
|
||||||
|
if (!sortFields.isEmpty()) sql.append(" ORDER BY ").append(String.join(", ",sortFields));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Request clone() {
|
protected Request clone() {
|
||||||
Request clone = new Request(sql);
|
Request clone = new Request(sql);
|
||||||
@@ -142,6 +147,7 @@ public class Database {
|
|||||||
var args = new ArrayList<>();
|
var args = new ArrayList<>();
|
||||||
applyValues(args);
|
applyValues(args);
|
||||||
applyConditions(args);
|
applyConditions(args);
|
||||||
|
applySorting();
|
||||||
return new CompiledRequest(sql.toString(),args);
|
return new CompiledRequest(sql.toString(),args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,6 +251,11 @@ public class Database {
|
|||||||
list.add(value);
|
list.add(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Request sort(String field) {
|
||||||
|
sortFields.add(field);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Database(Connection connection) {
|
public Database(Connection connection) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package de.srsoftware.widerhall.data;
|
package de.srsoftware.widerhall.data;
|
||||||
|
|
||||||
|
import de.srsoftware.widerhall.Configuration;
|
||||||
import de.srsoftware.widerhall.Util;
|
import de.srsoftware.widerhall.Util;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -11,8 +12,10 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.sql.Array;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -59,7 +62,9 @@ public class Post {
|
|||||||
var time = message.getSentDate().getTime();
|
var time = message.getSentDate().getTime();
|
||||||
|
|
||||||
Post post = new Post(id,list,fromEmail,fromName,subject,time);
|
Post post = new Post(id,list,fromEmail,fromName,subject,time);
|
||||||
Files.writeString(post.file().toPath(),text, StandardCharsets.UTF_8);
|
var file = post.file();
|
||||||
|
file.getParentFile().mkdirs();
|
||||||
|
Files.writeString(file.toPath(),text, StandardCharsets.UTF_8);
|
||||||
return post.save();
|
return post.save();
|
||||||
} catch (MessagingException | IOException | SQLException e) {
|
} catch (MessagingException | IOException | SQLException e) {
|
||||||
LOG.warn("Failed to create post from {}",message);
|
LOG.warn("Failed to create post from {}",message);
|
||||||
@@ -93,10 +98,10 @@ public class Post {
|
|||||||
return new File(filename);
|
return new File(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashSet<Post> find(MailingList list) throws SQLException {
|
public static ArrayList<Post> find(MailingList list) throws SQLException {
|
||||||
var rs = Database.open().select(TABLE_NAME).where(LIST,list.email()).compile().exec();
|
var rs = Database.open().select(TABLE_NAME).where(LIST,list.email()).sort(DATE).compile().exec();
|
||||||
try {
|
try {
|
||||||
var result = new HashSet<Post>();
|
var result = new ArrayList<Post>();
|
||||||
while (rs.next()) result.add(Post.from(rs));
|
while (rs.next()) result.add(Post.from(rs));
|
||||||
return result;
|
return result;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -111,6 +116,7 @@ public class Post {
|
|||||||
if (post == null) {
|
if (post == null) {
|
||||||
var list = MailingList.load(rs.getString(LIST));
|
var list = MailingList.load(rs.getString(LIST));
|
||||||
post = new Post(id, list, rs.getString(FROM_ADDR), rs.getString(FROM_NAME), rs.getString(SUBJECT), rs.getLong(DATE));
|
post = new Post(id, list, rs.getString(FROM_ADDR), rs.getString(FROM_NAME), rs.getString(SUBJECT), rs.getLong(DATE));
|
||||||
|
post.filename = rs.getString(FILE);
|
||||||
cache.put(id,post);
|
cache.put(id,post);
|
||||||
}
|
}
|
||||||
return post;
|
return post;
|
||||||
@@ -122,7 +128,7 @@ public class Post {
|
|||||||
|
|
||||||
|
|
||||||
private String generateFilename() {
|
private String generateFilename() {
|
||||||
return "/tmp/"+id+".json";
|
return Configuration.instance().archiveDir()+File.separator+id+".txt";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String id() {
|
public String id() {
|
||||||
|
|||||||
@@ -9,19 +9,15 @@ import org.json.simple.JSONObject;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.mail.MessagingException;
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static de.srsoftware.widerhall.Constants.*;
|
import static de.srsoftware.widerhall.Constants.*;
|
||||||
import static de.srsoftware.widerhall.Util.t;
|
import static de.srsoftware.widerhall.Util.t;
|
||||||
@@ -148,17 +144,17 @@ public class Rest extends HttpServlet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Long, Object> archive(HttpServletRequest req) {
|
private List<? extends Object> archive(HttpServletRequest req) {
|
||||||
var list = Util.getMailingList(req);
|
var list = Util.getMailingList(req);
|
||||||
if (list != null){
|
if (list != null){
|
||||||
try {
|
try {
|
||||||
return Post.find(list).stream().collect(Collectors.toMap(Post::timestamp,Post::safeMap));
|
return Post.find(list).stream().map(Post::safeMap).toList();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG.debug("list: {}",list.email());
|
LOG.debug("list: {}",list.email());
|
||||||
return Map.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String handlePost(HttpServletRequest req, HttpServletResponse resp){
|
public String handlePost(HttpServletRequest req, HttpServletResponse resp){
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ public class Web extends TemplateServlet {
|
|||||||
private static final String CONFIRM = "confirm";
|
private static final String CONFIRM = "confirm";
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(Web.class);
|
private static final Logger LOG = LoggerFactory.getLogger(Web.class);
|
||||||
private static final String ADMIN = "admin";
|
private static final String ADMIN = "admin";
|
||||||
private static final String ARCHIVE = "archive";
|
|
||||||
private static final String INSPECT = "inspect";
|
private static final String INSPECT = "inspect";
|
||||||
private static final String LOGIN = "login";
|
private static final String LOGIN = "login";
|
||||||
private static final String LOGOUT = "logout";
|
private static final String LOGOUT = "logout";
|
||||||
|
|||||||
Reference in New Issue
Block a user