Skip to content

Commit

Permalink
Merge pull request #14 from likes-gay/dev
Browse files Browse the repository at this point in the history
Push Dev to main
  • Loading branch information
Zoobdude authored Jan 29, 2024
2 parents 22b4db5 + 0c44b39 commit 6e3a904
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 117 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
static
static
dict-data
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ This site is hosted in a [Docker container](https://hub.docker.com/r/likesgay/di
### Production

The easiest and most secure way to run this is using our [offcial Docker image](https://hub.docker.com/r/likesgay/dict).
The default port it runs on is 8000. Change the first port to change the host port.
The volume sets where the database file should be stored, so it persits. This defaults to the directory the command is run in.
The detach argument runs the container in the background.
The name argument sets the name

* **Make sure to replace the SECRET_KEY in the command**
* The default port it runs on is 8000. Change the first port to change the host port.
* The volume sets where the database file should be stored, so it persits. This defaults to the directory the command is run in.
* The detach argument runs the container in the background.
* The name argument sets the name

```shell
docker run --publish 8000:8000 --volume $(pwd)/dict-data:/backend/dict-data --detach --restart always --name Dict likesgay/dict
docker run -e SECRET_KEY="SET_SECRECT_KEY_HERE" --publish 8000:8000 --volume $(pwd)/dict-data:/backend/dict-data --detach --restart always --name Dict likesgay/dict
```
The Docker container can automatically be updated to the latest image using [Watchtower](https://containrrr.dev/watchtower/).

Expand Down
2 changes: 1 addition & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
For the `/api/delete_word` endpoint.

```env
SECRECT_KEY= #Here
SECRET_KEY= #Here
```
19 changes: 9 additions & 10 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,23 @@

# -------------------------------------------


class UpdootEnum(str, Enum):
UP = "up"
DOWN = "down"
NONE = "none"


class UpdateUpdoot(BaseModel):
id: int
updootState: UpdootEnum
prevUpdootState: UpdootEnum


class UploadWordFormat(BaseModel):
word: str
description: str
creationDate: int
uploader: str
isRobot: bool


class DeleteWord(BaseModel):
id: int
secretKey: str
Expand All @@ -73,7 +69,6 @@ class DirEnum(str, Enum):
DESC = "desc"
ASC = "asc"


class SortByEnum(str, Enum):
TOTALDOOTS = "totaldoots"
UPDOOTS = "updoots"
Expand All @@ -82,10 +77,8 @@ class SortByEnum(str, Enum):
CREATION_DATE = "date"
ALPHABETICAL = "alphabet"


# -------------------------------------------


# Remove trailing slashes
@app.middleware("http")
async def remove_trailing_slash(request: Request, call_next):
Expand All @@ -96,8 +89,7 @@ async def remove_trailing_slash(request: Request, call_next):

# -------------------------------------------


@app.get("/api")
@app.get("/api", status_code=418)
async def check_if_api_is_working():
return {"I'm a": "teapot"}

Expand Down Expand Up @@ -142,7 +134,7 @@ async def upload_a_new_word(new_word: UploadWordFormat):

@app.delete("/api/delete_word", status_code=204)
async def delete_a_word(req: DeleteWord):
if req.secretKey != getenv("SECRECT_KEY"):
if req.secretKey != getenv("SECRET_KEY"):
raise HTTPException(status_code=403, detail="Unauthorised, invalid secret key")

# Check if the word exists
Expand Down Expand Up @@ -178,6 +170,7 @@ async def get_word_by_ID(wordId: GetWordParam):

if response:
return response[0]

else:
raise HTTPException(status_code=404, detail="Item not found lol")

Expand All @@ -190,15 +183,20 @@ async def get_all_words(

if sortby == SortByEnum.TOTALDOOTS:
return sorted(db.all(), key=lambda x: x["updoots"] - x["downdoots"], reverse=IS_REVERSED)

elif sortby == SortByEnum.ID:
return sorted(db.all(), key=lambda x: x["id"], reverse=IS_REVERSED)

elif sortby == SortByEnum.UPDOOTS:
print("UPDOOT")
return sorted(db.all(), key=lambda x: x["updoots"], reverse=IS_REVERSED)

elif sortby == SortByEnum.DOWNDOOTS:
return sorted(db.all(), key=lambda x: x["downdoots"], reverse=IS_REVERSED)

elif sortby == SortByEnum.CREATION_DATE:
return sorted(db.all(), key=lambda x: x["creationDate"], reverse=IS_REVERSED)

elif sortby == SortByEnum.ALPHABETICAL:
return sorted(db.all(), key=lambda x: x["word"].lower(), reverse=IS_REVERSED)

Expand All @@ -225,6 +223,7 @@ async def lookup_id_of_word(wordId: GetWordParam):
response = db.search(Query().word == wordId)
if response:
return {"id": response[0]["id"]}

raise HTTPException(status_code=404, detail="Item not found lol")


Expand Down
2 changes: 1 addition & 1 deletion frontend/src/hooks/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function LinkIcon() {

export function UpdootIcon() {
return (
<svg className="arrow-icon" width={30} height={30} viewBox="0 0 256 256">
<svg className="arrow-icon" width={30} height={30} viewBox="0 0 256 256">
<path
d="M231.39062,123.06152A8,8,0,0,1,224,128H184v80a16.01833,16.01833,0,0,1-16,16H88a16.01833,16.01833,0,0,1-16-16V128H32a8.00065,8.00065,0,0,1-5.65723-13.65723l96-96a8.003,8.003,0,0,1,11.31446,0l96,96A8.002,8.002,0,0,1,231.39062,123.06152Z"
/>
Expand Down
Loading

0 comments on commit 6e3a904

Please sign in to comment.