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
12f99692
Verified
Commit
12f99692
authored
1 year ago
by
Volkor Barbarian Warrior
Browse files
Options
Downloads
Patches
Plain Diff
fix: improve logging
parent
3438a655
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/serve_file.rs
+12
-12
12 additions, 12 deletions
src/handlers/serve_file.rs
with
12 additions
and
12 deletions
src/handlers/serve_file.rs
+
12
−
12
View file @
12f99692
...
...
@@ -11,7 +11,7 @@ use salvo::{
Request
,
Response
,
};
use
std
::
time
::
SystemTime
;
use
tracing
::
debug
;
use
tracing
::
{
debug
,
info
,
error
}
;
use
crate
::{
db
::{
self
,
FileCheckResult
},
...
...
@@ -28,7 +28,7 @@ pub async fn render_file(req: &mut Request, res: &mut Response, headers: HeaderM
.param
(
"file"
)
.expect
(
"Failed to set the filename variable"
);
tracing
::
info!
(
"
New
File View: {:?}"
,
&
filename
.to_string
());
info!
(
"
[{}]
File View: {:?}"
,
&
headers
[
HOST
]
.to_str
()
.unwrap
(),
&
filename
.to_string
());
// Get a new sql pool thingy
let
sqlconn
=
SQLITE
.get
()
.expect
(
"Failed to grab sqlite pool"
);
...
...
@@ -47,7 +47,7 @@ pub async fn render_file(req: &mut Request, res: &mut Response, headers: HeaderM
.any
(|
mime
|
mime
.clone
()
==
mimetype
.clone
())
{
// Check if any of the unsafe mime types match the given mimetype
tracing
::
info!
(
"Unsafe Extension Filtered: {:?}"
,
mimetype
);
info!
(
"Unsafe Extension Filtered: {:?}"
,
mimetype
);
mimetype
=
String
::
from
(
"text/plain"
);
// If there is a match, change the mimetype to text/plain
}
...
...
@@ -62,12 +62,12 @@ pub async fn render_file(req: &mut Request, res: &mut Response, headers: HeaderM
db
::
update_fileview
(
sqlconn
,
&
filename
,
accessed
)
.await
.unwrap_or_else
(|
err
|
{
tracing
::
error!
(
error!
(
"Failed to update fileview for file: {} error: {:?}"
,
&
filename
,
err
);
tracing
::
error!
(
"soft-setting fileview to 0 for file: {}"
,
&
filename
);
error!
(
"soft-setting fileview to 0 for file: {}"
,
&
filename
);
0
});
...
...
@@ -89,7 +89,7 @@ pub async fn render_file(req: &mut Request, res: &mut Response, headers: HeaderM
res
.add_header
(
"Content-Type"
,
mimetype
,
true
)
.unwrap
();
// Go through all the headers and print them out, just to check for now!
tracing
::
debug!
(
"response headers: {:?}"
,
res
.headers
());
debug!
(
"response headers: {:?}"
,
res
.headers
());
// https://github.com/salvo-rs/salvo/issues/233
res
.status_code
(
StatusCode
::
OK
);
...
...
@@ -106,7 +106,7 @@ pub async fn render_file(req: &mut Request, res: &mut Response, headers: HeaderM
res
.add_header
(
"Content-Type"
,
mimetype
,
true
)
.unwrap
();
// Go through all the headers and print them out, just to check for now!
tracing
::
debug!
(
"response headers: {:?}"
,
res
.headers
());
debug!
(
"response headers: {:?}"
,
res
.headers
());
res
.status_code
(
StatusCode
::
OK
);
}
...
...
@@ -169,16 +169,16 @@ pub async fn serve_file(req: &mut Request, res: &mut Response) {
match
check_file_exists
(
&
filename
,
"files/"
)
.await
{
// File does exist in the filesystem!
true
=>
{
debug
!
(
"Adding previously unknown file to the database
."
);
info
!
(
"Adding previously unknown file to the database
: {}"
,
&
filename
);
// Add the file to the database
match
add_undeleted_file
(
&
filename
)
.await
{
Ok
(
_
)
=>
{
tracing
::
info!
(
"Successfully added
file
back into the database"
);
info!
(
"Successfully added
{}
back into the database"
,
&
filename
);
// Now we can render the file!
render_file
(
req
,
res
,
headers
)
.await
}
Err
(
_
)
=>
{
tracing
::
error!
(
"Error while adding
file
back into the database"
);
error!
(
"Error while adding
{}
back into the database"
,
&
filename
);
// TODO: Refactor a nice error rendering function, were we just pass the errorcode, and message
render_404
(
res
,
upload_by_web
,
headers
)
.await
}
...
...
@@ -186,7 +186,7 @@ pub async fn serve_file(req: &mut Request, res: &mut Response) {
}
// File doesn't exist in the filesystem :(
false
=>
{
tracing
::
debug!
(
"Double checked,
file
truly doesn't exist."
);
debug!
(
"Double checked,
{}
truly doesn't exist."
,
&
filename
);
render_404
(
res
,
upload_by_web
,
headers
)
.await
}
}
...
...
@@ -194,7 +194,7 @@ pub async fn serve_file(req: &mut Request, res: &mut Response) {
// Error while finding file in the database
Err
(
err
)
=>
{
tracing
::
error!
(
"Error while trying to check the filename: {:?}"
,
err
);
error!
(
"Error while trying to check the filename: {:?}"
,
err
);
if
upload_by_web
{
let
template_filename
=
"error.html"
;
...
...
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