Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Ephemeral
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Volkor Barbarian Warrior
Ephemeral
Commits
ab3dbb6a
Verified
Commit
ab3dbb6a
authored
1 year ago
by
Volkor Barbarian Warrior
Browse files
Options
Downloads
Patches
Plain Diff
forgot one
parent
596f3616
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/handlers/upload.rs
+8
-9
8 additions, 9 deletions
src/handlers/upload.rs
with
8 additions
and
9 deletions
src/handlers/upload.rs
+
8
−
9
View file @
ab3dbb6a
...
...
@@ -6,7 +6,7 @@ use std::{
path
::{
Path
,
PathBuf
},
time
::
SystemTime
,
};
use
tracing
::{
debug
,
error
,
info
};
use
tracing
::{
debug
,
error
,
info
,
trace
};
use
super
::
guess_ip
;
use
crate
::{
...
...
@@ -25,7 +25,7 @@ pub async fn upload(req: &mut Request, res: &mut Response) {
let
remote_addr
=
&
req
.remote_addr
()
.clone
();
// Get the host header for nicely setting up the response.
let
host
=
headers
[
HOST
]
.to_str
()
.unwrap_or
(
"localhost:8282"
);
tracing
::
debug!
(
"upload(req): {:?}"
,
req
);
debug!
(
"upload(req): {:?}"
,
req
);
// Check if the request was done in https or not by seeing if "x-forwarded-proto" exists.
let
mut
https
:
String
=
"http"
.to_string
();
...
...
@@ -61,12 +61,12 @@ pub async fn upload(req: &mut Request, res: &mut Response) {
.read_to_end
(
&
mut
buffer
)
.expect
(
"couldn't read mimetype buffer"
);
tracing
::
trace!
(
"read bytes for mime parsing: {:x?}"
,
buffer
);
trace!
(
"read bytes for mime parsing: {:x?}"
,
buffer
);
// Guess the mimetype
let
mimetype
:
&
str
=
&
detect_mime_type
(
&
buffer
)
.unwrap_or
(
"text/plain"
.to_string
());
tracing
::
debug!
(
"upload(mimetype): {:?}"
,
mimetype
);
debug!
(
"upload(mimetype): {:?}"
,
mimetype
);
// Check if the mimetype is banned, and render the error pages.
if
is_mimetype_banned
(
mimetype
)
.await
{
...
...
@@ -93,17 +93,16 @@ pub async fn upload(req: &mut Request, res: &mut Response) {
// Generate the admin key.
let
adminkey
=
engine
::
generate_adminkey
(
sqlconn
)
.await
;
tracing
::
debug!
(
"upload(filename, adminkey): {:?}, {:?}"
,
filename
,
adminkey
);
debug!
(
"upload(filename, adminkey): {:?}, {:?}"
,
filename
,
adminkey
);
// Set Destination
let
dest
:
PathBuf
=
PathBuf
::
from
(
"files/"
)
.join
(
&
filename
);
// Copy the file
if
let
Err
(
e
)
=
std
::
fs
::
copy
(
file
.path
(),
Path
::
new
(
&
dest
))
{
tracing
::
error!
(
error!
(
"There was a problem uploading file: {:?}, error: {}"
,
dest
,
e
dest
,
e
);
// If web is true, render html, otherwise json.
if
upload_by_web
{
...
...
@@ -169,7 +168,7 @@ pub async fn upload(req: &mut Request, res: &mut Response) {
error!
(
"File upload error: {:?}"
,
e
);
}
info!
(
"File uploaded to {:?}"
,
dest
);
info!
(
"
[{}]
File uploaded to {:?}"
,
&
host
,
dest
);
let
fileurl
=
format!
(
"{}://{}/{}"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment