From 2911a38dc862520bc159f39c94d6c1211e0777fd Mon Sep 17 00:00:00 2001 From: EvieePy Date: Tue, 31 Oct 2023 15:07:56 +1000 Subject: [PATCH] Add spec. Add unique to safety column. --- mystbin/backend/routers/safety.py | 20 ++++++++++++++++++-- mystbin/backend/utils/openapi.py | 2 +- mystbin/database/migrate_v4.sql | 2 +- mystbin/database/schema.sql | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/mystbin/backend/routers/safety.py b/mystbin/backend/routers/safety.py index 4b6bd95..d4db2da 100644 --- a/mystbin/backend/routers/safety.py +++ b/mystbin/backend/routers/safety.py @@ -18,6 +18,9 @@ """ from __future__ import annotations +import pathlib +import json + from asyncpg import Record from models import responses @@ -28,12 +31,25 @@ from utils.router import Router +__p = pathlib.Path("./config.json") +if not __p.exists(): + __p = pathlib.Path("../../config.json") + +with __p.open() as __f: + __config = json.load(__f) + +del __p, __f # micro-opt, don't keep unneeded variables in-ram + + router = Router() desc = f"""Delete a paste using a Safety Token. When you create a paste you will receive a token named "safety_token", this token is displayed **only once**. + +This endpoint has no direct ratelimit bucket, and falls only under the global ratelimit. +The global ratelimit is {__config['ratelimits']['global']}, and {__config['ratelimits']["authed_global"]} when logged in. """ @@ -45,9 +61,9 @@ "Delete Paste with Safety Token", ["safety"], None, - [], + [openapi.RouteParameter("Safety Token", "string", "safety_token", True, "path")], { - 200: openapi.Response("Success", openapi.SafetyDelete), + 200: openapi.Response("Success", openapi.SafetyDeleteResponse), 404: openapi.NotFoundResponse, }, description=desc, diff --git a/mystbin/backend/utils/openapi.py b/mystbin/backend/utils/openapi.py index c61cbf1..c6fa775 100644 --- a/mystbin/backend/utils/openapi.py +++ b/mystbin/backend/utils/openapi.py @@ -584,7 +584,7 @@ def render(self) -> dict: ], ) -SafetyDelete = _Component( +SafetyDeleteResponse = _Component( "SafetyDelete", properties=[ ComponentProperty("id", "Paste ID", "string", required=True), diff --git a/mystbin/database/migrate_v4.sql b/mystbin/database/migrate_v4.sql index 3d19b07..30800bf 100644 --- a/mystbin/database/migrate_v4.sql +++ b/mystbin/database/migrate_v4.sql @@ -37,7 +37,7 @@ ALTER TABLE pastes ON DELETE SET NULL, ADD COLUMN public BOOLEAN NOT NULL DEFAULT TRUE, ADD COLUMN source TEXT, - ADD COLUMN safety TEXT, + ADD COLUMN safety TEXT UNIQUE, ALTER COLUMN created_at TYPE TIMESTAMP; -- previously timestamp with time zone ALTER TABLE files diff --git a/mystbin/database/schema.sql b/mystbin/database/schema.sql index d941335..0f8461d 100644 --- a/mystbin/database/schema.sql +++ b/mystbin/database/schema.sql @@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS pastes ( token_id INTEGER REFERENCES tokens(id), public BOOLEAN NOT NULL DEFAULT TRUE, source TEXT, - safety TEXT + safety TEXT UNIQUE ); CREATE TABLE IF NOT EXISTS files (