diff --git a/src/routes/index.svelte b/src/routes/index.svelte
index 4080a3e..0701788 100644
--- a/src/routes/index.svelte
+++ b/src/routes/index.svelte
@@ -9,10 +9,15 @@
}
let id;
+ let invalidId = false;
function connect() {
- const url=`${process.env.URL}/room/?id=${id}`;
- window.location.href = url;
+ if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(id)) {
+ const url=`${process.env.URL}/room/?id=${id}`;
+ window.location.href = url;
+ } else {
+ invalidId = true;
+ }
}
const plcType = ['Лабораторная работа', 'Лаба', 'Практическая работа', 'Практика', 'Лабораторная', 'Доклад'];
@@ -60,6 +65,7 @@
Код подключения:
+ {#if invalidId}Неверный формат кода :({/if}
@@ -83,6 +89,10 @@
width: 100%;
}
+ .error-hint {
+ color: indianred;
+ }
+
.btn {
width: 15ch;
}
diff --git a/src/routes/room.svelte b/src/routes/room.svelte
index 172abb5..218a254 100644
--- a/src/routes/room.svelte
+++ b/src/routes/room.svelte
@@ -10,9 +10,10 @@
import { onMount } from 'svelte';
let room;
+ let res;
async function getRoom() {
var url = `${process.env.URL}/api/join/?id=${parsed.id}`;
- const res = await fetch(url);
+ res = await fetch(url);
room = await res.json();
}
@@ -106,8 +107,14 @@
- {:else}
- Loading...
+ {:else if res==undefined}
+ Загрузка...
+ {:else if res.status==404}
+
{/if}
@@ -198,15 +205,16 @@
display: inline-block;
}
- /*
- .individual:before {
- background-color: #2196F3;
+ .status {
+ width: 100%;
+ text-align: center;
+ margin-top: 250px;
}
- .group:before {
- background-color: #f57323;
+ .status > h1 {
+ font-size: 128px;
+ font-weight: bold;
}
- */
@media only screen and (max-width: 1024px) {
ol {
diff --git a/src/server.js b/src/server.js
index d2b5a9a..5ed1ae2 100644
--- a/src/server.js
+++ b/src/server.js
@@ -53,8 +53,12 @@ MongoClient.connect(process.env.DB_CONNECTION, { useUnifiedTopology: true })
// id
app.get('/api/join/', (req, res) => {
rooms.findOne({ "id": req.query.id }).then(room => {
- res.writeHead(200, { 'Content-Type': 'application/json' });
- res.write(JSON.stringify(room));
+ if (room !== null) {
+ res.writeHead(200, { 'Content-Type': 'application/json' });
+ res.write(JSON.stringify(room));
+ } else {
+ res.writeHead(404, { 'Content-Type': 'application/json' });
+ }
res.end();
});
});