add basic ratelimiting

This commit is contained in:
Ishaan Dey
2024-05-05 12:55:34 -07:00
parent 5ae5c226ba
commit 7fba908b7c
9 changed files with 148 additions and 55 deletions

View File

@ -18,6 +18,7 @@ import NewProjectModal from "./newProject"
import Link from "next/link"
import { useSearchParams } from "next/navigation"
import AboutModal from "./about"
import { toast } from "sonner"
type TScreen = "projects" | "shared" | "settings" | "search"
@ -58,7 +59,13 @@ export default function Dashboard({
<div className="w-56 shrink-0 border-r border-border p-4 justify-between flex flex-col">
<div className="flex flex-col">
<CustomButton
onClick={() => setNewProjectModalOpen(true)}
onClick={() => {
if (sandboxes.length >= 8) {
toast.error("You reached the maximum # of sandboxes.")
return
}
setNewProjectModalOpen(true)
}}
className="mb-4"
>
<Plus className="w-4 h-4 mr-2" />

View File

@ -372,6 +372,7 @@ export default function CodeEditor({
const selectFile = (tab: TTab) => {
if (tab.id === activeId) return
const exists = tabs.find((t) => t.id === tab.id)
setTabs((prev) => {
if (exists) {
setActiveId(exists.id)
@ -420,8 +421,9 @@ export default function CodeEditor({
oldName: string,
type: "file" | "folder"
) => {
if (!validateName(newName, oldName, type)) {
toast.error("Invalid file name.")
const valid = validateName(newName, oldName, type)
if (!valid.status) {
if (valid.message) toast.error("Invalid file name.")
return false
}
@ -633,6 +635,11 @@ export default function CodeEditor({
Shell
</Tab>
<Button
onClick={() => {
if (terminals.length >= 4) {
toast.error("You reached the maximum # of terminals.")
}
}}
size="smIcon"
variant={"secondary"}
className={`font-normal select-none text-muted-foreground`}

View File

@ -20,13 +20,15 @@ export default function New({
const createNew = () => {
const name = inputRef.current?.value
// console.log("Create:", name, type)
if (name && validateName(name, "", type)) {
if (type === "file") {
socket.emit("createFile", name)
if (name) {
const valid = validateName(name, "", type)
if (valid.status) {
if (type === "file") {
socket.emit("createFile", name)
}
addNew(name, type)
}
addNew(name, type)
}
stopEditing()
}