src: cargo clippy and fmt the project
Signed-off-by: Gunwant Jain <mail@wantguns.dev>
This commit is contained in:
@@ -3,7 +3,10 @@ extern crate rocket;
|
|||||||
use std::{fs, net::IpAddr, path::PathBuf};
|
use std::{fs, net::IpAddr, path::PathBuf};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use rocket::{shield::{NoSniff, Shield}, figment::{providers::Env, Figment}};
|
use rocket::{
|
||||||
|
figment::{providers::Env, Figment},
|
||||||
|
shield::{NoSniff, Shield},
|
||||||
|
};
|
||||||
use rocket_dyn_templates::{tera::Tera, Template};
|
use rocket_dyn_templates::{tera::Tera, Template};
|
||||||
use rust_embed::RustEmbed;
|
use rust_embed::RustEmbed;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::Path;
|
||||||
|
|
||||||
use syntect::highlighting::ThemeSet;
|
use syntect::highlighting::ThemeSet;
|
||||||
use syntect::html::highlighted_html_for_string;
|
use syntect::html::highlighted_html_for_string;
|
||||||
use syntect::parsing::SyntaxSet;
|
use syntect::parsing::SyntaxSet;
|
||||||
|
|
||||||
pub fn get_pretty_body(path: &PathBuf, ext: &String) -> String {
|
pub fn get_pretty_body(path: &Path, ext: &str) -> String {
|
||||||
let ss = SyntaxSet::load_defaults_newlines();
|
let ss = SyntaxSet::load_defaults_newlines();
|
||||||
|
|
||||||
let mut theme_cursor =
|
let mut theme_cursor =
|
||||||
@@ -16,7 +16,6 @@ pub fn get_pretty_body(path: &PathBuf, ext: &String) -> String {
|
|||||||
let syntax = ss
|
let syntax = ss
|
||||||
.find_syntax_by_token(ext)
|
.find_syntax_by_token(ext)
|
||||||
.unwrap_or_else(|| ss.find_syntax_plain_text());
|
.unwrap_or_else(|| ss.find_syntax_plain_text());
|
||||||
let html = highlighted_html_for_string(&content, &ss, syntax, &theme);
|
|
||||||
|
|
||||||
html
|
highlighted_html_for_string(&content, &ss, syntax, &theme)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ pub struct PasteIdSyntax<'a> {
|
|||||||
|
|
||||||
fn valid_syn(syn: &str) -> bool {
|
fn valid_syn(syn: &str) -> bool {
|
||||||
let mut flag = false;
|
let mut flag = false;
|
||||||
let split: Vec<&str> = syn.split(".").collect();
|
let split: Vec<&str> = syn.split('.').collect();
|
||||||
if split.len() == 2 {
|
if split.len() == 2 {
|
||||||
for s in split {
|
for s in split {
|
||||||
if s.chars().all(char::is_alphanumeric) {
|
if s.chars().all(char::is_alphanumeric) {
|
||||||
@@ -22,10 +22,10 @@ fn valid_syn(syn: &str) -> bool {
|
|||||||
|
|
||||||
impl<'a> PasteIdSyntax<'a> {
|
impl<'a> PasteIdSyntax<'a> {
|
||||||
pub fn get_fname(&self) -> &str {
|
pub fn get_fname(&self) -> &str {
|
||||||
&self.syn_id.split(".").collect::<Vec<&str>>()[0]
|
self.syn_id.split('.').collect::<Vec<&str>>()[0]
|
||||||
}
|
}
|
||||||
pub fn get_ext(&self) -> &str {
|
pub fn get_ext(&self) -> &str {
|
||||||
&self.syn_id.split(".").collect::<Vec<&str>>()[1]
|
self.syn_id.split('.').collect::<Vec<&str>>()[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ pub async fn pretty_retrieve_ext(
|
|||||||
let id = id_ext.get_fname();
|
let id = id_ext.get_fname();
|
||||||
let ext = id_ext.get_ext();
|
let ext = id_ext.get_ext();
|
||||||
|
|
||||||
let filepath = Path::new(&get_upload_dir()).join(format!("{id}", id = id));
|
let filepath = Path::new(&get_upload_dir()).join(id.to_string());
|
||||||
|
|
||||||
let contents = get_pretty_body(&filepath, &ext.to_string());
|
let contents = get_pretty_body(&filepath, &ext.to_string());
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,5 @@ pub async fn retrieve(id: PasteId<'_>) -> Option<File> {
|
|||||||
pub async fn retrieve_ext(id_ext: PasteIdSyntax<'_>) -> Option<File> {
|
pub async fn retrieve_ext(id_ext: PasteIdSyntax<'_>) -> Option<File> {
|
||||||
// let filename = format!("upload/{id}", id = id_ext.get_fname());
|
// let filename = format!("upload/{id}", id = id_ext.get_fname());
|
||||||
|
|
||||||
File::open(get_upload_dir().join(format!("{id}", id = id_ext.get_fname())))
|
File::open(get_upload_dir().join(id_ext.get_fname().to_string())).ok()
|
||||||
.ok()
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user