Skip to content

Commit bcc68f2

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # mystbin/frontend/components/EditorTabs.tsx
2 parents 72ac2f0 + 5635dcb commit bcc68f2

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

mystbin/backend/main.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import argparse
12
import json
23
import os
34
import pathlib
45
import sys
56
from typing import cast
67

8+
79
import uvicorn
810
from uvicorn.supervisors import Multiprocess
911

@@ -24,20 +26,19 @@ def get_config() -> dict[str, dict[str, int | str]]:
2426

2527
return data
2628

27-
28-
async def run_cli():
29-
pass
30-
31-
32-
def run_cli_with_workers():
33-
pass
34-
35-
3629
if __name__ == "__main__":
3730
cfg = get_config()
3831
port = cast(int, cfg["site"]["backend_port"])
39-
use_workers = "--no-workers" not in sys.argv and cfg["redis"]["use-redis"]
40-
use_cli = "--no-cli" not in sys.argv
32+
parser = argparse.ArgumentParser(prog="Mystbin")
33+
parser.add_argument("--no-workers", "-nw", action="store_true", default=False)
34+
parser.add_argument("--no-cli", "-nc", action="store_true", default=False)
35+
parser.add_argument("--workers", "-w", nargs=1, default=os.cpu_count() or 1)
36+
37+
ns = parser.parse_args(sys.argv[1:])
38+
39+
use_workers: bool = not ns.no_workers
40+
use_cli: bool = not ns.no_cli
41+
worker_count: int = ns.workers
4142
_cli_path = pathlib.Path(".nocli")
4243

4344
if not use_cli:
@@ -57,7 +58,7 @@ def run_cli_with_workers():
5758
server = uvicorn.Server(config)
5859

5960
if use_workers:
60-
config.workers = os.cpu_count() or 1
61+
config.workers = worker_count
6162
sock = config.bind_socket()
6263

6364
runner = Multiprocess(config, target=server.run, sockets=[sock])

mystbin/backend/utils/db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ async def put_paste(
269269
resp["id"],
270270
page.content,
271271
page.filename,
272-
page.content.count("\n"),
272+
page.content.count("\n") + 1, # add an extra for line 1
273273
)
274274
)
275275

@@ -959,7 +959,7 @@ async def put_log(self, request: Request, response: Response) -> None:
959959
await self._do_query(
960960
query,
961961
request.headers.get("X-Forwarded-For", request.client.host),
962-
request.state.user and request.state.user.id,
962+
request.state.user and request.state.user["id"],
963963
datetime.datetime.utcnow(),
964964
request.headers.get("CF-RAY"),
965965
request.headers.get("CF-IPCOUNTRY"),

mystbin/frontend/components/EditorTabs.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import { Button } from "@material-ui/core";
1313
import DropdownItem from "react-bootstrap/DropdownItem";
1414
import React from "react";
1515
import InsertPhotoIcon from "@material-ui/icons/InsertPhoto";
16-
import SettingsIcon from '@material-ui/icons/Settings';
17-
import {language} from "@hapi/accept";
16+
import SettingsIcon from "@material-ui/icons/Settings";
1817

1918
const languages = {
2019
py: "python",
@@ -200,7 +199,7 @@ export default function EditorTabs({
200199
</Button>
201200
{langDropDown ? (
202201
<div className={styles.langParent}>
203-
<Dropdown className={styles.dropDown} autoClose={'outside'}>
202+
<Dropdown className={styles.dropDown} autoClose>
204203
{Object.keys(languages).map((v, index) => {
205204
if (i !== currTab) {
206205
return <></>;
@@ -214,7 +213,7 @@ export default function EditorTabs({
214213
}}
215214
onClick={() => {
216215
setLangDropDown(false);
217-
setDropLang(getLanguage(v));
216+
setDropLang(v);
218217
}}
219218
>
220219
{v}

0 commit comments

Comments
 (0)