vw_small

Hardened fork of Vaultwarden (https://github.com/dani-garcia/vaultwarden) with fewer features.
git clone https://git.philomathiclife.com/repos/vw_small
Log | Files | Refs | README

sends.rs (4668B)


      1 use crate::{
      2     auth::Headers,
      3     error::Error,
      4     util::{NumberOrString, SafeString},
      5 };
      6 use chrono::{DateTime, Utc};
      7 use rocket::{
      8     form::Form,
      9     fs::{NamedFile, TempFile},
     10     serde::json::Json,
     11 };
     12 use serde_json::Value;
     13 
     14 pub fn routes() -> Vec<rocket::Route> {
     15     routes![
     16         delete_send,
     17         download_send,
     18         get_send,
     19         get_sends,
     20         post_access,
     21         post_access_file,
     22         post_send,
     23         post_send_file,
     24         post_send_file_v2,
     25         post_send_file_v2_data,
     26         put_remove_password,
     27         put_send,
     28     ]
     29 }
     30 
     31 #[derive(Deserialize)]
     32 #[serde(rename_all = "camelCase")]
     33 struct SendData {
     34     #[allow(dead_code)]
     35     r#type: i32,
     36     #[allow(dead_code)]
     37     key: String,
     38     #[allow(dead_code)]
     39     password: Option<String>,
     40     #[allow(dead_code)]
     41     max_access_count: Option<NumberOrString>,
     42     #[allow(dead_code)]
     43     expiration_date: Option<DateTime<Utc>>,
     44     #[allow(dead_code)]
     45     deletion_date: DateTime<Utc>,
     46     #[allow(dead_code)]
     47     disabled: bool,
     48     #[allow(dead_code)]
     49     hide_email: Option<bool>,
     50     #[allow(dead_code)]
     51     name: String,
     52     #[allow(dead_code)]
     53     notes: Option<String>,
     54     #[allow(dead_code)]
     55     text: Option<Value>,
     56     #[allow(dead_code)]
     57     file: Option<Value>,
     58     #[allow(dead_code)]
     59     file_length: Option<NumberOrString>,
     60     #[allow(dead_code)]
     61     id: Option<String>,
     62 }
     63 
     64 #[allow(unused_variables, clippy::needless_pass_by_value)]
     65 #[get("/sends")]
     66 fn get_sends(_headers: Headers) -> Json<Value> {
     67     Json(json!({
     68       "data": Vec::<Value>::new(),
     69       "object": "list",
     70       "continuationToken": null
     71     }))
     72 }
     73 const SENDS_DISABLED_MSG: &str = "Sends are disabled.";
     74 #[allow(unused_variables, clippy::needless_pass_by_value)]
     75 #[get("/sends/<uuid>")]
     76 fn get_send(uuid: &str, _headers: Headers) -> Error {
     77     Error::new(SENDS_DISABLED_MSG, SENDS_DISABLED_MSG)
     78 }
     79 
     80 #[allow(unused_variables, clippy::needless_pass_by_value)]
     81 #[post("/sends", data = "<data>")]
     82 fn post_send(data: Json<SendData>, _headers: Headers) -> Error {
     83     Error::new(SENDS_DISABLED_MSG, SENDS_DISABLED_MSG)
     84 }
     85 
     86 #[allow(dead_code)]
     87 #[derive(FromForm)]
     88 struct UploadData<'f> {
     89     model: Json<SendData>,
     90     data: TempFile<'f>,
     91 }
     92 
     93 #[allow(dead_code)]
     94 #[derive(FromForm)]
     95 struct UploadDataV2<'f> {
     96     data: TempFile<'f>,
     97 }
     98 
     99 #[allow(unused_variables, clippy::needless_pass_by_value)]
    100 #[post("/sends/file", format = "multipart/form-data", data = "<data>")]
    101 fn post_send_file(data: Form<UploadData<'_>>, _headers: Headers) -> Error {
    102     Error::new(SENDS_DISABLED_MSG, SENDS_DISABLED_MSG)
    103 }
    104 
    105 #[allow(unused_variables, clippy::needless_pass_by_value)]
    106 #[post("/sends/file/v2", data = "<data>")]
    107 fn post_send_file_v2(data: Json<SendData>, _headers: Headers) -> Error {
    108     Error::new(SENDS_DISABLED_MSG, SENDS_DISABLED_MSG)
    109 }
    110 
    111 #[allow(unused_variables, clippy::needless_pass_by_value)]
    112 #[post(
    113     "/sends/<send_uuid>/file/<file_id>",
    114     format = "multipart/form-data",
    115     data = "<data>"
    116 )]
    117 fn post_send_file_v2_data(
    118     send_uuid: &str,
    119     file_id: &str,
    120     data: Form<UploadDataV2<'_>>,
    121     _headers: Headers,
    122 ) -> Error {
    123     Error::new(SENDS_DISABLED_MSG, SENDS_DISABLED_MSG)
    124 }
    125 
    126 #[derive(Deserialize)]
    127 #[serde(rename_all = "camelCase")]
    128 struct SendAccessData {
    129     #[allow(dead_code)]
    130     password: Option<String>,
    131 }
    132 
    133 #[allow(unused_variables, clippy::needless_pass_by_value)]
    134 #[post("/sends/access/<access_id>", data = "<data>")]
    135 fn post_access(access_id: &str, data: Json<SendAccessData>) -> Error {
    136     Error::new(SENDS_DISABLED_MSG, SENDS_DISABLED_MSG)
    137 }
    138 
    139 #[allow(unused_variables, clippy::needless_pass_by_value)]
    140 #[post("/sends/<send_id>/access/file/<file_id>", data = "<data>")]
    141 fn post_access_file(send_id: &str, file_id: &str, data: Json<SendAccessData>) -> Error {
    142     Error::new(SENDS_DISABLED_MSG, SENDS_DISABLED_MSG)
    143 }
    144 
    145 #[allow(unused_variables, clippy::needless_pass_by_value)]
    146 #[get("/sends/<send_id>/<file_id>?<t>")]
    147 fn download_send(send_id: SafeString, file_id: SafeString, t: &str) -> Option<NamedFile> {
    148     None
    149 }
    150 
    151 #[allow(unused_variables, clippy::needless_pass_by_value)]
    152 #[put("/sends/<id>", data = "<data>")]
    153 fn put_send(id: &str, data: Json<SendData>, _headers: Headers) -> Error {
    154     Error::new(SENDS_DISABLED_MSG, SENDS_DISABLED_MSG)
    155 }
    156 
    157 #[allow(unused_variables, clippy::needless_pass_by_value)]
    158 #[delete("/sends/<id>")]
    159 fn delete_send(id: &str, _headers: Headers) -> Error {
    160     Error::new(SENDS_DISABLED_MSG, SENDS_DISABLED_MSG)
    161 }
    162 
    163 #[allow(unused_variables, clippy::needless_pass_by_value)]
    164 #[put("/sends/<id>/remove-password")]
    165 fn put_remove_password(id: &str, _headers: Headers) -> Error {
    166     Error::new(SENDS_DISABLED_MSG, SENDS_DISABLED_MSG)
    167 }