idk
This commit is contained in:
@@ -18,6 +18,7 @@ val resourcesPath: String = System.getenv("RESOURCES") ?: "src/main/resources/"
|
||||
|
||||
object ConversationHandler {
|
||||
val ids = mutableListOf<Int>()
|
||||
val conversations = mutableListOf<Conversation>()
|
||||
|
||||
fun nextID(): Int
|
||||
{
|
||||
@@ -29,12 +30,23 @@ object ConversationHandler {
|
||||
return num
|
||||
}
|
||||
}
|
||||
val conversations = mutableListOf<Conversation>()
|
||||
fun listAllConversations(): String
|
||||
{
|
||||
val stringBuilder = StringBuilder()
|
||||
|
||||
for (conversation in conversations)
|
||||
{
|
||||
stringBuilder.append(conversation.list())
|
||||
}
|
||||
|
||||
return stringBuilder.toString()
|
||||
|
||||
}
|
||||
|
||||
fun newConv(id: Int = nextID())
|
||||
{
|
||||
conversations.add(Conversation(id))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Conversation(val ID: Int)
|
||||
@@ -48,18 +60,39 @@ class Conversation(val ID: Int)
|
||||
newMsg = true
|
||||
}
|
||||
|
||||
fun list(): String
|
||||
{
|
||||
return """
|
||||
<div class="conversation">
|
||||
<p style="flex-grow: 1; background: ">$ID</p>
|
||||
<p style="flex-grow: 9;">${messages.last().text}</p>
|
||||
<div>
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
override fun toString(): String
|
||||
{
|
||||
newMsg = false
|
||||
|
||||
return messages.last().toString()
|
||||
val returnString = StringBuilder()
|
||||
|
||||
for (message in messages.reversed())
|
||||
{
|
||||
if (!message.read)
|
||||
{
|
||||
returnString.append(message.toString())
|
||||
returnString.append("\n")
|
||||
}
|
||||
}
|
||||
|
||||
return returnString.toString()
|
||||
}
|
||||
|
||||
fun sendAll(): String
|
||||
{
|
||||
val returnString = StringBuilder()
|
||||
|
||||
for (message in messages)
|
||||
for (message in messages.reversed())
|
||||
{
|
||||
returnString.append(message.toString())
|
||||
returnString.append("\n")
|
||||
@@ -71,13 +104,18 @@ class Conversation(val ID: Int)
|
||||
|
||||
data class Message(val user: Boolean, val text: String)
|
||||
{
|
||||
var read: Boolean = false
|
||||
|
||||
override fun toString(): String
|
||||
{
|
||||
read = true
|
||||
|
||||
override fun toString() = """
|
||||
return """
|
||||
<div class="message-${if (user) "user" else "scott"}">
|
||||
<p>$text</p>
|
||||
</div>
|
||||
""".trimIndent()
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
@@ -92,6 +130,14 @@ fun runEmbeddedServer()
|
||||
routing {
|
||||
staticFiles("/resources", File(resourcesPath))
|
||||
staticFiles("/", File(resourcesPath+"/index.html"))
|
||||
staticFiles("/admin", File(resourcesPath+"/admin.html"))
|
||||
|
||||
route("/admin")
|
||||
{
|
||||
get("/api/all_messages") {
|
||||
call.respondText(ConversationHandler.listAllConversations())
|
||||
}
|
||||
}
|
||||
|
||||
put("/api/write/{id}")
|
||||
{
|
||||
|
||||
42
kiszolgalo/src/main/resources/admin.html
Normal file
42
kiszolgalo/src/main/resources/admin.html
Normal file
@@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>ScottGPT admin</title>
|
||||
<link rel="icon" type="image/x-icon" href="/resources/favicon.ico">
|
||||
<link rel="stylesheet" href="/resources/style.css">
|
||||
|
||||
</head>
|
||||
<body onload="javascript:fetch_data()">
|
||||
<h2>Conversations:</h2>
|
||||
<div id="messages">
|
||||
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
|
||||
async function fetch_data()
|
||||
{
|
||||
var url = '/admin/api/all_messages'
|
||||
|
||||
fetch(url)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.then(data => {
|
||||
|
||||
document.getElementById("messages").insertAdjacentHTML("afterbegin", data)
|
||||
|
||||
console.log(data.body)
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
</html>
|
||||
@@ -9,8 +9,7 @@
|
||||
</head>
|
||||
<body onload="javascript:init()">
|
||||
|
||||
<div class="navbar" id="myNavbar">
|
||||
<a href="#" style="float: left">ScottGPT</a>
|
||||
<header class="navbar">
|
||||
<a href="https://sc0tt.org/" style="float: left" target="_blank">Sc0tt főoldal</a>
|
||||
<a href="#" style="float: left">About</a>
|
||||
|
||||
@@ -21,21 +20,22 @@
|
||||
onclick="toggleMenu()">
|
||||
☰
|
||||
</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="main-content">
|
||||
<div id="messages" class="messages">
|
||||
|
||||
</div>
|
||||
<div class="textbox-parent">
|
||||
<div class="textbox">
|
||||
<input class="text_input" name="valami" type="text" id="promptText" placeholder="Kérdezz az OSI modellről... vagy idk...">
|
||||
<button class="send_button" onclick="send_data()">send</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div class="textbox">
|
||||
<input class="text_input" name="valami" type="text" id="promptText" placeholder="Kérdezz az OSI modellről... vagy idk...">
|
||||
<button class="send_button" onclick="send_data()">send</button>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
let id;
|
||||
|
||||
@@ -148,13 +148,5 @@
|
||||
|
||||
</script>
|
||||
|
||||
<script>
|
||||
function toggleMenu() {
|
||||
let navbar = document.getElementById("myNavbar");
|
||||
navbar.className = navbar.className === "navbar" ?
|
||||
"navbar responsive" : "navbar";
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -6,17 +6,17 @@ body {
|
||||
|
||||
.main-content {
|
||||
display: flex;
|
||||
margin: auto;
|
||||
text-align: center;
|
||||
box-sizing: border-box;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
min-height: 90vh;
|
||||
}
|
||||
|
||||
.message-user {
|
||||
margin: auto;
|
||||
margin-top: 10px;
|
||||
padding: 0px 20px;
|
||||
padding: 0px 25px;
|
||||
text-align: left;
|
||||
width: 60%;
|
||||
color: white;
|
||||
@@ -26,13 +26,11 @@ body {
|
||||
|
||||
.messages {
|
||||
display: flex;
|
||||
|
||||
bottom: 20px;
|
||||
margin: 10px auto 0px auto;
|
||||
padding: 10px 0px;
|
||||
flex-direction: column-reverse;
|
||||
width: 80%;
|
||||
overflow:scroll;
|
||||
overflow: scroll;
|
||||
}
|
||||
|
||||
.textbox-parent {
|
||||
@@ -45,6 +43,14 @@ body {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.textbox {
|
||||
background: #323232;
|
||||
display: flex;
|
||||
margin: auto;
|
||||
width: 80%;
|
||||
border-radius: 25px;
|
||||
}
|
||||
|
||||
|
||||
.text_input {
|
||||
justify-content: flex-start;
|
||||
@@ -71,15 +77,38 @@ body {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.conversation {
|
||||
background: #323232;
|
||||
display: flex;
|
||||
margin: auto;
|
||||
width: 80%;
|
||||
padding: 10px 10px;
|
||||
border-radius: 25px;
|
||||
}
|
||||
|
||||
.conversation p {
|
||||
background: black;
|
||||
margin: auto 10px;
|
||||
padding: 10px;
|
||||
border-radius: 15px;
|
||||
}
|
||||
|
||||
.navbar {
|
||||
overflow: hidden;
|
||||
height: 10%;
|
||||
width: 100%;
|
||||
position: fixed;
|
||||
padding: 5px;
|
||||
padding: 10px;
|
||||
background: #212121;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
footer {
|
||||
width: 100%;
|
||||
position: fixed;
|
||||
padding: 10px;
|
||||
background: #212121;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.navbar a {
|
||||
display: block;
|
||||
color: white;
|
||||
@@ -101,37 +130,4 @@ body {
|
||||
.navbar a.icon {
|
||||
display: none;
|
||||
}
|
||||
@media screen and (max-width: 600px) {
|
||||
.textbox {
|
||||
display: flex;
|
||||
position: relative;
|
||||
justify-content: center;
|
||||
width: 60%;
|
||||
margin: 5px;
|
||||
background: #2f2f2f;
|
||||
border-radius: 25px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
|
||||
.navbar a:not(:first-child) {
|
||||
display: none;
|
||||
}
|
||||
.navbar a.icon {
|
||||
float: right;
|
||||
display: block;
|
||||
}
|
||||
.navbar.responsive {
|
||||
position: relative;
|
||||
}
|
||||
.navbar.responsive a.icon {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
}
|
||||
.navbar.responsive a {
|
||||
float: none;
|
||||
display: block;
|
||||
text-align: left;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user