Compare commits

..

No commits in common. "b773a0dde1d3dca87d743fb757d4231efeab178d" and "816eddd039f7b79f95761e5684551aad29f1504d" have entirely different histories.

24 changed files with 626 additions and 56 deletions

View file

@ -86,23 +86,4 @@ BEGIN;
ALTER TABLE user_configs
ADD COLUMN IF NOT EXISTS context_length INT NOT NULL DEFAULT 5;
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;
COMMIT

View file

@ -2,7 +2,9 @@ package de.hhhammer.dchat;
import de.hhhammer.dchat.db.ServerDBService;
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.user.AllowedUserCrudHandler;
import de.hhhammer.dchat.web.user.ConfigUserCrudHandler;
import io.javalin.Javalin;
import org.slf4j.Logger;
@ -39,19 +41,18 @@ public class WebAPI implements Runnable {
event.serverStopping(() -> logger.info("Stopping web service"));
event.serverStopped(() -> logger.info("Stopped web service"));
});
app.before(ctx -> {
ctx.header("Access-Control-Allow-Origin", "*");
});
app.get("/", ctx -> ctx.result("""
{ "message": "Hello World"}
"""));
app.routes(() -> {
path("servers", () -> {
path("server", () -> {
crud("allowed/{id}", new AllowedCrudHandler(this.serverDBService));
crud("configs/{id}", new ConfigCrudHandler(this.serverDBService));
});
path("users", () -> {
path("user", () -> {
crud("allowed/{id}", new AllowedUserCrudHandler(this.userDBService));
crud("configs/{id}", new ConfigUserCrudHandler(this.userDBService));
});
});

View file

@ -1,5 +1,6 @@
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.ServerMessage;
import org.slf4j.Logger;
@ -24,6 +25,115 @@ public class ServerDBService {
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) {
var getServerConfig = """
SELECT * FROM server_configs WHERE server_id = ?

View file

@ -1,5 +1,6 @@
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.UserMessage;
import org.slf4j.Logger;
@ -24,6 +25,114 @@ public class UserDBService {
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) {
var getServerConfig = """
SELECT * FROM user_configs WHERE user_id = ?

View file

@ -0,0 +1,25 @@
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) {
}
}

View file

@ -5,9 +5,8 @@ import org.jetbrains.annotations.Nullable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.Instant;
public record ServerConfig(long id, long serverId, String systemMessage, int rateLimit, Instant time) {
public record ServerConfig(long id, long serverId, String systemMessage, int rateLimit) {
public static class ServerConfigResultSetTransformer implements ResultSetTransformer<ServerConfig> {
@ -17,8 +16,7 @@ public record ServerConfig(long id, long serverId, String systemMessage, int rat
var serverId = resultSet.getLong("server_id");
var systemMessage = resultSet.getString("system_message");
var rateLimit = resultSet.getInt("rate_limit");
var time = resultSet.getTimestamp("time").toInstant();
return new ServerConfig(id, serverId, systemMessage, rateLimit, time);
return new ServerConfig(id, serverId, systemMessage, rateLimit);
}
}

View file

@ -0,0 +1,25 @@
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) {
}
}

View file

@ -5,9 +5,8 @@ import org.jetbrains.annotations.Nullable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.Instant;
public record UserConfig(long id, long userId, String systemMessage, int contextLength, int rateLimit, Instant time) {
public record UserConfig(long id, long userId, String systemMessage, int contextLength, int rateLimit) {
public static class UserConfigResultSetTransformer implements ResultSetTransformer<UserConfig> {
@ -18,8 +17,7 @@ public record UserConfig(long id, long userId, String systemMessage, int context
var systemMessage = resultSet.getString("system_message");
var contextLength = resultSet.getInt("context_length");
var rateLimit = resultSet.getInt("rate_limit");
var time = resultSet.getTimestamp("time").toInstant();
return new UserConfig(id, userId, systemMessage, contextLength, rateLimit, time);
return new UserConfig(id, userId, systemMessage, contextLength, rateLimit);
}
}

View file

@ -56,17 +56,16 @@ public class ServerMessageHandler implements MessageHandler {
@Override
public boolean isAllowed(MessageCreateEvent event) {
if (event.getServer().isEmpty()) {
return false;
}
if (event.getServer().isPresent()) {
var serverId = event.getServer().get().getId();
var config = this.serverDBService.getConfig(serverId);
if (config.isEmpty()) {
var allowed = this.serverDBService.isAllowed(serverId);
if (!allowed) {
logger.debug("Not allowed with id: " + serverId);
return false;
}
return true;
return allowed;
}
// only support server messages
return false;
}
@Override

View file

@ -47,12 +47,11 @@ public class UserMessageHandler implements MessageHandler {
}
var userId = event.getMessageAuthor().getId();
var config = this.userDBService.getConfig(userId);
if (config.isEmpty()) {
var allowed = this.userDBService.isAllowed(userId);
if (!allowed) {
logger.debug("Not allowed with id: " + userId);
return false;
}
return true;
return allowed;
}
@Override

View file

@ -0,0 +1,84 @@
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);
}
}
}

View file

@ -0,0 +1,84 @@
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);
}
}
}

View file

@ -22,9 +22,7 @@ import { RouterView } from 'vue-router'
</div>
</div>
</header>
<Suspense>
<RouterView />
</Suspense>
<footer class="footer footer-center p-4 bg-base-300 text-base-content">
<div>
<p>Copyright © 2023 Augusto Dwenger J.</p>

View file

@ -0,0 +1,6 @@
export type ServerAllowed = {
id: number,
serverId: number,
time: string,
comment: string
}

View file

@ -1,9 +1,15 @@
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '@/views/HomeView.vue'
import AllowedServersView from '@/views/servers/AllowedServersView.vue'
import IndexServersView from '@/views/servers/IndexServersView.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 UserConfigsView from '@/views/users/UserConfigsView.vue'
import UsersMessagesView from '@/views/users/UsersMessagesView.vue'
import UserMessagesView from '@/views/users/UserMessagesView.vue'
const routerConfig = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
@ -18,20 +24,50 @@ const routerConfig = createRouter({
name: 'servers',
component: IndexServersView
},
{
path: '/servers/allowed',
name: 'allowedServers',
component: AllowedServersView
},
{
path: '/servers/configs',
name: 'serverConfigs',
component: ServerConfigsView
},
{
path: '/servers/messages',
name: 'serversMessages',
component: ServersMessagesView
},
{
path: '/servers/messages/:serverId(\\d+)',
name: 'serverMessages',
component: ServerMessagesView
},
{
path: '/users',
name: 'users',
component: IndexUsersView
},
{
path: '/users/allowed',
name: 'allowedUsers',
component: AllowedUsersView
},
{
path: '/users/configs',
name: 'userConfigs',
component: UserConfigsView
},
{
path: '/users/messages',
name: 'usersMessages',
component: UsersMessagesView
},
{
path: '/users/messages/:userId(\\d+)',
name: 'userMessages',
component: UserMessagesView
}
]
})

View file

@ -0,0 +1,14 @@
<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>

View file

@ -4,9 +4,15 @@
<h1 class="text-xl normal-case m-5">Server overview</h1>
<div class="flex justify-center m-4">
<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">
<button class="btn btn-wide btn-outline">Configs</button>
</RouterLink>
<RouterLink to="/servers/messages">
<button class="btn btn-wide btn-outline">Server with Messages</button>
</RouterLink>
</div>
</div>
</template>

View file

@ -1,10 +1,8 @@
<script setup lang="ts">
import TableComponent from '@/components/TableComponent.vue';
import {getConfigs} from '@/services/ServerConfigs'
const serverConfigs = await getConfigs()
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 tableHeader = ["ID", "Server ID", "System Message", "Rate limit"]
const tableRows = [["1", "name", "comment", "1"]]
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>
@ -12,6 +10,5 @@ const actions = [{ class: "btn btn-sm btn-info m-1", content: "Edit", event: (_:
<h1 class="text-xl normal-case">Server Configs</h1>
<button class="btn btn-circle btn-success">Add</button>
</div>
<TableComponent v-if="serverConfigs.length" :tableHeader="tableHeader" :tableRows="tableRows" :actions="actions" />
<p v-else class="m-5">No server configs</p>
<TableComponent :tableHeader="tableHeader" :tableRows="tableRows" :actions="actions" />
</template>

View file

@ -0,0 +1,16 @@
<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>

View file

@ -0,0 +1,24 @@
<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>

View file

@ -0,0 +1,14 @@
<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>

View file

@ -4,9 +4,15 @@
<h1 class="text-xl normal-case m-5">Server overview</h1>
<div class="flex justify-center m-4">
<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">
<button class="btn btn-wide btn-outline">Configs</button>
</RouterLink>
<RouterLink to="/users/messages">
<button class="btn btn-wide btn-outline">User with Messages</button>
</RouterLink>
</div>
</div>
</template>

View file

@ -0,0 +1,16 @@
<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>

View file

@ -0,0 +1,24 @@
<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>