Skip to content

Commit

Permalink
created uploaders page, changed file delete method to GET
Browse files Browse the repository at this point in the history
  • Loading branch information
Andcool-Systems committed Jan 28, 2024
1 parent 0acb971 commit e65777f
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Upon successful execution, the API returns a `200` status code along with a JSON
| 400 | Bad file extension | The file does not have an extension |
| 413 | File size exceeds the limit (100MB) | The file size exceeds 100MB |

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

#### Possible Errors
Expand Down
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async def send_file(url: str, request: Request):
return FileResponse(path=result.filename, filename=result.user_filename, media_type=result.type) # Send file as FileResponse


@app.delete("/api/delete/{url}") # File delete handler
@app.get("/api/delete/{url}") # File delete handler
async def delete_file(url: str, key: str = ""):
result = await db.file.find_first(where={"url": url}) # Get file record by url
if not result: return JSONResponse(content={"status": "error", "message": "File not found"}, status_code=200) # if file does'n exists
Expand All @@ -186,6 +186,7 @@ async def delete_file(url: str, key: str = ""):
else: # If provided key doesn't matched with key from database record
return JSONResponse(content={"status": "error", "message": "invalid unique key"}, status_code=400)


@app.get("/api/getFiles") # get files handler
@limiter.limit(f"10/minute")
async def getFiles(request: Request,
Expand Down
3 changes: 2 additions & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@
<main>
<h1>File uploader</h1>
<nav>
<a href="https://fu.andcool.ru" class="selected">Home</a>
<a class="selected">Home</a>
<a href="https://fu.andcool.ru/login/" id="login_page_a">Login</a>
<a href="https://fu.andcool.ru/tos/" id="login_page_a">ToS</a>
<a id="login_page_a" href="https://fu.andcool.ru/uploaders/">Uploaders</a>
<a href="https://github.com/Andcool-Systems/File-uploader" target="_blank">GitHub</a>
</nav>
<hr>
Expand Down
3 changes: 2 additions & 1 deletion web/login/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
<h1>File uploader</h1>
<nav>
<a href="https://fu.andcool.ru">Home</a>
<a href="https://fu.andcool.ru/login/" class="selected">Login</a>
<a class="selected">Login</a>
<a href="https://fu.andcool.ru/tos/" id="login_page_a">ToS</a>
<a id="login_page_a" href="https://fu.andcool.ru/uploaders/">Uploaders</a>
<a href="https://github.com/Andcool-Systems/File-uploader" target="_blank">GitHub</a>
</nav>
<hr>
Expand Down
2 changes: 1 addition & 1 deletion web/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let api_url = "https://fu.andcool.ru";
async function delete_file(data, id){
let confirmed = confirm("Delete it? It will be impossible to restore the file!");
if (confirmed){
let response = await axios.delete(api + "/api/delete/" + data.file_url + "?key=" + data.key);
let response = await axios.get(api + "/api/delete/" + data.file_url + "?key=" + data.key);
if (response.status == 200){
if (!data.synced){
let old_data = JSON.parse(localStorage.getItem("file_history") || "[]");
Expand Down
3 changes: 2 additions & 1 deletion web/tos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<h1>File uploader</h1>
<nav>
<a href="https://fu.andcool.ru">Home</a>
<a href="https://fu.andcool.ru/tos/" id="login_page_a" class="selected">ToS</a>
<a id="login_page_a" class="selected">ToS</a>
<a id="login_page_a" href="https://fu.andcool.ru/uploaders/">Uploaders</a>
<a href="https://github.com/Andcool-Systems/File-uploader" target="_blank">GitHub</a>
</nav>
<hr>
Expand Down
15 changes: 15 additions & 0 deletions web/uploaders/File uploader.sxcu
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"Version": "15.0.0",
"Name": "File uploader",
"DestinationType": "ImageUploader, FileUploader",
"RequestMethod": "POST",
"RequestURL": "https://fu.andcool.ru/api/upload",
"Parameters": {
"include_ext": "true"
},
"Body": "MultipartFormData",
"FileFormName": "file",
"URL": "{json:file_url_full}",
"DeletionURL": "https://fu.andcool.ru/api/delete/{json:file_url}?key={json:key}",
"ErrorMessage": "{json:message}"
}
31 changes: 31 additions & 0 deletions web/uploaders/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>File uploader</title>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Manrope:wght@800&family=Roboto+Mono&display=swap" rel="stylesheet">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="../style.css">
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>


<body>
<main>
<h1>File uploader</h1>
<nav>
<a href="https://fu.andcool.ru">Home</a>
<a id="login_page_a" href="https://fu.andcool.ru/tos/">ToS</a>
<a id="login_page_a" class="selected">Uploaders</a>
<a href="https://github.com/Andcool-Systems/File-uploader" target="_blank">GitHub</a>
</nav>
<hr>
<p style="margin-top: 0%;font-size: 80%;">by AndcoolSystems</p>
<h2 style="font-weight: 600;">ShareX</h2>
<p id="sharex"><a href="/uploaders/File uploader.sxcu" download="File uploader.sxcu">Click here</a> to download the ShareX config</p>

</main>
</body>
</html>
14 changes: 14 additions & 0 deletions web/uploaders/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
h2{
margin-bottom: 1%;
}

#sharex{
margin: 0%;
margin-left: 15px;
}

#sharex a{
color:white;
text-decoration: underline;

}

0 comments on commit e65777f

Please sign in to comment.