idk
This commit is contained in:
@@ -18,6 +18,7 @@ val resourcesPath: String = System.getenv("RESOURCES") ?: "src/main/resources/"
|
|||||||
|
|
||||||
object ConversationHandler {
|
object ConversationHandler {
|
||||||
val ids = mutableListOf<Int>()
|
val ids = mutableListOf<Int>()
|
||||||
|
val conversations = mutableListOf<Conversation>()
|
||||||
|
|
||||||
fun nextID(): Int
|
fun nextID(): Int
|
||||||
{
|
{
|
||||||
@@ -29,7 +30,18 @@ object ConversationHandler {
|
|||||||
return num
|
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())
|
fun newConv(id: Int = nextID())
|
||||||
{
|
{
|
||||||
@@ -48,18 +60,39 @@ class Conversation(val ID: Int)
|
|||||||
newMsg = true
|
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
|
override fun toString(): String
|
||||||
{
|
{
|
||||||
newMsg = false
|
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
|
fun sendAll(): String
|
||||||
{
|
{
|
||||||
val returnString = StringBuilder()
|
val returnString = StringBuilder()
|
||||||
|
|
||||||
for (message in messages)
|
for (message in messages.reversed())
|
||||||
{
|
{
|
||||||
returnString.append(message.toString())
|
returnString.append(message.toString())
|
||||||
returnString.append("\n")
|
returnString.append("\n")
|
||||||
@@ -71,13 +104,18 @@ class Conversation(val ID: Int)
|
|||||||
|
|
||||||
data class Message(val user: Boolean, val text: String)
|
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"}">
|
<div class="message-${if (user) "user" else "scott"}">
|
||||||
<p>$text</p>
|
<p>$text</p>
|
||||||
</div>
|
</div>
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
@@ -92,6 +130,14 @@ fun runEmbeddedServer()
|
|||||||
routing {
|
routing {
|
||||||
staticFiles("/resources", File(resourcesPath))
|
staticFiles("/resources", File(resourcesPath))
|
||||||
staticFiles("/", File(resourcesPath+"/index.html"))
|
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}")
|
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>
|
</head>
|
||||||
<body onload="javascript:init()">
|
<body onload="javascript:init()">
|
||||||
|
|
||||||
<div class="navbar" id="myNavbar">
|
<header class="navbar">
|
||||||
<a href="#" style="float: left">ScottGPT</a>
|
|
||||||
<a href="https://sc0tt.org/" style="float: left" target="_blank">Sc0tt főoldal</a>
|
<a href="https://sc0tt.org/" style="float: left" target="_blank">Sc0tt főoldal</a>
|
||||||
<a href="#" style="float: left">About</a>
|
<a href="#" style="float: left">About</a>
|
||||||
|
|
||||||
@@ -21,21 +20,22 @@
|
|||||||
onclick="toggleMenu()">
|
onclick="toggleMenu()">
|
||||||
☰
|
☰
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</header>
|
||||||
|
|
||||||
<div class="main-content">
|
<div class="main-content">
|
||||||
<div id="messages" class="messages">
|
<div id="messages" class="messages">
|
||||||
|
|
||||||
</div>
|
</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>
|
</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>
|
<script>
|
||||||
let id;
|
let id;
|
||||||
|
|
||||||
@@ -148,13 +148,5 @@
|
|||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
|
||||||
function toggleMenu() {
|
|
||||||
let navbar = document.getElementById("myNavbar");
|
|
||||||
navbar.className = navbar.className === "navbar" ?
|
|
||||||
"navbar responsive" : "navbar";
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -6,17 +6,17 @@ body {
|
|||||||
|
|
||||||
.main-content {
|
.main-content {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
margin: auto;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
min-height: 90vh;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.message-user {
|
.message-user {
|
||||||
margin: auto;
|
margin: auto;
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
padding: 0px 20px;
|
padding: 0px 25px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
width: 60%;
|
width: 60%;
|
||||||
color: white;
|
color: white;
|
||||||
@@ -26,13 +26,11 @@ body {
|
|||||||
|
|
||||||
.messages {
|
.messages {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
||||||
bottom: 20px;
|
|
||||||
margin: 10px auto 0px auto;
|
margin: 10px auto 0px auto;
|
||||||
padding: 10px 0px;
|
padding: 10px 0px;
|
||||||
flex-direction: column-reverse;
|
flex-direction: column-reverse;
|
||||||
width: 80%;
|
width: 80%;
|
||||||
overflow:scroll;
|
overflow: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
.textbox-parent {
|
.textbox-parent {
|
||||||
@@ -45,6 +43,14 @@ body {
|
|||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.textbox {
|
||||||
|
background: #323232;
|
||||||
|
display: flex;
|
||||||
|
margin: auto;
|
||||||
|
width: 80%;
|
||||||
|
border-radius: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.text_input {
|
.text_input {
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
@@ -71,15 +77,38 @@ body {
|
|||||||
border: none;
|
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 {
|
.navbar {
|
||||||
overflow: hidden;
|
|
||||||
height: 10%;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
padding: 5px;
|
padding: 10px;
|
||||||
background: #212121;
|
background: #212121;
|
||||||
top: 0;
|
top: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
width: 100%;
|
||||||
|
position: fixed;
|
||||||
|
padding: 10px;
|
||||||
|
background: #212121;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.navbar a {
|
.navbar a {
|
||||||
display: block;
|
display: block;
|
||||||
color: white;
|
color: white;
|
||||||
@@ -101,37 +130,4 @@ body {
|
|||||||
.navbar a.icon {
|
.navbar a.icon {
|
||||||
display: none;
|
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