Skip to content

Commit

Permalink
updated icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Andcool-Systems committed Feb 5, 2024
1 parent b22dfa4 commit fad5956
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/dataBase.db
/.env
/tg
/web_nextjs
/out
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "FileUploaderBot"]
path = FileUploaderBot
url = https://github.com/kwixie1/FileUploaderBot.git
1 change: 1 addition & 0 deletions FileUploaderBot
Submodule FileUploaderBot added at 2c0f5d
61 changes: 30 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ This section will be referred to as `1.1` in the documentation.

**List of errors:**

| errorId | message | Reasons |
| ------- | ----------------------------------------------------- | --------------------------------------------------- |
| -1 | No Authorization header provided | The request is missing the `Authorization` header |
| errorId | message | Reasons |
| ------- | ------------------------------------------------------ | -------------------------------------------------- |
| -1 | No Authorization header provided | The request is missing the `Authorization` header |
| -2 | Authorization header must have `Bearer <token>` format | The `Authorization` header has an incorrect format |
| -3 | Access token expired | The token has expired |
| -4 | Invalid access token | The token cannot be decrypted |
| -5 | Token not found | The token is not found |
| -3 | Access token expired | The token has expired |
| -4 | Invalid access token | The token cannot be decrypted |
| -5 | Token not found | The token is not found |

### 1.2 Basic API

Expand All @@ -56,9 +56,9 @@ If the file type cannot be determined, the API returns the file in download mode

#### Possible Errors

| Error Code | Description | Possible Reasons |
| ---------- | ----------------------------- | -----------------------------------------------|
| 404 | File not found | The file referenced by the code does not exist |
| Error Code | Description | Possible Reasons |
| ---------- | -------------- | ---------------------------------------------- |
| 404 | File not found | The file referenced by the code does not exist |

### Upload a file to the server
`POST /api/upload?include_ext=false`
Expand Down Expand Up @@ -93,22 +93,21 @@ On successful execution, the API returns a `200` HTTP code along with a JSON res
```

#### Possible Errors
| Error Code | Description | Possible Reasons |
| ---------- | ------------------------------ | ---------------------------------------- |
| 400 | No file uploaded | No file is given in the request body |
| 400 | Bad file extension | The file does not have an extension |
| 413 | File size exceeds the limit (100MB) | The file size exceeds 100MB |
| Error Code | Description | Possible Reasons |
| ---------- | ----------------------------------- | ------------------------------------ |
| 400 | No file uploaded | No file is given in the request body |
| 413 | File size exceeds the limit (100MB) | The file size exceeds 100MB |

### Delete a file
`GET /api/delete/<file_url>?key=<unique key>`
Successful execution returns a `200` status code, removing the file from the server.

#### Possible Errors

| Error Code | Description | Possible Reasons |
| ---------- | -------------------------- | ---------------------------------- |
| 404 | File not found | The file for deletion is not found |
| 400 | Invalid unique key | The provided unique key is invalid |
| Error Code | Description | Possible Reasons |
| ---------- | ------------------ | ---------------------------------- |
| 404 | File not found | The file for deletion is not found |
| 400 | Invalid unique key | The provided unique key is invalid |

### 1.2 Authorization API
### Login and register
Expand Down Expand Up @@ -142,22 +141,22 @@ Successful execution returns a `200` HTTP code, indicating successful registrati

**Common for both requests:**

| errorId | HTTP code |message | Reasons |
| ------- | ----------|---------------------------------| --------------------------------------------------- |
| 2 | 400 | No username/password provided | Username/password fields are missing in the request |
| errorId | HTTP code | message | Reasons |
| ------- | --------- | ----------------------------- | --------------------------------------------------- |
| 2 | 400 | No username/password provided | Username/password fields are missing in the request |

**Errors for /register:**

| errorId | HTTP code | message | Reasons |
| ------- | ----------|------------------------------------------------| ----------------------------------------------|
| 1 | 400 |An account with this name is already registered | A user with the given username already exists |
| errorId | HTTP code | message | Reasons |
| ------- | --------- | ----------------------------------------------- | --------------------------------------------- |
| 1 | 400 | An account with this name is already registered | A user with the given username already exists |

**Errors for /login:**

| errorId | HTTP code | message | Reasons |
| ------- | ----------|----------------------| -----------------------|
| 3 | 400 |Wrong password | Incorrect password |
| 4 | 404 |User not found | Username not found |
| errorId | HTTP code | message | Reasons |
| ------- | --------- | -------------- | ------------------ |
| 3 | 400 | Wrong password | Incorrect password |
| 4 | 404 | User not found | Username not found |

### Refreshe the token
`POST /api/refresh_token`
Expand All @@ -167,9 +166,9 @@ Successful execution returns a `200` HTTP code along with the `accessToken` fiel

#### Possible Errors

| errorId | HTTP code | message | Reasons |
| ------- | ----------|-----------------------------| ------------------------------------------------- |
| 5 | 400 | No access token provided | The `accessToken` field is missing in the request |
| errorId | HTTP code | message | Reasons |
| ------- | --------- | ------------------------ | ------------------------------------------------- |
| 5 | 400 | No access token provided | The `accessToken` field is missing in the request |

Errors described in section `1.1` may also occur.

Expand Down
72 changes: 39 additions & 33 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async def check_token(Authorization):
@app.get("/invite/{group_id}") # invite page handler
async def invite(group_id: str, request: Request):
async with aiofiles.open("accept_invite.html", mode="rb") as f:
return Response(await f.read(), media_type="text/html", status_code=200)
return Response(await f.read(), media_type="text/html", status_code=200)


@app.post("/api/upload/{group_id}") # File upload handler
Expand All @@ -114,12 +114,6 @@ async def upload_file(
content={"status": "error", "message": "No file uploaded"}, status_code=400
)

if file.filename.find(".") == -1: # Check, if the file has a extension
return JSONResponse(
content={"status": "error", "message": "Bad file extension"},
status_code=400,
)

if file.size > 100 * 1024 * 1024: # 100MB limit
return JSONResponse(
content={
Expand All @@ -145,31 +139,38 @@ async def upload_file(

if group_id != "private":
if not token_db: # If token is not valid
return JSONResponse(content={
return JSONResponse(
content={
"status": "error",
"message": "Auth error",
"auth_error": auth_error,
},
status_code=401,
)
if not group_id.isnumeric():
return JSONResponse(content={"status": "error", "message": "Invalid group id"},
status_code=400)
return JSONResponse(
content={"status": "error", "message": "Invalid group id"},
status_code=400,
)

group = await db.group.find_first(where={"group_id": group_id}, include={"members": True}
group = await db.group.find_first(
where={"group_id": group_id}, include={"members": True}
)
if not group:
return JSONResponse(content={"status": "error", "message": "Group not found"},
status_code=404
return JSONResponse(
content={"status": "error", "message": "Group not found"},
status_code=404,
)
if token_db.user not in group.members:
return JSONResponse(content={"status": "error", "message": "You are not in the group"},
status_code=400)
return JSONResponse(
content={"status": "error", "message": "You are not in the group"},
status_code=400,
)
else:
group_id = -1

key = str(uuid.uuid4()) # Generate unique delete key
ext = "." + file.filename.split(".")[-1].lower() # Get file extension
ext = ("." + file.filename.split(".")[-1].lower()) if file.filename.find(".") != -1 else "" # Get file extension
fid = utils.generate_token(10) + (ext if include_ext else "") # Generate file url
fn = str(uuid.uuid4()) + ext # Generate file name

Expand All @@ -188,9 +189,7 @@ async def upload_file(
"last_watched": time.time(),
"key": key,
"type": (
filetypes.get(ext[1:], default)
if ext.lower()[1:] in filetypes
else "download"
filetypes.get(ext[1:], default) if ext and ext.lower()[1:] in filetypes else "download"
),
"ext": ext,
"size": file.size,
Expand All @@ -212,7 +211,7 @@ async def upload_file(
"ext": created.ext,
"size": utils.calculate_size(file.size),
"user_filename": user_filename,
"username": None if not token_db else token_db.user.username,
"username": None if not token_db and group_id != "private" else token_db.user.username,
"craeted_at": created.craeted_at,
"synced": saved_to_account,
"auth_error": auth_error,
Expand Down Expand Up @@ -324,8 +323,9 @@ async def getFiles(
) # Get user files from db

if group_id == "private":
files = await db.file.find_many(where={"user_id": user.id, "group_id": -1}
) # Get all user files from db
files = await db.file.find_many(
where={"user_id": user.id, "group_id": -1}
) # Get all user files from db
else:
if not group_id.isnumeric():
return JSONResponse(
Expand Down Expand Up @@ -354,7 +354,7 @@ async def getFiles(
user_filename = file.user_filename[:50] + (
"..." if len(file.user_filename) > 50 else ""
)
usr = await db.user.find_first(where={"id": file.user_id})
usr = (await db.user.find_first(where={"id": file.user_id})).username if group_id != "private" else None
files_response.append(
{
"file_url": file.url,
Expand All @@ -365,7 +365,7 @@ async def getFiles(
"creation_date": file.created_date,
"craeted_at": file.craeted_at,
"size": utils.calculate_size(file.size),
"username": (usr.username if usr else None) if group_id != "private" else None,
"username": usr,
"synced": True,
}
)
Expand All @@ -374,7 +374,9 @@ async def getFiles(
"status": "success",
"message": "messages got successfully",
"username": user.username,
"is_group_owner": None if group_id == "private" else group.admin_id == token_db.user_id,
"is_group_owner": (
None if group_id == "private" else group.admin_id == token_db.user_id
),
"data": files_response,
},
status_code=200,
Expand Down Expand Up @@ -754,12 +756,15 @@ async def generate_invite(
status_code=403,
)

invite = await db.invitements.create(data={"data": utils.generate_token(15),
"group":{
'connect':{"id": group.id}
}})
invite = await db.invitements.create(
data={"data": utils.generate_token(15), "group": {"connect": {"id": group.id}}}
)

return {"status": "success", "message": "created", "invite_link": f"https://fu.andcool.ru/invite/{invite.data}"}
return {
"status": "success",
"message": "created",
"invite_link": f"https://fu.andcool.ru/invite/{invite.data}",
}


@app.post("/api/join/{invite_link}") # join handler
Expand Down Expand Up @@ -791,7 +796,9 @@ async def delete_group(
{"status": "error", "message": "Invite link not found"}, status_code=404
)

group = await db.group.find_first(where={"id": invite.group_id}, include={"members": True})
group = await db.group.find_first(
where={"id": invite.group_id}, include={"members": True}
)
if token_db.user in group.members:
return JSONResponse(
{"status": "error", "message": "You are already in the group"},
Expand Down Expand Up @@ -846,7 +853,6 @@ async def delete_group(
{"status": "error", "message": "Invite link not found"}, status_code=404
)


return {
"status": "success",
"message": "Info got successfully",
Expand Down Expand Up @@ -928,8 +934,8 @@ async def get_groups(
"group_id": group.group_id,
}
)

return {"status": "success", "message": "groups got successfully", "groups": groups}


if __name__ == "__main__": # Start program
uvicorn.run("main:app", reload=True, port=8080)
4 changes: 2 additions & 2 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<link rel="stylesheet" href="style.css">
<link rel="preload" as="image" href="./res/globe_on.png">
<link rel="preload" as="image" href="./res/globe_off.png">
<link rel="preload" as="image" href="./res/external-link.png">
<link rel="preload" as="image" href="./res/external-link.svg">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="login/script.js"></script>
<script src="script.js"></script>
Expand Down Expand Up @@ -94,7 +94,7 @@ <h1>File uploader</h1>
</div>
<div style="display: none;" id="invite_link_link">
<p style="margin-bottom: 5px; margin-top: 5px">Generated invite link:</p>
<p id="invite_link" style="margin: 0%; font-size: 90%; margin-left: 2px; cursor:pointer;"></p>
<p id="invite_link" style="margin: 0%; font-size: 90%; margin-left: 2px; cursor:pointer; overflow-wrap: anywhere;"></p>
</div>
<div id="group_create_div" style="display: none;">
<p style="margin-bottom: 5px; margin-left: 0;">Create group</p>
Expand Down
4 changes: 4 additions & 0 deletions web/res/external-link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion web/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function append_to_files_arr(data, id) {
a_btn.title = "Open in new tab";

let href_img = document.createElement("img");
href_img.src = "./res/external-link.png";
href_img.src = "./res/external-link.svg";
href_img.id = "external";
a_btn.appendChild(href_img);

let username = document.createElement("p");
Expand Down
6 changes: 6 additions & 0 deletions web/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ nav a:hover{
transition: background-color 0.2s;
}

#external{
width: 16px;
height: 16px;

}

@media(max-width: 425px){
main{width: 90%;}
h1{font-size: 130%;}
Expand Down

0 comments on commit fad5956

Please sign in to comment.