Compare commits
9 commits
816eddd039
...
b773a0dde1
Author | SHA1 | Date | |
---|---|---|---|
b773a0dde1 | |||
3c1a049dd7 | |||
5509126896 | |||
2b3d812c00 | |||
c1e2f4c4f3 | |||
aaffdda371 | |||
ed6ff54537 | |||
255a4ede3e | |||
806aee663d |
24 changed files with 56 additions and 626 deletions
21
schema.sql
21
schema.sql
|
@ -86,4 +86,23 @@ BEGIN;
|
||||||
ALTER TABLE user_configs
|
ALTER TABLE user_configs
|
||||||
ADD COLUMN IF NOT EXISTS context_length INT NOT NULL DEFAULT 5;
|
ADD COLUMN IF NOT EXISTS context_length INT NOT NULL DEFAULT 5;
|
||||||
|
|
||||||
COMMIT
|
COMMIT;
|
||||||
|
|
||||||
|
-- Add time to config to know when it was added
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
ALTER TABLE server_configs
|
||||||
|
ADD COLUMN IF NOT EXISTS time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
|
ALTER TABLE user_configs
|
||||||
|
ADD COLUMN IF NOT EXISTS time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
|
-- Remove obsolete allowed tables that are being replaced the configs tables
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS allowed_servers;
|
||||||
|
DROP TABLE IF EXISTS allowed_users;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|
|
@ -2,9 +2,7 @@ package de.hhhammer.dchat;
|
||||||
|
|
||||||
import de.hhhammer.dchat.db.ServerDBService;
|
import de.hhhammer.dchat.db.ServerDBService;
|
||||||
import de.hhhammer.dchat.db.UserDBService;
|
import de.hhhammer.dchat.db.UserDBService;
|
||||||
import de.hhhammer.dchat.web.server.AllowedCrudHandler;
|
|
||||||
import de.hhhammer.dchat.web.server.ConfigCrudHandler;
|
import de.hhhammer.dchat.web.server.ConfigCrudHandler;
|
||||||
import de.hhhammer.dchat.web.user.AllowedUserCrudHandler;
|
|
||||||
import de.hhhammer.dchat.web.user.ConfigUserCrudHandler;
|
import de.hhhammer.dchat.web.user.ConfigUserCrudHandler;
|
||||||
import io.javalin.Javalin;
|
import io.javalin.Javalin;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -41,18 +39,19 @@ public class WebAPI implements Runnable {
|
||||||
event.serverStopping(() -> logger.info("Stopping web service"));
|
event.serverStopping(() -> logger.info("Stopping web service"));
|
||||||
event.serverStopped(() -> logger.info("Stopped web service"));
|
event.serverStopped(() -> logger.info("Stopped web service"));
|
||||||
});
|
});
|
||||||
|
app.before(ctx -> {
|
||||||
|
ctx.header("Access-Control-Allow-Origin", "*");
|
||||||
|
});
|
||||||
|
|
||||||
app.get("/", ctx -> ctx.result("""
|
app.get("/", ctx -> ctx.result("""
|
||||||
{ "message": "Hello World"}
|
{ "message": "Hello World"}
|
||||||
"""));
|
"""));
|
||||||
|
|
||||||
app.routes(() -> {
|
app.routes(() -> {
|
||||||
path("server", () -> {
|
path("servers", () -> {
|
||||||
crud("allowed/{id}", new AllowedCrudHandler(this.serverDBService));
|
|
||||||
crud("configs/{id}", new ConfigCrudHandler(this.serverDBService));
|
crud("configs/{id}", new ConfigCrudHandler(this.serverDBService));
|
||||||
});
|
});
|
||||||
path("user", () -> {
|
path("users", () -> {
|
||||||
crud("allowed/{id}", new AllowedUserCrudHandler(this.userDBService));
|
|
||||||
crud("configs/{id}", new ConfigUserCrudHandler(this.userDBService));
|
crud("configs/{id}", new ConfigUserCrudHandler(this.userDBService));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package de.hhhammer.dchat.db;
|
package de.hhhammer.dchat.db;
|
||||||
|
|
||||||
import de.hhhammer.dchat.db.models.server.AllowedServer;
|
|
||||||
import de.hhhammer.dchat.db.models.server.ServerConfig;
|
import de.hhhammer.dchat.db.models.server.ServerConfig;
|
||||||
import de.hhhammer.dchat.db.models.server.ServerMessage;
|
import de.hhhammer.dchat.db.models.server.ServerMessage;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -25,115 +24,6 @@ public class ServerDBService {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAllowed(long serverId) {
|
|
||||||
var getAllowedServerSql = """
|
|
||||||
SELECT * FROM allowed_servers WHERE server_id = ?
|
|
||||||
""";
|
|
||||||
try (Connection con = DriverManager.getConnection(this.jdbcConnectionString, this.username, this.password);
|
|
||||||
PreparedStatement pstmt = con.prepareStatement(getAllowedServerSql)
|
|
||||||
) {
|
|
||||||
pstmt.setLong(1, serverId);
|
|
||||||
ResultSet result = pstmt.executeQuery();
|
|
||||||
Iterable<AllowedServer> iterable = () -> new ResultSetIterator<>(result, new AllowedServer.AllowedServerResultSetTransformer());
|
|
||||||
return StreamSupport.stream(iterable.spliterator(), false).count() == 1;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
logger.error("Searching for allowed server with id: " + serverId, e);
|
|
||||||
} catch (ResultSetIteratorException e) {
|
|
||||||
logger.error("Iterating over AllowedServer ResultSet for server with id: " + serverId, e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<AllowedServer> getAllowedBy(long id) throws DBException {
|
|
||||||
var getAllowedServerSql = """
|
|
||||||
SELECT * FROM allowed_servers WHERE id = ?
|
|
||||||
""";
|
|
||||||
try (Connection con = DriverManager.getConnection(this.jdbcConnectionString, this.username, this.password);
|
|
||||||
PreparedStatement pstmt = con.prepareStatement(getAllowedServerSql)
|
|
||||||
) {
|
|
||||||
pstmt.setLong(1, id);
|
|
||||||
ResultSet result = pstmt.executeQuery();
|
|
||||||
Iterable<AllowedServer> iterable = () -> new ResultSetIterator<>(result, new AllowedServer.AllowedServerResultSetTransformer());
|
|
||||||
return StreamSupport.stream(iterable.spliterator(), false).findFirst();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DBException("Not found allowed server entry with id: " + id, e);
|
|
||||||
} catch (ResultSetIteratorException e) {
|
|
||||||
throw new DBException("Iterating over AllowedServer ResultSet searching for id: " + id, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<AllowedServer> getAllAllowed() throws DBException {
|
|
||||||
var getAllowedServerSql = """
|
|
||||||
SELECT * FROM allowed_servers
|
|
||||||
""";
|
|
||||||
try (Connection con = DriverManager.getConnection(this.jdbcConnectionString, this.username, this.password);
|
|
||||||
PreparedStatement pstmt = con.prepareStatement(getAllowedServerSql)
|
|
||||||
) {
|
|
||||||
ResultSet result = pstmt.executeQuery();
|
|
||||||
Iterable<AllowedServer> iterable = () -> new ResultSetIterator<>(result, new AllowedServer.AllowedServerResultSetTransformer());
|
|
||||||
return StreamSupport.stream(iterable.spliterator(), false).toList();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DBException("Not found allowed server entries", e);
|
|
||||||
} catch (ResultSetIteratorException e) {
|
|
||||||
throw new DBException("Iterating over AllowedServer ResultSet", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAllowed(AllowedServer.NewAllowedServer newAllowedServer) throws DBException {
|
|
||||||
var insertAllowedServerSql = """
|
|
||||||
INSERT INTO allowed_servers (server_id, comment) VALUES (?, ?)
|
|
||||||
""";
|
|
||||||
try (Connection con = DriverManager.getConnection(this.jdbcConnectionString, this.username, this.password);
|
|
||||||
PreparedStatement pstmt = con.prepareStatement(insertAllowedServerSql)
|
|
||||||
) {
|
|
||||||
pstmt.setLong(1, newAllowedServer.serverId());
|
|
||||||
pstmt.setString(2, newAllowedServer.comment());
|
|
||||||
int affectedRows = pstmt.executeUpdate();
|
|
||||||
if (affectedRows == 0) {
|
|
||||||
logger.error("No server inserted to allowed_servers with id: " + newAllowedServer.serverId());
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DBException("Allowing new server with id: " + newAllowedServer.serverId(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateAllowed(long id, AllowedServer.NewAllowedServer newAllowedServer) throws DBException {
|
|
||||||
var insertAllowedServerSql = """
|
|
||||||
UPDATE allowed_servers SET comment = ?, server_id = ? WHERE id = ?
|
|
||||||
""";
|
|
||||||
try (Connection con = DriverManager.getConnection(this.jdbcConnectionString, this.username, this.password);
|
|
||||||
PreparedStatement pstmt = con.prepareStatement(insertAllowedServerSql)
|
|
||||||
) {
|
|
||||||
pstmt.setString(1, newAllowedServer.comment());
|
|
||||||
pstmt.setLong(2, newAllowedServer.serverId());
|
|
||||||
pstmt.setLong(3, id);
|
|
||||||
int affectedRows = pstmt.executeUpdate();
|
|
||||||
if (affectedRows == 0) {
|
|
||||||
logger.error("No comment updated on server with id: " + newAllowedServer.serverId());
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DBException("Updating comment on allowed server with id: " + newAllowedServer.serverId(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteAllowed(long id) throws DBException {
|
|
||||||
var insertAllowedServerSql = """
|
|
||||||
DELETE FROM allowed_servers WHERE id = ?
|
|
||||||
""";
|
|
||||||
try (Connection con = DriverManager.getConnection(this.jdbcConnectionString, this.username, this.password);
|
|
||||||
PreparedStatement pstmt = con.prepareStatement(insertAllowedServerSql)
|
|
||||||
) {
|
|
||||||
pstmt.setLong(1, id);
|
|
||||||
int affectedRows = pstmt.executeUpdate();
|
|
||||||
if (affectedRows == 0) {
|
|
||||||
logger.error("No server deleted with id: " + id);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DBException("Deleting allowed server with id: " + id, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<ServerConfig> getConfig(long serverId) {
|
public Optional<ServerConfig> getConfig(long serverId) {
|
||||||
var getServerConfig = """
|
var getServerConfig = """
|
||||||
SELECT * FROM server_configs WHERE server_id = ?
|
SELECT * FROM server_configs WHERE server_id = ?
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package de.hhhammer.dchat.db;
|
package de.hhhammer.dchat.db;
|
||||||
|
|
||||||
import de.hhhammer.dchat.db.models.user.AllowedUser;
|
|
||||||
import de.hhhammer.dchat.db.models.user.UserConfig;
|
import de.hhhammer.dchat.db.models.user.UserConfig;
|
||||||
import de.hhhammer.dchat.db.models.user.UserMessage;
|
import de.hhhammer.dchat.db.models.user.UserMessage;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -25,114 +24,6 @@ public class UserDBService {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAllowed(long userId) {
|
|
||||||
var getAllowedServerSql = """
|
|
||||||
SELECT * FROM allowed_users WHERE user_id = ?
|
|
||||||
""";
|
|
||||||
try (Connection con = DriverManager.getConnection(this.jdbcConnectionString, this.username, this.password);
|
|
||||||
PreparedStatement pstmt = con.prepareStatement(getAllowedServerSql)
|
|
||||||
) {
|
|
||||||
pstmt.setLong(1, userId);
|
|
||||||
ResultSet result = pstmt.executeQuery();
|
|
||||||
Iterable<AllowedUser> iterable = () -> new ResultSetIterator<>(result, new AllowedUser.AllowedUserResultSetTransformer());
|
|
||||||
return StreamSupport.stream(iterable.spliterator(), false).count() == 1;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
logger.error("Searching for allowed user with id: " + userId, e);
|
|
||||||
} catch (ResultSetIteratorException e) {
|
|
||||||
logger.error("Iterating over AllowedServer ResultSet for user with id: " + userId, e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<AllowedUser> getAllowedBy(long id) throws DBException {
|
|
||||||
var getAllowedServerSql = """
|
|
||||||
SELECT * FROM allowed_users WHERE id = ?
|
|
||||||
""";
|
|
||||||
try (Connection con = DriverManager.getConnection(this.jdbcConnectionString, this.username, this.password);
|
|
||||||
PreparedStatement pstmt = con.prepareStatement(getAllowedServerSql)
|
|
||||||
) {
|
|
||||||
pstmt.setLong(1, id);
|
|
||||||
ResultSet result = pstmt.executeQuery();
|
|
||||||
Iterable<AllowedUser> iterable = () -> new ResultSetIterator<>(result, new AllowedUser.AllowedUserResultSetTransformer());
|
|
||||||
return StreamSupport.stream(iterable.spliterator(), false).findFirst();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DBException("Searching for allowed with id: " + id, e);
|
|
||||||
} catch (ResultSetIteratorException e) {
|
|
||||||
throw new DBException("Iterating over AllowedServer ResultSet with id: " + id, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<AllowedUser> getAllAllowed() throws DBException {
|
|
||||||
var getAllowedServerSql = """
|
|
||||||
SELECT * FROM allowed_users
|
|
||||||
""";
|
|
||||||
try (Connection con = DriverManager.getConnection(this.jdbcConnectionString, this.username, this.password);
|
|
||||||
PreparedStatement pstmt = con.prepareStatement(getAllowedServerSql)
|
|
||||||
) {
|
|
||||||
ResultSet result = pstmt.executeQuery();
|
|
||||||
Iterable<AllowedUser> iterable = () -> new ResultSetIterator<>(result, new AllowedUser.AllowedUserResultSetTransformer());
|
|
||||||
return StreamSupport.stream(iterable.spliterator(), false).toList();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DBException("Searching all allowed users", e);
|
|
||||||
} catch (ResultSetIteratorException e) {
|
|
||||||
throw new DBException("Iterating over all AllowedServer ResultSet ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAllowed(AllowedUser.NewAllowedUser newAllowedUser) throws DBException {
|
|
||||||
var insertAllowedServerSql = """
|
|
||||||
INSERT INTO allowed_users (user_id, comment) VALUES (?, ?)
|
|
||||||
""";
|
|
||||||
try (Connection con = DriverManager.getConnection(this.jdbcConnectionString, this.username, this.password);
|
|
||||||
PreparedStatement pstmt = con.prepareStatement(insertAllowedServerSql)
|
|
||||||
) {
|
|
||||||
pstmt.setLong(1, newAllowedUser.userId());
|
|
||||||
pstmt.setString(2, newAllowedUser.comment());
|
|
||||||
int affectedRows = pstmt.executeUpdate();
|
|
||||||
if (affectedRows == 0) {
|
|
||||||
logger.error("No server inserted to allowed_users with id: " + newAllowedUser.userId());
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DBException("Allowing new user with id: " + newAllowedUser.userId(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateAllowed(long id, AllowedUser.NewAllowedUser newAllowedUser) throws DBException {
|
|
||||||
var insertAllowedServerSql = """
|
|
||||||
UPDATE allowed_users SET comment = ? WHERE id = ?
|
|
||||||
""";
|
|
||||||
try (Connection con = DriverManager.getConnection(this.jdbcConnectionString, this.username, this.password);
|
|
||||||
PreparedStatement pstmt = con.prepareStatement(insertAllowedServerSql)
|
|
||||||
) {
|
|
||||||
pstmt.setString(1, newAllowedUser.comment());
|
|
||||||
pstmt.setLong(2, id);
|
|
||||||
int affectedRows = pstmt.executeUpdate();
|
|
||||||
if (affectedRows == 0) {
|
|
||||||
logger.error("No comment updated on user with id: " + newAllowedUser.userId());
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DBException("Updating comment on allowed user with id: " + id, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteAllowed(long id) throws DBException {
|
|
||||||
var insertAllowedServerSql = """
|
|
||||||
DELETE FROM allowed_users WHERE id = ?
|
|
||||||
""";
|
|
||||||
try (Connection con = DriverManager.getConnection(this.jdbcConnectionString, this.username, this.password);
|
|
||||||
PreparedStatement pstmt = con.prepareStatement(insertAllowedServerSql)
|
|
||||||
) {
|
|
||||||
pstmt.setLong(1, id);
|
|
||||||
int affectedRows = pstmt.executeUpdate();
|
|
||||||
if (affectedRows == 0) {
|
|
||||||
logger.error("No user deleted with id: " + id);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DBException("Deleting allowed user with id: " + id, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<UserConfig> getConfig(long userId) {
|
public Optional<UserConfig> getConfig(long userId) {
|
||||||
var getServerConfig = """
|
var getServerConfig = """
|
||||||
SELECT * FROM user_configs WHERE user_id = ?
|
SELECT * FROM user_configs WHERE user_id = ?
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
package de.hhhammer.dchat.db.models.server;
|
|
||||||
|
|
||||||
import de.hhhammer.dchat.db.ResultSetTransformer;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.time.Instant;
|
|
||||||
|
|
||||||
public record AllowedServer(long id, long serverId, Instant time, @Nullable String comment) {
|
|
||||||
|
|
||||||
public static class AllowedServerResultSetTransformer implements ResultSetTransformer<AllowedServer> {
|
|
||||||
@Override
|
|
||||||
public AllowedServer transform(ResultSet resultSet) throws SQLException {
|
|
||||||
var id = resultSet.getLong("id");
|
|
||||||
var serverId = resultSet.getLong("server_id");
|
|
||||||
var time = resultSet.getTimestamp("time").toInstant();
|
|
||||||
var comment = resultSet.getString("comment");
|
|
||||||
return new AllowedServer(id, serverId, time, comment);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public record NewAllowedServer(long serverId, @Nullable String comment) {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,8 +5,9 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
public record ServerConfig(long id, long serverId, String systemMessage, int rateLimit) {
|
public record ServerConfig(long id, long serverId, String systemMessage, int rateLimit, Instant time) {
|
||||||
|
|
||||||
public static class ServerConfigResultSetTransformer implements ResultSetTransformer<ServerConfig> {
|
public static class ServerConfigResultSetTransformer implements ResultSetTransformer<ServerConfig> {
|
||||||
|
|
||||||
|
@ -16,7 +17,8 @@ public record ServerConfig(long id, long serverId, String systemMessage, int rat
|
||||||
var serverId = resultSet.getLong("server_id");
|
var serverId = resultSet.getLong("server_id");
|
||||||
var systemMessage = resultSet.getString("system_message");
|
var systemMessage = resultSet.getString("system_message");
|
||||||
var rateLimit = resultSet.getInt("rate_limit");
|
var rateLimit = resultSet.getInt("rate_limit");
|
||||||
return new ServerConfig(id, serverId, systemMessage, rateLimit);
|
var time = resultSet.getTimestamp("time").toInstant();
|
||||||
|
return new ServerConfig(id, serverId, systemMessage, rateLimit, time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
package de.hhhammer.dchat.db.models.user;
|
|
||||||
|
|
||||||
import de.hhhammer.dchat.db.ResultSetTransformer;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.time.Instant;
|
|
||||||
|
|
||||||
public record AllowedUser(long id, long userId, Instant time, @Nullable String comment) {
|
|
||||||
|
|
||||||
public static class AllowedUserResultSetTransformer implements ResultSetTransformer<AllowedUser> {
|
|
||||||
@Override
|
|
||||||
public AllowedUser transform(ResultSet resultSet) throws SQLException {
|
|
||||||
var id = resultSet.getLong("id");
|
|
||||||
var userId = resultSet.getLong("user_id");
|
|
||||||
var time = resultSet.getTimestamp("time").toInstant();
|
|
||||||
var comment = resultSet.getString("comment");
|
|
||||||
return new AllowedUser(id, userId, time, comment);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public record NewAllowedUser(long userId, @Nullable String comment) {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,8 +5,9 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
public record UserConfig(long id, long userId, String systemMessage, int contextLength, int rateLimit) {
|
public record UserConfig(long id, long userId, String systemMessage, int contextLength, int rateLimit, Instant time) {
|
||||||
|
|
||||||
public static class UserConfigResultSetTransformer implements ResultSetTransformer<UserConfig> {
|
public static class UserConfigResultSetTransformer implements ResultSetTransformer<UserConfig> {
|
||||||
|
|
||||||
|
@ -17,7 +18,8 @@ public record UserConfig(long id, long userId, String systemMessage, int context
|
||||||
var systemMessage = resultSet.getString("system_message");
|
var systemMessage = resultSet.getString("system_message");
|
||||||
var contextLength = resultSet.getInt("context_length");
|
var contextLength = resultSet.getInt("context_length");
|
||||||
var rateLimit = resultSet.getInt("rate_limit");
|
var rateLimit = resultSet.getInt("rate_limit");
|
||||||
return new UserConfig(id, userId, systemMessage, contextLength, rateLimit);
|
var time = resultSet.getTimestamp("time").toInstant();
|
||||||
|
return new UserConfig(id, userId, systemMessage, contextLength, rateLimit, time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,18 +56,19 @@ public class ServerMessageHandler implements MessageHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAllowed(MessageCreateEvent event) {
|
public boolean isAllowed(MessageCreateEvent event) {
|
||||||
if (event.getServer().isPresent()) {
|
if (event.getServer().isEmpty()) {
|
||||||
var serverId = event.getServer().get().getId();
|
|
||||||
var allowed = this.serverDBService.isAllowed(serverId);
|
|
||||||
if (!allowed) {
|
|
||||||
logger.debug("Not allowed with id: " + serverId);
|
|
||||||
}
|
|
||||||
return allowed;
|
|
||||||
}
|
|
||||||
// only support server messages
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var serverId = event.getServer().get().getId();
|
||||||
|
var config = this.serverDBService.getConfig(serverId);
|
||||||
|
if (config.isEmpty()) {
|
||||||
|
logger.debug("Not allowed with id: " + serverId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean exceedsRate(MessageCreateEvent event) {
|
public boolean exceedsRate(MessageCreateEvent event) {
|
||||||
var serverId = event.getServer().get().getId();
|
var serverId = event.getServer().get().getId();
|
||||||
|
|
|
@ -47,11 +47,12 @@ public class UserMessageHandler implements MessageHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
var userId = event.getMessageAuthor().getId();
|
var userId = event.getMessageAuthor().getId();
|
||||||
var allowed = this.userDBService.isAllowed(userId);
|
var config = this.userDBService.getConfig(userId);
|
||||||
if (!allowed) {
|
if (config.isEmpty()) {
|
||||||
logger.debug("Not allowed with id: " + userId);
|
logger.debug("Not allowed with id: " + userId);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return allowed;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
package de.hhhammer.dchat.web.server;
|
|
||||||
|
|
||||||
import de.hhhammer.dchat.db.DBException;
|
|
||||||
import de.hhhammer.dchat.db.ServerDBService;
|
|
||||||
import de.hhhammer.dchat.db.models.server.AllowedServer;
|
|
||||||
import io.javalin.apibuilder.CrudHandler;
|
|
||||||
import io.javalin.http.Context;
|
|
||||||
import io.javalin.http.HttpStatus;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class AllowedCrudHandler implements CrudHandler {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(AllowedCrudHandler.class);
|
|
||||||
|
|
||||||
private final ServerDBService serverDBService;
|
|
||||||
|
|
||||||
public AllowedCrudHandler(ServerDBService serverDBService) {
|
|
||||||
this.serverDBService = serverDBService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void create(@NotNull Context context) {
|
|
||||||
var body = context.bodyAsClass(AllowedServer.NewAllowedServer.class);
|
|
||||||
try {
|
|
||||||
this.serverDBService.addAllowed(body);
|
|
||||||
} catch (DBException e) {
|
|
||||||
logger.error("Adding new allowed server", e);
|
|
||||||
context.status(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
context.status(HttpStatus.CREATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delete(@NotNull Context context, @NotNull String s) {
|
|
||||||
try {
|
|
||||||
this.serverDBService.deleteAllowed(Long.parseLong(s));
|
|
||||||
context.status(HttpStatus.NO_CONTENT);
|
|
||||||
} catch (DBException e) {
|
|
||||||
logger.error("Deleting server with id: " + s, e);
|
|
||||||
context.status(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getAll(@NotNull Context context) {
|
|
||||||
try {
|
|
||||||
var allowedServers = this.serverDBService.getAllAllowed();
|
|
||||||
context.json(allowedServers);
|
|
||||||
} catch (DBException e) {
|
|
||||||
logger.error("Getting all allowed servers", e);
|
|
||||||
context.status(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getOne(@NotNull Context context, @NotNull String s) {
|
|
||||||
var id = Long.parseLong(s);
|
|
||||||
try {
|
|
||||||
var server = this.serverDBService.getAllowedBy(id);
|
|
||||||
if (server.isEmpty()) {
|
|
||||||
context.status(HttpStatus.NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
context.json(server.get());
|
|
||||||
} catch (DBException e) {
|
|
||||||
logger.error("Searching with id: " + s, e);
|
|
||||||
context.status(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(@NotNull Context context, @NotNull String idString) {
|
|
||||||
var newAllowedServer = context.bodyAsClass(AllowedServer.NewAllowedServer.class);
|
|
||||||
var id = Long.parseLong(idString);
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.serverDBService.updateAllowed(id, newAllowedServer);
|
|
||||||
} catch (DBException e) {
|
|
||||||
logger.error("Updating allowed server with id: " + idString, e);
|
|
||||||
context.status(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,84 +0,0 @@
|
||||||
package de.hhhammer.dchat.web.user;
|
|
||||||
|
|
||||||
import de.hhhammer.dchat.db.DBException;
|
|
||||||
import de.hhhammer.dchat.db.UserDBService;
|
|
||||||
import de.hhhammer.dchat.db.models.user.AllowedUser;
|
|
||||||
import io.javalin.apibuilder.CrudHandler;
|
|
||||||
import io.javalin.http.Context;
|
|
||||||
import io.javalin.http.HttpStatus;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class AllowedUserCrudHandler implements CrudHandler {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(AllowedUserCrudHandler.class);
|
|
||||||
|
|
||||||
private final UserDBService userDBService;
|
|
||||||
|
|
||||||
public AllowedUserCrudHandler(UserDBService userDBService) {
|
|
||||||
this.userDBService = userDBService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void create(@NotNull Context context) {
|
|
||||||
var body = context.bodyAsClass(AllowedUser.NewAllowedUser.class);
|
|
||||||
try {
|
|
||||||
this.userDBService.addAllowed(body);
|
|
||||||
} catch (DBException e) {
|
|
||||||
logger.error("Adding new server configuration", e);
|
|
||||||
context.status(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
context.status(HttpStatus.CREATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delete(@NotNull Context context, @NotNull String s) {
|
|
||||||
try {
|
|
||||||
this.userDBService.deleteAllowed(Long.parseLong(s));
|
|
||||||
context.status(HttpStatus.NO_CONTENT);
|
|
||||||
} catch (DBException e) {
|
|
||||||
logger.error("Deleting configuration with id: " + s, e);
|
|
||||||
context.status(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getAll(@NotNull Context context) {
|
|
||||||
try {
|
|
||||||
var allowedServers = this.userDBService.getAllAllowed();
|
|
||||||
context.json(allowedServers);
|
|
||||||
} catch (DBException e) {
|
|
||||||
logger.error("Getting all server configs", e);
|
|
||||||
context.status(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getOne(@NotNull Context context, @NotNull String s) {
|
|
||||||
var id = Long.parseLong(s);
|
|
||||||
try {
|
|
||||||
var server = this.userDBService.getAllowedBy(id);
|
|
||||||
if (server.isEmpty()) {
|
|
||||||
context.status(HttpStatus.NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
context.json(server.get());
|
|
||||||
} catch (DBException e) {
|
|
||||||
logger.error("Searching for config with id: " + s, e);
|
|
||||||
context.status(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(@NotNull Context context, @NotNull String idString) {
|
|
||||||
var body = context.bodyAsClass(AllowedUser.NewAllowedUser.class);
|
|
||||||
var id = Long.parseLong(idString);
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.userDBService.updateAllowed(id, body);
|
|
||||||
} catch (DBException e) {
|
|
||||||
logger.error("Updating allowed server with id: " + idString, e);
|
|
||||||
context.status(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,7 +22,9 @@ import { RouterView } from 'vue-router'
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
<Suspense>
|
||||||
<RouterView />
|
<RouterView />
|
||||||
|
</Suspense>
|
||||||
<footer class="footer footer-center p-4 bg-base-300 text-base-content">
|
<footer class="footer footer-center p-4 bg-base-300 text-base-content">
|
||||||
<div>
|
<div>
|
||||||
<p>Copyright © 2023 Augusto Dwenger J.</p>
|
<p>Copyright © 2023 Augusto Dwenger J.</p>
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
export type ServerAllowed = {
|
|
||||||
id: number,
|
|
||||||
serverId: number,
|
|
||||||
time: string,
|
|
||||||
comment: string
|
|
||||||
}
|
|
|
@ -1,15 +1,9 @@
|
||||||
import { createRouter, createWebHistory } from 'vue-router'
|
import { createRouter, createWebHistory } from 'vue-router'
|
||||||
import HomeView from '@/views/HomeView.vue'
|
import HomeView from '@/views/HomeView.vue'
|
||||||
import AllowedServersView from '@/views/servers/AllowedServersView.vue'
|
|
||||||
import IndexServersView from '@/views/servers/IndexServersView.vue'
|
import IndexServersView from '@/views/servers/IndexServersView.vue'
|
||||||
import ServerConfigsView from '@/views/servers/ServerConfigsView.vue'
|
import ServerConfigsView from '@/views/servers/ServerConfigsView.vue'
|
||||||
import ServersMessagesView from '@/views/servers/ServersMessagesView.vue'
|
|
||||||
import ServerMessagesView from '@/views/servers/ServerMessagesView.vue'
|
|
||||||
import AllowedUsersView from '@/views/users/AllowedUsersView.vue'
|
|
||||||
import IndexUsersView from '@/views/users/IndexUsersView.vue'
|
import IndexUsersView from '@/views/users/IndexUsersView.vue'
|
||||||
import UserConfigsView from '@/views/users/UserConfigsView.vue'
|
import UserConfigsView from '@/views/users/UserConfigsView.vue'
|
||||||
import UsersMessagesView from '@/views/users/UsersMessagesView.vue'
|
|
||||||
import UserMessagesView from '@/views/users/UserMessagesView.vue'
|
|
||||||
|
|
||||||
const routerConfig = createRouter({
|
const routerConfig = createRouter({
|
||||||
history: createWebHistory(import.meta.env.BASE_URL),
|
history: createWebHistory(import.meta.env.BASE_URL),
|
||||||
|
@ -24,50 +18,20 @@ const routerConfig = createRouter({
|
||||||
name: 'servers',
|
name: 'servers',
|
||||||
component: IndexServersView
|
component: IndexServersView
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: '/servers/allowed',
|
|
||||||
name: 'allowedServers',
|
|
||||||
component: AllowedServersView
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: '/servers/configs',
|
path: '/servers/configs',
|
||||||
name: 'serverConfigs',
|
name: 'serverConfigs',
|
||||||
component: ServerConfigsView
|
component: ServerConfigsView
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: '/servers/messages',
|
|
||||||
name: 'serversMessages',
|
|
||||||
component: ServersMessagesView
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/servers/messages/:serverId(\\d+)',
|
|
||||||
name: 'serverMessages',
|
|
||||||
component: ServerMessagesView
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: '/users',
|
path: '/users',
|
||||||
name: 'users',
|
name: 'users',
|
||||||
component: IndexUsersView
|
component: IndexUsersView
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: '/users/allowed',
|
|
||||||
name: 'allowedUsers',
|
|
||||||
component: AllowedUsersView
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: '/users/configs',
|
path: '/users/configs',
|
||||||
name: 'userConfigs',
|
name: 'userConfigs',
|
||||||
component: UserConfigsView
|
component: UserConfigsView
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/users/messages',
|
|
||||||
name: 'usersMessages',
|
|
||||||
component: UsersMessagesView
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/users/messages/:userId(\\d+)',
|
|
||||||
name: 'userMessages',
|
|
||||||
component: UserMessagesView
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
<script setup lang="ts">
|
|
||||||
import TableComponent from '@/components/TableComponent.vue';
|
|
||||||
|
|
||||||
const tableHeader = ["ID", "User", "Comment", "Date"]
|
|
||||||
const tableRows = [["1", "name", "comment", Date.now()]]
|
|
||||||
const actions = [{ class: "btn btn-sm btn-info m-1", content: "Edit", event: (_: number) => { } }, { class: "btn btn-sm btn-error m-1", content: "Delete", event: (_: number) => { } }]
|
|
||||||
</script>
|
|
||||||
<template>
|
|
||||||
<div class="flex justify-between m-5">
|
|
||||||
<h1 class="text-xl normal-case">Allowed Servers</h1>
|
|
||||||
<button class="btn btn-circle btn-success">Add</button>
|
|
||||||
</div>
|
|
||||||
<TableComponent :tableHeader="tableHeader" :tableRows="tableRows" :actions="actions" />
|
|
||||||
</template>
|
|
|
@ -4,15 +4,9 @@
|
||||||
<h1 class="text-xl normal-case m-5">Server overview</h1>
|
<h1 class="text-xl normal-case m-5">Server overview</h1>
|
||||||
<div class="flex justify-center m-4">
|
<div class="flex justify-center m-4">
|
||||||
<div class="flex flex-col space-y-2">
|
<div class="flex flex-col space-y-2">
|
||||||
<RouterLink to="/servers/allowed">
|
|
||||||
<button class="btn btn-wide btn-outline">Allowed</button>
|
|
||||||
</RouterLink>
|
|
||||||
<RouterLink to="/servers/configs">
|
<RouterLink to="/servers/configs">
|
||||||
<button class="btn btn-wide btn-outline">Configs</button>
|
<button class="btn btn-wide btn-outline">Configs</button>
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
<RouterLink to="/servers/messages">
|
|
||||||
<button class="btn btn-wide btn-outline">Server with Messages</button>
|
|
||||||
</RouterLink>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import TableComponent from '@/components/TableComponent.vue';
|
import TableComponent from '@/components/TableComponent.vue';
|
||||||
|
import {getConfigs} from '@/services/ServerConfigs'
|
||||||
|
|
||||||
const tableHeader = ["ID", "Server ID", "System Message", "Rate limit"]
|
const serverConfigs = await getConfigs()
|
||||||
const tableRows = [["1", "name", "comment", "1"]]
|
const tableHeader = ["ID", "Server ID", "System Message", "Rate limit", "Created"]
|
||||||
|
const tableRows = serverConfigs.map(config => [config.id, config.serverId, config.systemMessage.slice(0, 47) + "...", config.rateLimit, config.time])
|
||||||
const actions = [{ class: "btn btn-sm btn-info m-1", content: "Edit", event: (_: number) => { } }, { class: "btn btn-sm btn-error m-1", content: "Delete", event: (_: number) => { } }]
|
const actions = [{ class: "btn btn-sm btn-info m-1", content: "Edit", event: (_: number) => { } }, { class: "btn btn-sm btn-error m-1", content: "Delete", event: (_: number) => { } }]
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
|
@ -10,5 +12,6 @@ const actions = [{ class: "btn btn-sm btn-info m-1", content: "Edit", event: (_:
|
||||||
<h1 class="text-xl normal-case">Server Configs</h1>
|
<h1 class="text-xl normal-case">Server Configs</h1>
|
||||||
<button class="btn btn-circle btn-success">Add</button>
|
<button class="btn btn-circle btn-success">Add</button>
|
||||||
</div>
|
</div>
|
||||||
<TableComponent :tableHeader="tableHeader" :tableRows="tableRows" :actions="actions" />
|
<TableComponent v-if="serverConfigs.length" :tableHeader="tableHeader" :tableRows="tableRows" :actions="actions" />
|
||||||
|
<p v-else class="m-5">No server configs</p>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
<script setup lang="ts">
|
|
||||||
import TableComponent from '@/components/TableComponent.vue';
|
|
||||||
import { useRoute } from 'vue-router';
|
|
||||||
|
|
||||||
const router = useRoute()
|
|
||||||
const { serverId } = router.params
|
|
||||||
const tableHeader = ["ID", "Server ID", "User ID", "Tokens", "Date"]
|
|
||||||
const tableRows = [["1", "name", "comment", "2", Date.now()]]
|
|
||||||
</script>
|
|
||||||
<template>
|
|
||||||
<div class="flex justify-between m-5">
|
|
||||||
<h1 class="text-xl normal-case">Server Messages</h1>
|
|
||||||
<h1 class="text-xl normal-case">Server ID: {{ serverId }}</h1>
|
|
||||||
</div>
|
|
||||||
<TableComponent :tableHeader="tableHeader" :tableRows="tableRows" />
|
|
||||||
</template>
|
|
|
@ -1,24 +0,0 @@
|
||||||
<script setup lang="ts">
|
|
||||||
import TableComponent from '@/components/TableComponent.vue';
|
|
||||||
import { useRouter } from 'vue-router';
|
|
||||||
import { provide } from 'vue';
|
|
||||||
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const tableHeader = ["ID", "Server ID"]
|
|
||||||
const tableRows = [["1", "1234567890"]]
|
|
||||||
|
|
||||||
const view = (index: number) => {
|
|
||||||
const row = tableRows[index]
|
|
||||||
const id = row[0]
|
|
||||||
router.push("/servers/messages/" + id)
|
|
||||||
}
|
|
||||||
|
|
||||||
const actions = [{ class: "btn btn-sm btn-info m-1", content: "View", event: view }]
|
|
||||||
</script>
|
|
||||||
<template>
|
|
||||||
<div class="flex justify-between m-5">
|
|
||||||
<h1 class="text-xl normal-case">Server with Messages</h1>
|
|
||||||
</div>
|
|
||||||
<TableComponent :tableHeader="tableHeader" :tableRows="tableRows" :actions="actions" />
|
|
||||||
</template>
|
|
|
@ -1,14 +0,0 @@
|
||||||
<script setup lang="ts">
|
|
||||||
import TableComponent from '@/components/TableComponent.vue';
|
|
||||||
|
|
||||||
const tableHeader = ["ID", "User", "Comment", "Date"]
|
|
||||||
const tableRows = [["1", "name", "comment", Date.now()]]
|
|
||||||
const actions = [{ class: "btn btn-sm btn-info m-1", content: "Edit", event: (_: number) => { } }, { class: "btn btn-sm btn-error m-1", content: "Delete", event: (_: number) => { } }]
|
|
||||||
</script>
|
|
||||||
<template>
|
|
||||||
<div class="flex justify-between m-5">
|
|
||||||
<h1 class="text-xl normal-case">Allowed Users</h1>
|
|
||||||
<button class="btn btn-circle btn-success">Add</button>
|
|
||||||
</div>
|
|
||||||
<TableComponent :tableHeader="tableHeader" :tableRows="tableRows" :actions="actions" />
|
|
||||||
</template>
|
|
|
@ -4,15 +4,9 @@
|
||||||
<h1 class="text-xl normal-case m-5">Server overview</h1>
|
<h1 class="text-xl normal-case m-5">Server overview</h1>
|
||||||
<div class="flex justify-center m-4">
|
<div class="flex justify-center m-4">
|
||||||
<div class="flex flex-col space-y-2">
|
<div class="flex flex-col space-y-2">
|
||||||
<RouterLink to="/users/allowed">
|
|
||||||
<button class="btn btn-wide btn-outline">Allowed</button>
|
|
||||||
</RouterLink>
|
|
||||||
<RouterLink to="/users/configs">
|
<RouterLink to="/users/configs">
|
||||||
<button class="btn btn-wide btn-outline">Configs</button>
|
<button class="btn btn-wide btn-outline">Configs</button>
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
<RouterLink to="/users/messages">
|
|
||||||
<button class="btn btn-wide btn-outline">User with Messages</button>
|
|
||||||
</RouterLink>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
<script setup lang="ts">
|
|
||||||
import TableComponent from '@/components/TableComponent.vue';
|
|
||||||
import { useRoute } from 'vue-router';
|
|
||||||
|
|
||||||
const router = useRoute()
|
|
||||||
const { userId } = router.params
|
|
||||||
const tableHeader = ["ID", "Server ID", "User ID", "Tokens", "Date"]
|
|
||||||
const tableRows = [["1", "name", "comment", "2", Date.now()]]
|
|
||||||
</script>
|
|
||||||
<template>
|
|
||||||
<div class="flex justify-between m-5">
|
|
||||||
<h1 class="text-xl normal-case">User Messages</h1>
|
|
||||||
<h1 class="text-xl normal-case">User ID: {{ userId }}</h1>
|
|
||||||
</div>
|
|
||||||
<TableComponent :tableHeader="tableHeader" :tableRows="tableRows" />
|
|
||||||
</template>
|
|
|
@ -1,24 +0,0 @@
|
||||||
<script setup lang="ts">
|
|
||||||
import TableComponent from '@/components/TableComponent.vue';
|
|
||||||
import { useRouter } from 'vue-router';
|
|
||||||
import { provide } from 'vue';
|
|
||||||
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const tableHeader = ["ID", "Server ID"]
|
|
||||||
const tableRows = [["1", "1234567890"]]
|
|
||||||
|
|
||||||
const view = (index: number) => {
|
|
||||||
const row = tableRows[index]
|
|
||||||
const id = row[0]
|
|
||||||
router.push("/servers/messages/" + id)
|
|
||||||
}
|
|
||||||
|
|
||||||
const actions = [{ class: "btn btn-sm btn-info m-1", content: "View", event: view }]
|
|
||||||
</script>
|
|
||||||
<template>
|
|
||||||
<div class="flex justify-between m-5">
|
|
||||||
<h1 class="text-xl normal-case">Users with Messages</h1>
|
|
||||||
</div>
|
|
||||||
<TableComponent :tableHeader="tableHeader" :tableRows="tableRows" :actions="actions" />
|
|
||||||
</template>
|
|
Loading…
Reference in a new issue