guits / pastefile Goto Github PK
View Code? Open in Web Editor NEWa little daemon to share any file via http
a little daemon to share any file via http
Hi,
When I tried to open a DMG file sent by Pastefile, it's opened a text editor with binary code inside instead of the DiskImageMounter app.
Simply add a readonly
arg to jsonDB to not try to lock.
For example the ls
url just need to read. No need to lock the db for that. https://github.com/guits/pastefile/blob/master/pastefile/app.py#L207
We also don't want to return a return "Lock timed out"
in that case. Only read only database is enough.
https://github.com/guits/pastefile/blob/master/pastefile/app.py#L213
ls
return 500 if one of all file have no infos.
Just skip it and display others. Could replace abort(500)
by a simple continue
Idea is to provide a "admin_token" in the config file.
Request with the admin_token in the header could have more option than an other user.
For example, we could add in the config file, list of method only for admin :
admin_only_urls : ls,delete, ...
jsondb doesn't load any data
The pip install
should rather use the requierements.txt file provided here https://github.com/guits/pastefile/blob/master/requirements.txt
In particular for the burn_after_read feature
the filename is not the good one when retrieving a file.
this is because files are stored with md5 as filename
line 108: os.rename(tmp_full_filename, storage_full_filename)
need to find a way to send file with original filename
Should add : install and usage part with a small example.
Don't forget the test with it
For security reason or custom usage, it could be cool to provide a way to disable /ls option.
For a usage like a pastebin where only user with the link can access to the file.
Provide the possibility to upload a burn after read file.
To allow only one user to download the file. After the download the file will be removed.
We have
curl localhost:5000/dfgdfg
<h1>File not found</h1>
<p>Usage:<br><br>
GET /ls<br>
GET /id_file/infos<br>
POST /<br>
GET /<id_file><br>
<br><br>
TO improve
We should fix to display help like the /
url
Use argparse :
ex: -c /path/to/config/file.cfg
(at the moment it is hardcoded)
If a variable isn't present on config file, application crash.
Typical case :
Upgrade, doesn't compare your config file to template.
If a new config variable has been added, server will crash.
Should be really good to add the same log formatter https://github.com/guits/pastefile/blob/master/pastefile/app.py#L45
on stream handler https://github.com/guits/pastefile/blob/master/pastefile/app.py#L16
Change the display regarding the user agent.
Example : http://stackoverflow.com/questions/9878020/how-do-i-get-the-user-agent-with-flask
The idea is to have nice output for page like /help
with curl
and also with a web browser.
Just add a check if directory in pastefile.conf exist; If not try to create them (not recursively)
When we try a random url we have an error :
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1478, in full_dispatch_request
response = self.make_response(rv)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1566, in make_response
raise ValueError('View function did not return a response')
ValueError: View function did not return a response
Try to add a custom 404
page that print of a help page.
It could be great to add a button 'upload and send by email'
Thus we could directly upload the file and the mail client would open automatically to send the link.
As discuss, change the db lock behavior https://github.com/guits/pastefile/blob/master/jsondb.py#L45
To remove the signal.signal and simply use a non blocant lock
Example : http://tilde.town/~cristo/file-locking-in-python.html (simply add timeout on that)
Your md5 function : https://github.com/guits/pastefile/blob/master/pastefile/app.py#L66
Should be replaced by thing like this : https://github.com/shaftmx/myvideostore/blob/master/myvideostore/tools.py#L74,L79
add log in file to know who and when a file is uploaded.
I proposed :
app.py
for api https://github.com/guits/pastefile/blob/master/pastefile/app.py#L209-L265controller.py
for methode that do actions https://github.com/guits/pastefile/blob/master/pastefile/app.py#L70-L206utils.py
for all generic tools https://github.com/guits/pastefile/blob/master/pastefile/app.py#L43-L67Also rename some method to a more explicite name : https://github.com/guits/pastefile/blob/master/pastefile/app.py#L224-L229
For exemple :
get_or_delete_file_view
delete_file()
get_file()
If you are ok with that, I propose to implement that, just give me a GO when it should not impact code that you havn't merged yet
these 2 button are not used, juste remove them
refact this part of code https://github.com/guits/pastefile/blob/master/pastefile/app.py#L121,L148
To avoid double call of remove and return for file already existing
Actually :
~$ curl -F "file=@foo" pastefile.learnit.fr
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>403 Forbidden</title>
<h1>Forbidden</h1>
<p>You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.</p>
Should be better to only return the url of the existing file.
It could be good to have a cli tool to check that all file in the DB are existing on disk.
And if not, clean them from the DB.
Could be a script that we can call manually or in cron to clean entries in the DB.
this is related to the issue #38
add parameter port, construct variable "base_url" etc ...
The save
write the file. If we kill the process during the write, we will have a corrupted db.
It should be better to write a tmp file. And then rename it.
In example to retrieve file info, there is no file given.
Allow users to delete files with a
curl -X DELETE
When you are using explorer like chrome, chrome automatically try to get favicon.ico.
127.0.0.1 - - [02/Nov/2015 22:43:28] "GET /favicon.ico HTTP/1.1" 500 -
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1478, in full_dispatch_request
response = self.make_response(rv)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1566, in make_response
raise ValueError('View function did not return a response')
ValueError: View function did not return a response
Check and create if possible directory in config file.
Example if the upload_folder
not exist, you have a python error
If possible add unit test or at least a simple functional test.
For functional tests it could be in python or not.
The idea is to test the app with a customer point of view :
Currently each url result in a file downloaded by you browser.
We should give a try to use mime type to fill the content type header.
The goal is to display text or image in your browser natively.
Add a Dockerfile to build a docker image
Add a field that display the size of file in '/ls' or '/infos' query
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.