From 7e250b54b15a2cb3880170cebb424618e8fd4b8f Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 5 Mar 2023 13:04:09 +0800 Subject: [PATCH] feat: secfile content-type --- post-rs/src/main.rs | 117 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) diff --git a/post-rs/src/main.rs b/post-rs/src/main.rs index 6a68550..feeca0c 100644 --- a/post-rs/src/main.rs +++ b/post-rs/src/main.rs @@ -13,12 +13,13 @@ use std::collections::HashMap; use std::fs; use std::path::PathBuf; + use base64::Engine; use clap::{arg, Parser}; use rust_util::{debugging, failure_and_exit, information, success}; #[derive(Parser, Debug)] -#[command(author, version, about, long_about = None, bin_name="post.rs")] +#[command(author, version, about, long_about = None, bin_name = "post.rs")] struct Args { /// Access Token, or from environment: POST_RS_TOKEN #[arg(short, long)] @@ -107,8 +108,122 @@ fn main() { } fn get_content_type(file_name: &str) -> String { + let file_name = file_name.to_ascii_lowercase(); if file_name.ends_with(".txt") { "text/plain".into() + } else if file_name.ends_with(".aac") { + "audio/aac".into() + } else if file_name.ends_with(".avi") { + "video/x-msvideo".into() + } else if file_name.ends_with(".css") { + "text/css".into() + } else if file_name.ends_with(".csv") { + "text/csv".into() + } else if file_name.ends_with(".doc") { + "application/msword".into() + } else if file_name.ends_with(".docx") { + "application/vnd.openxmlformats-officedocument.wordprocessingml.document".into() + } else if file_name.ends_with(".eot") { + "application/vnd.ms-fontobject".into() + } else if file_name.ends_with(".epub") { + "application/epub+zip".into() + } else if file_name.ends_with(".gz") { + "application/gzip".into() + } else if file_name.ends_with(".dif") { + "image/gif".into() + } else if file_name.ends_with(".htm") + || file_name.ends_with(".html") { + "text/html".into() + } else if file_name.ends_with(".ico") { + "image/vnd.microsoft.icon".into() + } else if file_name.ends_with(".jar") { + "application/java-archive".into() + } else if file_name.ends_with(".jpe") + || file_name.ends_with(".jpg") + || file_name.ends_with(".jpeg") { + "image/jpeg".into() + } else if file_name.ends_with(".js") { + "text/javascript".into() + } else if file_name.ends_with(".json") { + "application/json".into() + } else if file_name.ends_with(".jsonld") { + "application/ld+json".into() + } else if file_name.ends_with(".mid") + || file_name.ends_with(".midi") { + "audio/midi".into() + } else if file_name.ends_with(".mp3") { + "audio/mpeg".into() + } else if file_name.ends_with(".mp4") { + "video/mp4".into() + } else if file_name.ends_with(".mpeg") { + "video/mpeg".into() + } else if file_name.ends_with(".mpkg") { + "application/vnd.apple.installer+xml".into() + } else if file_name.ends_with(".odp") { + "application/vnd.oasis.opendocument.presentation".into() + } else if file_name.ends_with(".ods") { + "application/vnd.oasis.opendocument.spreadsheet".into() + } else if file_name.ends_with(".odt") { + "application/vnd.oasis.opendocument.text".into() + } else if file_name.ends_with(".oga") { + "audio/ogg".into() + } else if file_name.ends_with(".ogv") { + "video/ogg".into() + } else if file_name.ends_with(".ogg") { + "application/ogg".into() + } else if file_name.ends_with(".otf") { + "font/otf".into() + } else if file_name.ends_with(".png") { + "image/png".into() + } else if file_name.ends_with(".pdf") { + "application/pdf".into() + } else if file_name.ends_with(".ppt") { + "application/vnd.ms-powerpoint".into() + } else if file_name.ends_with(".pptx") { + "application/vnd.openxmlformats-officedocument.presentationml.presentation".into() + } else if file_name.ends_with(".rar") { + "application/vnd.rar".into() + } else if file_name.ends_with(".rtf") { + "application/rtf".into() + } else if file_name.ends_with(".sh") { + "application/x-sh".into() + } else if file_name.ends_with(".svg") { + "image/svg+xml".into() + } else if file_name.ends_with(".tar") { + "application/x-tar".into() + } else if file_name.ends_with(".tif") + || file_name.ends_with(".tiff") { + "image/tiff".into() + } else if file_name.ends_with(".ts") { + "video/mp2t".into() + } else if file_name.ends_with(".ttf") { + "font/ttf".into() + } else if file_name.ends_with(".wav") { + "audio/wav".into() + } else if file_name.ends_with(".weba") { + "audio/webm".into() + } else if file_name.ends_with(".webm") { + "video/webm".into() + } else if file_name.ends_with(".webp") { + "image/webp".into() + } else if file_name.ends_with(".woff") { + "font/woff".into() + } else if file_name.ends_with(".woff2") { + "font/woff2".into() + } else if file_name.ends_with(".xhtml") { + "application/xhtml+xml".into() + } else if file_name.ends_with(".xls") { + "application/vnd.ms-excel".into() + } else if file_name.ends_with(".xlsx") { + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet".into() + } else if file_name.ends_with(".xml") { + "application/xml".into() + } else if file_name.ends_with(".zip") { + "application/zip".into() + } else if file_name.ends_with(".3gp") { + "video/3gpp".into() + } else if file_name.ends_with(".7z") { + "application/x-7z-compressed".into() } else { "application/octet-stream".into() }