Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
GNU Generation
GnuPaste
Commits
325d7dca
Commit
325d7dca
authored
Dec 22, 2020
by
Antoine Fontaine
🎱
Browse files
Add (hardcoded) maximum uploaded file size
parent
c3bb34d7
Pipeline
#1881
canceled with stages
in 2 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
TODO.mkd
View file @
325d7dca
# TODO:
*
Send mimetype on access.
*
Autodetct mimetype if field is empty.
*
Autodet
e
ct mimetype if field is empty.
*
Good practices testing.
*
Check error handling (should be good).
*
Continuous-integration.
*
Package this for Debian.
*
Fast continuous-integration.
*
Import script for previous pastes.
*
Add ETags for caching.
debian/changelog
View file @
325d7dca
gnupaste (2.0.0-rc1) unstable; urgency=medium
gnupaste (2.0.0+rc2) unstable; urgency=medium
* Add (hardcoded) maximum uploaded file size
-- Antoine Fontaine <antoine.fontaine@epfl.ch> Sun, 20 Dec 2020 15:49:01 +0100
gnupaste (2.0.0+rc1) unstable; urgency=medium
* Initial release
...
...
debian/control
View file @
325d7dca
...
...
@@ -2,6 +2,8 @@ Source: gnupaste
Maintainer: Antoine Fontaine <antoine.fontaine@epfl.ch>
Section: haskell
Build-Depends:
Vcs-Browser: https://gitlab.gnugen.ch/gnugen/gnupaste
Vcs-Git: https://gitlab.gnugen.ch/gnugen/gnupaste.git
Standards-Version: 4.5.0
Description: GNU Generation's new pastebin software
...
...
src/Paste/Handlers.hs
View file @
325d7dca
...
...
@@ -55,7 +55,13 @@ processUpload pool pasteDir reqAddr mXForward multipData =
case
head
$
files
multipData
of
Nothing
->
throwError
err400
{
errBody
=
"You must include a file in the multipart/formdata you upload!"
}
Just
upload
->
do
-- Get information to store.
size
<-
liftIO
$
getFileSize
(
fdPayload
upload
)
-- Ensure file isn't too big
when
(
size
>
1
*
1024
*
1024
)
$
throwError
err413
{
errBody
=
"Request size exceeded 1MiB."
}
-- Get information to store.
now
<-
liftIO
getCurrentTime
-- Generate a hash for the file, unique wrt the DB.
...
...
@@ -68,17 +74,17 @@ processUpload pool pasteDir reqAddr mXForward multipData =
-- Address from X-Forwarded-For header if it exists, otherwise from the requester.
let
address
=
fromMaybe
(
textifyAddress
reqAddr
)
(
mXForward
)
-- copy file to "uploads" dir.
-- copy file to "uploads" dir.
liftIO
$
copyFile
(
fdPayload
upload
)
(
pasteDir
++
(
T
.
unpack
hash
))
-- Store info in DB.
-- Store info in DB.
liftIO
$
insertPaste
Paste
{
pasteHash
=
hash
,
pasteMime
=
mime
,
pasteDate
=
now
,
pasteDueAt
=
expire
,
pasteIpAdd
=
address
}
pool
-- Send back 201 with the URL to the paste.
-- Send back 201 with the URL to the paste.
return
$
"https://paste.gnugen.ch/"
<>
hash
-- | Transform a 'SockAddr' datastructure to human-readable text to store in
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment