This commit is contained in:
mingyang 2021-01-27 12:02:11 +08:00
parent a609d3a55e
commit 8456b1869a
3 changed files with 200 additions and 153 deletions

263
.gitignore vendored
View File

@ -1,131 +1,132 @@
# ---> Python # ---> Python
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
*.py[cod] *.py[cod]
*$py.class *$py.class
.vscode/
# C extensions
*.so # C extensions
*.so
# Distribution / packaging
.Python # Distribution / packaging
build/ .Python
develop-eggs/ build/
dist/ develop-eggs/
downloads/ dist/
eggs/ downloads/
.eggs/ eggs/
lib/ .eggs/
lib64/ lib/
parts/ lib64/
sdist/ parts/
var/ sdist/
wheels/ var/
pip-wheel-metadata/ wheels/
share/python-wheels/ pip-wheel-metadata/
*.egg-info/ share/python-wheels/
.installed.cfg *.egg-info/
*.egg .installed.cfg
MANIFEST *.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template # PyInstaller
# before PyInstaller builds the exe, so as to inject date/other infos into it. # Usually these files are written by a python script from a template
*.manifest # before PyInstaller builds the exe, so as to inject date/other infos into it.
*.spec *.manifest
*.spec
# Installer logs
pip-log.txt # Installer logs
pip-delete-this-directory.txt pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/ # Unit test / coverage reports
.tox/ htmlcov/
.nox/ .tox/
.coverage .nox/
.coverage.* .coverage
.cache .coverage.*
nosetests.xml .cache
coverage.xml nosetests.xml
*.cover coverage.xml
*.py,cover *.cover
.hypothesis/ *.py,cover
.pytest_cache/ .hypothesis/
.pytest_cache/
# Translations
*.mo # Translations
*.pot *.mo
*.pot
# Django stuff:
*.log # Django stuff:
local_settings.py *.log
db.sqlite3 local_settings.py
db.sqlite3-journal db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/ # Flask stuff:
.webassets-cache instance/
.webassets-cache
# Scrapy stuff:
.scrapy # Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/ # Sphinx documentation
docs/_build/
# PyBuilder
target/ # PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints # Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/ # IPython
ipython_config.py profile_default/
ipython_config.py
# pyenv
.python-version # pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. # pipenv
# However, in case of collaboration, if having platform-specific dependencies or dependencies # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# having no cross-platform support, pipenv may install dependencies that don't work, or not # However, in case of collaboration, if having platform-specific dependencies or dependencies
# install all needed dependencies. # having no cross-platform support, pipenv may install dependencies that don't work, or not
#Pipfile.lock # install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule # Celery stuff
celerybeat.pid celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py # SageMath parsed files
*.sage.py
# Environments
.env # Environments
.venv .env
env/ .venv
venv/ env/
ENV/ venv/
env.bak/ ENV/
venv.bak/ env.bak/
venv.bak/
# Spyder project settings
.spyderproject # Spyder project settings
.spyproject .spyderproject
.spyproject
# Rope project settings
.ropeproject # Rope project settings
.ropeproject
# mkdocs documentation
/site # mkdocs documentation
/site
# mypy
.mypy_cache/ # mypy
.dmypy.json .mypy_cache/
dmypy.json .dmypy.json
dmypy.json
# Pyre type checker
.pyre/ # Pyre type checker
.pyre/

38
LICENSE
View File

@ -1,19 +1,19 @@
MIT License Copyright (c) <year> <copyright holders> MIT License Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions: to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the paragraph) shall be included in all copies or substantial portions of the
Software. Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,3 +1,49 @@
# HTTPImageServer # HTTPImageServer
A naive http-based tool to show the image in a given directory.
A Naive HTTP based image server, aims to show the image in a given folder.
## 1. Dependency
- python3
- Pillow
> Install pillow via ```pip install pillow```
## 2. How to use
A simple command would do the job:
```shell
python server.py <port> <webroot>
```
where ```port``` is a int number of which port to use (default: 80), and ```webroot``` is the directory that containing the images(default: current directory).
## 3. Structure.
The server.py mainly provides two api.
1. To access filelist under the given directory, please access:
```
/directory?path=relative/path/to/file
```
params:
path: the directory that you want to list.
return:
```json
{
"dirs": [list, of, subdirs],
"imgs": [image, file, under, the, directory],
}
```
2. to access the image:
```
/img?path=relative/path/to/file&height=100&width=200
```
params:
path: the image that you want to access.
height: image max height.
width: image max width.
> Note: if no height and width are provided, the original image will be returned.
return:
the image stream.
For more details about the structure, please see the network.py.
## 4. Ps
1. The http server are written starting from socket, i do not use the http.server module in python. Therefore, there might be some bugs and may cause some problems, be sure not to use in production enviroment.
2. The index.html is gabbage, i have never write javascript before. You can try to re-write it if you are disgusting with that.