Skip to content

Commit

Permalink
Add spec. Add unique to safety column.
Browse files Browse the repository at this point in the history
  • Loading branch information
EvieePy committed Oct 31, 2023
1 parent d66ddd1 commit 2911a38
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
20 changes: 18 additions & 2 deletions mystbin/backend/routers/safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"""
from __future__ import annotations

import pathlib
import json

from asyncpg import Record
from models import responses

Expand All @@ -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.
"""


Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion mystbin/backend/utils/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ def render(self) -> dict:
],
)

SafetyDelete = _Component(
SafetyDeleteResponse = _Component(
"SafetyDelete",
properties=[
ComponentProperty("id", "Paste ID", "string", required=True),
Expand Down
2 changes: 1 addition & 1 deletion mystbin/database/migrate_v4.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mystbin/database/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 2911a38

Please sign in to comment.