diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 2ee01c9..e205160 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -19,12 +19,21 @@ model Snippet {
createdAt DateTime @default(now())
}
+model Room {
+ id String @id @default(auto()) @map("_id") @db.ObjectId
+ code String @unique
+ createdAt DateTime @default(now())
+ pastes Paste[]
+}
+
model Paste {
- id String @id @default(auto()) @map("_id") @db.ObjectId
- text String
- title String
- password String?
+ id String @id @default(auto()) @map("_id") @db.ObjectId
+ text String
+ title String
+ password String?
paste_expiration Int?
- encrypted Int?
- createdAt DateTime @default(now())
+ encrypted Int?
+ createdAt DateTime @default(now())
+ roomId String? @db.ObjectId
+ room Room? @relation(fields: [roomId], references: [id])
}
\ No newline at end of file
diff --git a/src/lib/dataStore.js b/src/lib/dataStore.js
index 48fd402..8ef55d5 100644
--- a/src/lib/dataStore.js
+++ b/src/lib/dataStore.js
@@ -6,7 +6,17 @@ const prisma = new PrismaClient();
// Function to insert a new paste
export async function insertPaste(data) {
- const { text, title, password, paste_expiration, encrypted } = data;
+ const { text, title, password, paste_expiration, encrypted, roomCode } = data;
+
+ let roomId = undefined;
+ if (roomCode) {
+ const room = await prisma.room.findUnique({
+ where: { code: roomCode }
+ });
+ if (room) {
+ roomId = room.id;
+ }
+ }
// Insert the new paste into MongoDB
const newPaste = await prisma.paste.create({
@@ -16,6 +26,7 @@ export async function insertPaste(data) {
password,
paste_expiration,
encrypted,
+ roomId
},
});
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index d00c8e2..74c25fb 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -9,17 +9,57 @@
import "prismjs/components/prism-python";
import "prismjs/components/prism-java";
import toast, { Toaster } from "svelte-french-toast";
- import Hero from "./components/Hero.svelte";
import { fade, slide } from "svelte/transition";
import { quintOut } from "svelte/easing";
import { enhance } from "$app/forms";
+ import { goto } from '$app/navigation';
+
+ let view = 'choose'; // 'choose', 'public', 'room'
+ let roomCode = '';
+ let error = '';
+ let loading = false;
+
+ // Function to create a new room
+ async function createRoom() {
+ loading = true;
+ try {
+ const response = await fetch('/rooms', {
+ method: 'POST'
+ });
+ const data = await response.json();
+ if (response.ok) {
+ goto(`/rooms/${data.room.code}`);
+ } else {
+ error = data.error;
+ toast.error(data.error);
+ }
+ } catch (err) {
+ error = 'Failed to create room';
+ toast.error('Failed to create room');
+ } finally {
+ loading = false;
+ }
+ }
+
+ // Function to join a room
+ async function joinRoom() {
+ if (!roomCode) {
+ toast.error('Please enter a room code');
+ return;
+ }
+ if (roomCode.length !== 6) {
+ toast.error('Invalid room code format');
+ return;
+ }
+ goto(`/rooms/${roomCode}`);
+ }
let selectedLanguage = "markup";
let isDragging = false;
let showSuccessToast = false;
let toastMessage = "";
- let toastType = "success"; // 'success' or 'error'
- let currentTab = "editor"; // 'editor' or 'preview'
+ let toastType = "success";
+ let currentTab = "editor";
let createdPasteUrl = "";
const languageOptions = [
@@ -34,20 +74,18 @@
function formatExpirationTime(expirationTimestamp: number | null): string {
if (expirationTimestamp === null) return "Never";
-
const now = Date.now();
const secondsRemaining = Math.floor((expirationTimestamp - now) / 1000);
-
if (secondsRemaining <= 0) return "Expired";
if (secondsRemaining < 60) return `${secondsRemaining}s`;
if (secondsRemaining < 3600) return `${Math.floor(secondsRemaining / 60)}m`;
- if (secondsRemaining < 86400)
- return `${Math.floor(secondsRemaining / 3600)}h`;
+ if (secondsRemaining < 86400) return `${Math.floor(secondsRemaining / 3600)}h`;
return `${Math.floor(secondsRemaining / 86400)}d`;
}
-
+
function showToast(message: string, type: 'success' | 'error' = 'success') {
toastMessage = message;
+ toast[type](message);
toastType = type;
showSuccessToast = true;
setTimeout(() => {
@@ -210,239 +248,304 @@
}
-
{toastMessage}
-