Skip to content

Commit

Permalink
fix: handled languages with no specified extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
A91y committed Dec 29, 2023
1 parent 161a284 commit 668768b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/paste/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ async def get_paste_data(uuid):
except ClassNotFound:
lexer = get_lexer_by_name(
"text", stripall=True) # Default lexer
formatter = HtmlFormatter(style="colorful", full=True, linenos="inline")
formatter = HtmlFormatter(
style="colorful", full=True, linenos="inline")
highlighted_code = highlight(content, lexer, formatter)
return HTMLResponse(
content=highlighted_code
Expand Down Expand Up @@ -132,16 +133,20 @@ async def web(request: Request):

@app.post("/web", response_class=PlainTextResponse)
@limiter.limit("100/minute")
async def web_post(request: Request, content: str = Form(...), extension: str = Form(...)):
async def web_post(request: Request, content: str = Form(...), extension: str = Form(None)):
try:
file_content = content.encode()
uuid = generate_uuid()
if uuid in large_uuid_storage:
uuid = generate_uuid()
path = f"data/{uuid+extension}"
if extension:
uuid_ = uuid + extension
else:
uuid_ = uuid
path = f"data/{uuid_}"
with open(path, "wb") as f:
f.write(file_content)
large_uuid_storage.append(uuid+extension)
large_uuid_storage.append(uuid_)
except Exception as e:
print(e)
raise HTTPException(
Expand All @@ -150,7 +155,7 @@ async def web_post(request: Request, content: str = Form(...), extension: str =
)

return RedirectResponse(
f"{BASE_URL}/paste/{uuid+extension}", status_code=status.HTTP_303_SEE_OTHER
f"{BASE_URL}/paste/{uuid_}", status_code=status.HTTP_303_SEE_OTHER
)


Expand Down
4 changes: 2 additions & 2 deletions src/paste/templates/web.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
if (selectedLanguageData.extensions.length > 1) {
// Show the extension dropdown
extensionSelect.style.display = "block";
extensionSelect.disabled = false;
extensionSelect.style.opacity = 1;
extensionSelect.style.cursor = "auto";

// Populate the extension dropdown with options for each extension
Expand All @@ -119,7 +119,7 @@
extOption.text = ext;
extensionSelect.add(extOption);
extensionSelect.style.display = "block";
extensionSelect.disabled = true;
extensionSelect.style.opacity = 0.5;
extensionSelect.style.cursor = "no-drop";
}
} else {
Expand Down

0 comments on commit 668768b

Please sign in to comment.