1
0
Fork 0
mirror of https://codeberg.org/icewind/shelve.git synced 2026-06-03 12:04:09 +02:00

use builtin multipart handling for form upload

This commit is contained in:
Robin Appelman 2021-07-30 15:13:39 +02:00
commit 4d4108c83b
6 changed files with 163 additions and 712 deletions

596
Cargo.lock generated
View file

@ -2,60 +2,6 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "aead"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331"
dependencies = [
"generic-array",
]
[[package]]
name = "aes"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "884391ef1066acaa41e766ba8f596341b96e93ce34f9a43e7d24bf0a0eaf0561"
dependencies = [
"aes-soft",
"aesni",
"cipher",
]
[[package]]
name = "aes-gcm"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5278b5fabbb9bd46e24aa69b2fdea62c99088e0a950a9be40e3e0101298f88da"
dependencies = [
"aead",
"aes",
"cipher",
"ctr",
"ghash",
"subtle",
]
[[package]]
name = "aes-soft"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be14c7498ea50828a38d0e24a765ed2effe92a705885b57d029cd67d45744072"
dependencies = [
"cipher",
"opaque-debug",
]
[[package]]
name = "aesni"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea2e11f5e94c2f7d386164cc2aa1f97823fed6f259e486940a71c174dd01b0ce"
dependencies = [
"cipher",
"opaque-debug",
]
[[package]]
name = "aho-corasick"
version = "0.7.18"
@ -87,9 +33,9 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308"
dependencies = [
"proc-macro2 1.0.28",
"quote 1.0.9",
"syn 1.0.74",
"proc-macro2",
"quote",
"syn",
]
[[package]]
@ -98,9 +44,9 @@ version = "0.1.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e"
dependencies = [
"proc-macro2 1.0.28",
"quote 1.0.9",
"syn 1.0.74",
"proc-macro2",
"quote",
"syn",
]
[[package]]
@ -151,12 +97,6 @@ dependencies = [
"safemem",
]
[[package]]
name = "base64"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
name = "binascii"
version = "0.1.4"
@ -169,15 +109,6 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "block-buffer"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
dependencies = [
"generic-array",
]
[[package]]
name = "buf_redux"
version = "0.8.4"
@ -237,15 +168,6 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "498d20a7aaf62625b9bf26e637cf7736417cde1d0c99f1d04d1170229a85cf87"
[[package]]
name = "cipher"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801"
dependencies = [
"generic-array",
]
[[package]]
name = "cloudabi"
version = "0.0.3"
@ -267,22 +189,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]]
name = "cookie"
version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80f6044740a4a516b8aac14c140cdf35c1a640b1bd6b98b6224e49143b2f1566"
dependencies = [
"aes-gcm",
"base64 0.13.0",
"hkdf",
"hmac",
"percent-encoding 2.1.0",
"rand 0.8.4",
"sha2",
"time 0.1.43",
]
[[package]]
name = "cookie"
version = "0.15.1"
@ -294,40 +200,6 @@ dependencies = [
"version_check 0.9.3",
]
[[package]]
name = "cpufeatures"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef"
dependencies = [
"libc",
]
[[package]]
name = "cpuid-bool"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba"
[[package]]
name = "crypto-mac"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bff07008ec701e8028e2ceb8f83f0e4274ee62bd2dbdc4fefff2e9a91824081a"
dependencies = [
"generic-array",
"subtle",
]
[[package]]
name = "ctr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb4a30d54f7443bf3d6191dcd486aca19e67cb3c49fa7a06a319966346707e7f"
dependencies = [
"cipher",
]
[[package]]
name = "derive_more"
version = "0.99.16"
@ -335,20 +207,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df"
dependencies = [
"convert_case",
"proc-macro2 1.0.28",
"quote 1.0.9",
"proc-macro2",
"quote",
"rustc_version 0.3.3",
"syn 1.0.74",
]
[[package]]
name = "devise"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74e04ba2d03c5fa0d954c061fc8c9c288badadffc272ebb87679a89846de3ed3"
dependencies = [
"devise_codegen 0.2.0",
"devise_core 0.2.0",
"syn",
]
[[package]]
@ -357,18 +219,8 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50c7580b072f1c8476148f16e0a0d5dedddab787da98d86c5082c5e9ed8ab595"
dependencies = [
"devise_codegen 0.3.1",
"devise_core 0.3.1",
]
[[package]]
name = "devise_codegen"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "066ceb7928ca93a9bedc6d0e612a8a0424048b0ab1f75971b203d01420c055d7"
dependencies = [
"devise_core 0.2.0",
"quote 0.6.13",
"devise_codegen",
"devise_core",
]
[[package]]
@ -377,20 +229,8 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "123c73e7a6e51b05c75fe1a1b2f4e241399ea5740ed810b0e3e6cacd9db5e7b2"
dependencies = [
"devise_core 0.3.1",
"quote 1.0.9",
]
[[package]]
name = "devise_core"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf41c59b22b5e3ec0ea55c7847e5f358d340f3a8d6d53a5cf4f1564967f96487"
dependencies = [
"bitflags",
"proc-macro2 0.4.30",
"quote 0.6.13",
"syn 0.15.44",
"devise_core",
"quote",
]
[[package]]
@ -400,19 +240,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "841ef46f4787d9097405cac4e70fb8644fc037b526e8c14054247c0263c400d0"
dependencies = [
"bitflags",
"proc-macro2 1.0.28",
"proc-macro2",
"proc-macro2-diagnostics",
"quote 1.0.9",
"syn 1.0.74",
]
[[package]]
name = "digest"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
dependencies = [
"generic-array",
"quote",
"syn",
]
[[package]]
@ -449,10 +280,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcc7f65832b62ed38939f98966824eb6294911c3629b0e9a262bfb80836d9686"
dependencies = [
"proc-macro-error",
"proc-macro2 1.0.28",
"quote 1.0.9",
"proc-macro2",
"quote",
"rustversion",
"syn 1.0.74",
"syn",
"synstructure",
]
@ -463,9 +294,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "790b4292c72618abbab50f787a477014fe15634f96291de45672ce46afe122df"
dependencies = [
"atomic",
"pear 0.2.3",
"pear",
"serde",
"toml 0.5.8",
"toml",
"uncased",
"version_check 0.9.3",
]
@ -538,9 +369,9 @@ checksum = "c54913bae956fb8df7f4dc6fc90362aa72e69148e3f39041fbe8742d21e0ac57"
dependencies = [
"autocfg 1.0.1",
"proc-macro-hack",
"proc-macro2 1.0.28",
"quote 1.0.9",
"syn 1.0.74",
"proc-macro2",
"quote",
"syn",
]
[[package]]
@ -589,16 +420,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "generic-array"
version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817"
dependencies = [
"typenum",
"version_check 0.9.3",
]
[[package]]
name = "getrandom"
version = "0.2.3"
@ -610,16 +431,6 @@ dependencies = [
"wasi",
]
[[package]]
name = "ghash"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97304e4cd182c3846f7575ced3890c53012ce534ad9114046b0a9e00bb30a375"
dependencies = [
"opaque-debug",
"polyval",
]
[[package]]
name = "glob"
version = "0.3.0"
@ -666,26 +477,6 @@ dependencies = [
"libc",
]
[[package]]
name = "hkdf"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f"
dependencies = [
"digest",
"hmac",
]
[[package]]
name = "hmac"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15"
dependencies = [
"crypto-mac",
"digest",
]
[[package]]
name = "http"
version = "0.2.4"
@ -726,7 +517,7 @@ version = "0.10.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a0652d9a2609a968c14be1a9ea00bf4b1d64e2e1f53a1b51b6fff3a6e829273"
dependencies = [
"base64 0.9.3",
"base64",
"httparse",
"language-tags",
"log 0.3.9",
@ -978,28 +769,6 @@ dependencies = [
"version_check 0.9.3",
]
[[package]]
name = "multipart"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "136eed74cadb9edd2651ffba732b19a450316b680e4f48d6c79e905799e19d01"
dependencies = [
"buf_redux",
"httparse",
"hyper 0.10.16",
"iron",
"log 0.4.14",
"mime 0.2.6",
"mime_guess 1.8.8",
"nickel",
"quick-error",
"rand 0.6.5",
"safemem",
"tempfile",
"tiny_http",
"twoway 0.1.8",
]
[[package]]
name = "multipart"
version = "0.18.0"
@ -1097,12 +866,6 @@ version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
[[package]]
name = "opaque-debug"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "parking_lot"
version = "0.11.1"
@ -1128,15 +891,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "pear"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5320f212db967792b67cfe12bd469d08afd6318a249bd917d5c19bc92200ab8a"
dependencies = [
"pear_codegen 0.1.4",
]
[[package]]
name = "pear"
version = "0.2.3"
@ -1144,20 +898,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15e44241c5e4c868e3eaa78b7c1848cadd6344ed4f54d029832d32b415a58702"
dependencies = [
"inlinable_string",
"pear_codegen 0.2.3",
"yansi",
]
[[package]]
name = "pear_codegen"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfc1c836fdc3d1ef87c348b237b5b5c4dff922156fb2d968f57734f9669768ca"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"syn 0.15.44",
"version_check 0.9.3",
"pear_codegen",
"yansi",
]
@ -1167,10 +908,10 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82a5ca643c2303ecb740d506539deba189e16f2754040a42901cd8105d0282d0"
dependencies = [
"proc-macro2 1.0.28",
"proc-macro2",
"proc-macro2-diagnostics",
"quote 1.0.9",
"syn 1.0.74",
"quote",
"syn",
]
[[package]]
@ -1254,17 +995,6 @@ dependencies = [
"typemap",
]
[[package]]
name = "polyval"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eebcc4aa140b9abd2bc40d9c3f7ccec842679cd79045ac3a7ac698c1a064b7cd"
dependencies = [
"cpuid-bool",
"opaque-debug",
"universal-hash",
]
[[package]]
name = "ppv-lite86"
version = "0.2.10"
@ -1288,9 +1018,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2 1.0.28",
"quote 1.0.9",
"syn 1.0.74",
"proc-macro2",
"quote",
"syn",
"version_check 0.9.3",
]
@ -1300,8 +1030,8 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2 1.0.28",
"quote 1.0.9",
"proc-macro2",
"quote",
"version_check 0.9.3",
]
@ -1317,22 +1047,13 @@ version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086"
[[package]]
name = "proc-macro2"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
dependencies = [
"unicode-xid 0.1.0",
]
[[package]]
name = "proc-macro2"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612"
dependencies = [
"unicode-xid 0.2.2",
"unicode-xid",
]
[[package]]
@ -1341,9 +1062,9 @@ version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bf29726d67464d49fa6224a1d07936a8c08bb3fba727c7493f6cf1616fdaada"
dependencies = [
"proc-macro2 1.0.28",
"quote 1.0.9",
"syn 1.0.74",
"proc-macro2",
"quote",
"syn",
"version_check 0.9.3",
"yansi",
]
@ -1354,22 +1075,13 @@ version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quote"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
dependencies = [
"proc-macro2 0.4.30",
]
[[package]]
name = "quote"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
"proc-macro2 1.0.28",
"proc-macro2",
]
[[package]]
@ -1551,9 +1263,9 @@ version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c38e3aecd2b21cb3959637b883bb3714bc7e43f0268b9a29d3743ee3e55cdd2"
dependencies = [
"proc-macro2 1.0.28",
"quote 1.0.9",
"syn 1.0.74",
"proc-macro2",
"quote",
"syn",
]
[[package]]
@ -1582,27 +1294,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "rocket"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a7ab1dfdc75bb8bd2be381f37796b1b300c45a3c9145b34d86715e8dd90bf28"
dependencies = [
"atty",
"base64 0.13.0",
"log 0.4.14",
"memchr",
"num_cpus",
"pear 0.1.4",
"rocket_codegen 0.4.10",
"rocket_http 0.4.10",
"state 0.4.2",
"time 0.1.43",
"toml 0.4.10",
"version_check 0.9.3",
"yansi",
]
[[package]]
name = "rocket"
version = "0.5.0-rc.1"
@ -1627,10 +1318,10 @@ dependencies = [
"pin-project-lite",
"rand 0.8.4",
"ref-cast",
"rocket_codegen 0.5.0-rc.1",
"rocket_http 0.5.0-rc.1",
"rocket_codegen",
"rocket_http",
"serde",
"state 0.5.2",
"state",
"tempfile",
"time 0.2.27",
"tokio",
@ -1641,52 +1332,20 @@ dependencies = [
"yansi",
]
[[package]]
name = "rocket_codegen"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1729e687d6d2cf434d174da84fb948f7fef4fac22d20ce94ca61c28b72dbcf9f"
dependencies = [
"devise 0.2.0",
"glob",
"indexmap",
"quote 0.6.13",
"rocket_http 0.4.10",
"version_check 0.9.3",
"yansi",
]
[[package]]
name = "rocket_codegen"
version = "0.5.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66f5fa462f7eb958bba8710c17c5d774bbbd59809fa76fb1957af7e545aea8bb"
dependencies = [
"devise 0.3.1",
"devise",
"glob",
"indexmap",
"proc-macro2 1.0.28",
"quote 1.0.9",
"rocket_http 0.5.0-rc.1",
"syn 1.0.74",
"unicode-xid 0.2.2",
]
[[package]]
name = "rocket_http"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6131e6e6d38a9817f4a494ff5da95971451c2eb56a53915579fc9c80f6ef0117"
dependencies = [
"cookie 0.11.4",
"hyper 0.10.16",
"indexmap",
"pear 0.1.4",
"percent-encoding 1.0.1",
"smallvec",
"state 0.4.2",
"time 0.1.43",
"unicode-xid 0.1.0",
"proc-macro2",
"quote",
"rocket_http",
"syn",
"unicode-xid",
]
[[package]]
@ -1695,7 +1354,7 @@ version = "0.5.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23c8b7d512d2fcac2316ebe590cde67573844b99e6cc9ee0f53375fa16e25ebd"
dependencies = [
"cookie 0.15.1",
"cookie",
"either",
"http",
"hyper 0.14.11",
@ -1704,29 +1363,19 @@ dependencies = [
"memchr",
"mime 0.3.16",
"parking_lot",
"pear 0.2.3",
"pear",
"percent-encoding 2.1.0",
"pin-project-lite",
"ref-cast",
"serde",
"smallvec",
"stable-pattern",
"state 0.5.2",
"state",
"time 0.2.27",
"tokio",
"uncased",
]
[[package]]
name = "rocket_upload"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "241f21624894d711264e508041b3fb9cd26a1338e7c26c2c945ecbcea4bd7018"
dependencies = [
"multipart 0.16.1",
"rocket 0.4.10",
]
[[package]]
name = "rust-embed"
version = "5.9.0"
@ -1744,10 +1393,10 @@ version = "5.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed91c41c42ef7bf687384439c312e75e0da9c149b0390889b94de3c7d9d9e66"
dependencies = [
"proc-macro2 1.0.28",
"quote 1.0.9",
"proc-macro2",
"quote",
"rust-embed-utils",
"syn 1.0.74",
"syn",
"walkdir",
]
@ -1865,9 +1514,9 @@ version = "1.0.126"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43"
dependencies = [
"proc-macro2 1.0.28",
"quote 1.0.9",
"syn 1.0.74",
"proc-macro2",
"quote",
"syn",
]
[[package]]
@ -1887,19 +1536,6 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
[[package]]
name = "sha2"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12"
dependencies = [
"block-buffer",
"cfg-if",
"cpufeatures",
"digest",
"opaque-debug",
]
[[package]]
name = "shelve"
version = "0.1.0"
@ -1907,12 +1543,12 @@ dependencies = [
"async-trait",
"dotenv",
"err-derive",
"futures-util",
"hyper 0.14.11",
"multipart 0.18.0",
"multipart",
"priority-queue",
"rand 0.8.4",
"rocket 0.5.0-rc.1",
"rocket_upload",
"rocket",
"rust-embed",
"serde",
"serde_json",
@ -1980,12 +1616,6 @@ dependencies = [
"version_check 0.9.3",
]
[[package]]
name = "state"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3015a7d0a5fd5105c91c3710d42f9ccf0abfb287d62206484dcc67f9569a6483"
[[package]]
name = "state"
version = "0.5.2"
@ -2015,11 +1645,11 @@ version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
dependencies = [
"proc-macro2 1.0.28",
"quote 1.0.9",
"proc-macro2",
"quote",
"serde",
"serde_derive",
"syn 1.0.74",
"syn",
]
[[package]]
@ -2029,13 +1659,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11"
dependencies = [
"base-x",
"proc-macro2 1.0.28",
"quote 1.0.9",
"proc-macro2",
"quote",
"serde",
"serde_derive",
"serde_json",
"sha1",
"syn 1.0.74",
"syn",
]
[[package]]
@ -2044,32 +1674,15 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
[[package]]
name = "subtle"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "syn"
version = "0.15.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"unicode-xid 0.1.0",
]
[[package]]
name = "syn"
version = "1.0.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c"
dependencies = [
"proc-macro2 1.0.28",
"quote 1.0.9",
"unicode-xid 0.2.2",
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
@ -2078,10 +1691,10 @@ version = "0.12.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "474aaa926faa1603c40b7885a9eaea29b444d1cb2850cb7c0e37bb1a4182f4fa"
dependencies = [
"proc-macro2 1.0.28",
"quote 1.0.9",
"syn 1.0.74",
"unicode-xid 0.2.2",
"proc-macro2",
"quote",
"syn",
"unicode-xid",
]
[[package]]
@ -2140,10 +1753,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f"
dependencies = [
"proc-macro-hack",
"proc-macro2 1.0.28",
"quote 1.0.9",
"proc-macro2",
"quote",
"standback",
"syn 1.0.74",
"syn",
]
[[package]]
@ -2199,9 +1812,9 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54473be61f4ebe4efd09cec9bd5d16fa51d70ea0192213d754d2d500457db110"
dependencies = [
"proc-macro2 1.0.28",
"quote 1.0.9",
"syn 1.0.74",
"proc-macro2",
"quote",
"syn",
]
[[package]]
@ -2229,15 +1842,6 @@ dependencies = [
"tokio",
]
[[package]]
name = "toml"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f"
dependencies = [
"serde",
]
[[package]]
name = "toml"
version = "0.5.8"
@ -2319,12 +1923,6 @@ dependencies = [
"unsafe-any",
]
[[package]]
name = "typenum"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06"
[[package]]
name = "ubyte"
version = "0.10.1"
@ -2392,28 +1990,12 @@ dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "universal-hash"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05"
dependencies = [
"generic-array",
"subtle",
]
[[package]]
name = "unsafe-any"
version = "0.4.2"
@ -2502,9 +2084,9 @@ dependencies = [
"bumpalo",
"lazy_static",
"log 0.4.14",
"proc-macro2 1.0.28",
"quote 1.0.9",
"syn 1.0.74",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
@ -2514,7 +2096,7 @@ version = "0.2.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4"
dependencies = [
"quote 1.0.9",
"quote",
"wasm-bindgen-macro-support",
]
@ -2524,9 +2106,9 @@ version = "0.2.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97"
dependencies = [
"proc-macro2 1.0.28",
"quote 1.0.9",
"syn 1.0.74",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]

View file

@ -14,8 +14,8 @@ err-derive = "0.3"
rand = "0.8"
uuid = { version = "0.8", features = ["serde", "v4"] }
rust-embed = "5"
rocket_upload = "0.1"
serde = "1"
serde_json = "1"
multipart = "0.18"
async-trait = "0.1"
futures-util = { version = "0.3" }

View file

@ -129,10 +129,6 @@ impl ExpireQueue {
expired
}
pub fn len(&self) -> usize {
self.queue.lock().unwrap().len()
}
}
#[test]

View file

@ -1,27 +1,26 @@
use crate::expire_queue::{ExpireQueue, InvalidUploadIdError, UploadId};
use crate::token::{UploadToken, ValidTokens};
use dotenv::dotenv;
use rocket::data::ToByteUnit;
use rocket::fs::NamedFile;
use futures_util::future::try_join_all;
use rocket::data::{Limits, ToByteUnit};
use rocket::form::Form;
use rocket::fs::{FileName, NamedFile, TempFile};
use rocket::request::FromParam;
use rocket::response::Redirect;
use rocket::{get, launch, post, put, routes, Data, Responder, State};
use rocket::{get, launch, post, put, routes, Config, Data, FromForm, Responder, State};
use rust_embed::RustEmbed;
use serde::Serialize;
use std::borrow::Cow;
use std::collections::HashMap;
use std::env::{self, current_dir};
use std::fs::{create_dir, read_dir, remove_dir_all, File};
use std::fs::{create_dir, create_dir_all, read_dir, remove_dir_all};
use std::io;
use std::path::PathBuf;
use std::str::FromStr;
use std::thread::{sleep, spawn, JoinHandle};
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use upload::MultipartDatas;
mod expire_queue;
mod token;
mod upload;
impl<'r> FromParam<'r> for UploadId {
type Error = InvalidUploadIdError;
@ -81,36 +80,38 @@ enum UploadResponse {
}
#[derive(Debug, Serialize)]
struct UploadData {
struct UploadResponseData {
success: bool,
error: Option<&'static str>,
error: Option<Cow<'static, str>>,
urls: Option<Vec<String>>,
}
#[derive(FromForm, Debug)]
struct UploadData<'r> {
expire: Option<u64>,
ajax: bool,
token: &'r str,
files: Vec<TempFile<'r>>,
}
#[post("/upload", data = "<data>")]
fn post_upload(
data: MultipartDatas,
async fn post_upload(
data: Form<UploadData<'_>>,
accepted_tokens: &State<ValidTokens>,
basedir: &State<PathBuf>,
expire_queue: &State<ExpireQueue>,
) -> UploadResponse {
let mut fields: HashMap<String, String> = data
.texts
.into_iter()
.map(|text| (text.key, text.value))
.collect();
let expire = fields
.get("expire")
.and_then(|expire| u64::from_str(expire).ok());
let ajax = fields.get("ajax").is_some();
let token = fields.remove("token").unwrap_or_default();
let data = data.into_inner();
let expire = data.expire;
let ajax = data.ajax;
let token = data.token;
if !accepted_tokens.contains(&token) {
if !accepted_tokens.contains(token) {
if ajax {
UploadResponse::Data(
serde_json::to_string(&UploadData {
serde_json::to_string(&UploadResponseData {
success: false,
error: Some("invalid token"),
error: Some("invalid token".into()),
urls: None,
})
.unwrap_or_default(),
@ -119,28 +120,28 @@ fn post_upload(
UploadResponse::Redirect(Redirect::to("/?error=invalid%20token"))
}
} else {
match data
.files
.into_iter()
.map(|file| {
match try_join_all(data.files.into_iter().filter(|file| file.len() > 0).map(
|mut file| async move {
let id = UploadId::generate(now() + expire.unwrap_or(THOUSAND_YEARS));
expire_queue.push(id);
let name = &file.filename;
let name = file.name().unwrap_or("upload");
let ext = file.raw_name().and_then(filename_ext).unwrap_or_default();
let name = format!("{}.{}", name, ext);
let url = format!("{}/{}", id.as_string(), &name);
let mut path: PathBuf = basedir.join(id.as_string());
create_dir(&path)?;
path.push(name);
let mut file = File::open(&file.path)?;
io::copy(&mut file, &mut File::create(&path)?)?;
Ok(format!("{}/{}", id.as_string(), &name))
})
.collect::<io::Result<Vec<String>>>()
file.persist_to(path).await.map(|_| url)
},
))
.await
{
Ok(urls) => {
if ajax {
UploadResponse::Data(
serde_json::to_string(&UploadData {
serde_json::to_string(&UploadResponseData {
success: true,
error: None,
urls: Some(urls),
@ -151,10 +152,10 @@ fn post_upload(
UploadResponse::Redirect(Redirect::to(""))
}
}
Err(_) => UploadResponse::Data(
serde_json::to_string(&UploadData {
Err(e) => UploadResponse::Data(
serde_json::to_string(&UploadResponseData {
success: false,
error: Some("error while moving file"),
error: Some(format!("error while moving file: {}", e).into()),
urls: None,
})
.unwrap_or_default(),
@ -174,7 +175,7 @@ async fn download(id: UploadId, name: PathBuf, basedir: &State<PathBuf>) -> Opti
}
#[launch]
fn rockert() -> _ {
fn rocket() -> _ {
dotenv().ok();
let mut env: HashMap<_, _> = env::vars().collect();
@ -191,9 +192,19 @@ fn rockert() -> _ {
.map(PathBuf::from)
.unwrap_or_else(|| current_dir().unwrap_or_default().join("data"));
let tmpdir = basedir.join("tmp");
create_dir_all(&tmpdir).expect("failed to create tmp directory");
expire_job(basedir.clone(), expire_queue.clone());
rocket::build()
let figment = Config::figment().merge(("temp_dir", tmpdir)).merge((
"limits",
Limits::new()
.limit("file", 2.gibibytes())
.limit("data-form", 2.gibibytes()),
));
rocket::custom(figment)
.manage(tokens)
.manage(basedir.clone())
.manage(expire_queue)
@ -223,3 +234,23 @@ fn expire_job(expire_basedir: PathBuf, expire_queue: ExpireQueue) -> JoinHandle<
}
})
}
fn filename_ext(name: &FileName) -> Option<&str> {
let raw = name.dangerous_unsafe_unsanitized_raw().as_str();
let (name, ext) = raw.split_once('.')?;
if name.len() > 0 && ext.len() < 8 && ext.chars().all(|c| c.is_ascii_alphanumeric() || c == '.')
{
Some(ext)
} else {
None
}
}
#[test]
fn test_ext() {
assert_eq!(Some("jpg"), filename_ext("foo.jpg".into()));
assert_eq!(Some("tar.gz"), filename_ext("foo.tar.gz".into()));
assert_eq!(None, filename_ext(".png".into()));
assert_eq!(None, filename_ext("../foo.png".into()));
assert_eq!(None, filename_ext("tmp/../foo.png".into()));
}

View file

@ -1,158 +0,0 @@
use std::fs::{self, File};
use std::io::{Cursor, Read, Write};
use std::path::Path;
use rocket::data::{self, FromData, Outcome, ToByteUnit};
use rocket::{Data, Request};
use multipart::server::Multipart;
#[derive(Debug)]
pub struct TextPart {
pub key: String,
pub value: String,
}
#[derive(Debug)]
pub struct FilePart {
pub name: String,
pub path: String,
pub filename: String,
}
#[derive(Debug)]
pub struct MultipartDatas {
pub texts: Vec<TextPart>,
pub files: Vec<FilePart>,
}
impl FilePart {
pub fn persist(&self, p: &Path) {
let s = Path::join(p, &self.filename);
fs::copy(Path::new(&self.path), &s).unwrap();
}
}
impl Drop for FilePart {
fn drop(&mut self) {
fs::remove_file(Path::new(&self.path)).unwrap();
}
}
const TMP_PATH: &str = "/tmp/rust_upload/";
#[async_trait::async_trait]
impl<'r> FromData<'r> for MultipartDatas {
type Error = String;
async fn from_data(
request: &'r Request<'_>,
data: Data<'r>,
) -> data::Outcome<'r, Self, String> {
let ct = request
.headers()
.get_one("Content-Type")
.expect("no content-type");
let idx = ct.find("boundary=").expect("no boundary");
let boundary = &ct[(idx + "boundary=".len())..];
let mut d = Vec::new();
data.open(2.gibibytes())
.stream_to(&mut d)
.await
.expect("Unable to read");
let mut mp = Multipart::with_body(Cursor::new(d), boundary);
let mut texts = Vec::new();
let mut files = Vec::new();
let mut buffer = [0u8; 4096];
mp.foreach_entry(|entry| {
let mut data = entry.data;
if entry.headers.filename == None {
let mut text_buffer = Vec::new();
loop {
let c = match data.read(&mut buffer) {
Ok(c) => c,
Err(_err) => {
return;
}
};
if c == 0 {
break;
}
text_buffer.extend_from_slice(&buffer[..c]);
}
let text = match String::from_utf8(text_buffer) {
Ok(s) => s,
Err(_err) => {
return;
}
};
texts.push(TextPart {
key: entry.headers.name.to_string(),
value: text,
});
} else {
let filename = entry.headers.filename.clone().unwrap();
if !Path::new(TMP_PATH).exists() {
fs::create_dir_all(TMP_PATH).unwrap();
}
let target_path = Path::join(Path::new(TMP_PATH), &filename);
let mut file = match File::create(&target_path) {
Ok(f) => f,
Err(_err) => {
return;
}
};
let mut sum_c = 0u64;
loop {
let c = match data.read(&mut buffer) {
Ok(c) => c,
Err(_err) => {
try_delete(&target_path);
return;
}
};
if c == 0 {
break;
}
sum_c = sum_c + c as u64;
match file.write(&buffer[..c]) {
Ok(_) => (),
Err(_err) => {
try_delete(&target_path);
return;
}
}
}
files.push(FilePart {
name: entry.headers.name.to_string(),
path: String::from(TMP_PATH) + &filename,
filename: entry.headers.filename.clone().unwrap(),
})
}
})
.unwrap();
Outcome::Success(MultipartDatas { texts, files })
}
}
#[inline]
fn try_delete<P: AsRef<Path>>(path: P) {
if fs::remove_file(path.as_ref()).is_err() {}
}

View file

@ -285,7 +285,7 @@
var ajaxFlag = document.createElement('input');
ajaxFlag.setAttribute('type', 'hidden');
ajaxFlag.setAttribute('name', 'ajax');
ajaxFlag.setAttribute('value', 1);
ajaxFlag.setAttribute('value', 'true');
form.appendChild(ajaxFlag);
box.addEventListener('click', function () {