Compare commits
No commits in common. "721fda8b220044e84e92d6b58dd4a4dd282fbf48" and "8800b519c01c6b392d20b8cc2477d28d1950ec90" have entirely different histories.
721fda8b22
...
8800b519c0
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2022 ge <gechandev@gmail.com>
|
Copyright (c) 2021 gd <gechandev@gmail.com>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
16
README.md
16
README.md
@ -10,19 +10,3 @@ Features:
|
|||||||
* MIME type detecting
|
* MIME type detecting
|
||||||
|
|
||||||
See deployment options in Bottle documentation: https://bottlepy.org/docs/dev/deployment.html
|
See deployment options in Bottle documentation: https://bottlepy.org/docs/dev/deployment.html
|
||||||
|
|
||||||
# Additional
|
|
||||||
|
|
||||||
## imgs client with CLI
|
|
||||||
|
|
||||||
imgs has a simple CLI tool based on curl. Copy **imgs** script to your PATH.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo cp imgs /usr/bin/imgs
|
|
||||||
```
|
|
||||||
|
|
||||||
## Nautilus integration
|
|
||||||
|
|
||||||
Push files to your imgs instance via GNOME Files (former name: Nautilus). Depends packages: curl, notyfy-send.
|
|
||||||
|
|
||||||
Just place **Upload to imgs** script into **~/.local/share/nautilus/scripts**.
|
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# This is an imgs <https://gitea.gch.icu/ge/imgs> "integration" for Nautilus.
|
|
||||||
# Place this script into path: $HOME/.local/share/nautilus/scripts
|
|
||||||
# See more info at: <https://help.ubuntu.com/community/NautilusScriptsHowto>
|
|
||||||
|
|
||||||
imgs_check_vars() {
|
|
||||||
[ "$IMGSLOG" ] || IMGSLOG=$HOME/imgs_debug.log
|
|
||||||
[ "$IMGSREMOTE" ] && return 0 # exit from func if variable is set
|
|
||||||
|
|
||||||
if [ -f "$HOME/.imgsremote" ]; then
|
|
||||||
. $HOME/.imgsremote
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$IMGSREMOTE" ]; then
|
|
||||||
:
|
|
||||||
else
|
|
||||||
echo "$0: Error: IMGSREMOTE variable is not set." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
[ "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Started" >> "$IMGSLOG"
|
|
||||||
|
|
||||||
while read -r file; do
|
|
||||||
[ "$file" ] || break
|
|
||||||
if [ "$IMGSDEBUG" ]; then
|
|
||||||
image="$(curl -v -L -F "image=@$file" "$IMGSREMOTE" 2>&1 | tee -a "$IMGSLOG")"
|
|
||||||
image="$(tail -n 1 <<< "$image")"
|
|
||||||
else
|
|
||||||
image="$(curl -L -F "image=@$file" "$IMGSREMOTE")"
|
|
||||||
fi
|
|
||||||
[ "$IMGSDEBUG" ] && echo "$(date +"[%d %b %Y %H:%M:%S]") $file --> $image" >> "$IMGSLOG"
|
|
||||||
notify-send "File uploaded to imgs!" "$image"
|
|
||||||
done <<< "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"
|
|
||||||
|
|
||||||
[ "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Finished" >> "$IMGSLOG"
|
|
BIN
favicon.ico
BIN
favicon.ico
Binary file not shown.
Before Width: | Height: | Size: 15 KiB |
74
imgs
74
imgs
@ -1,74 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# imgs CLI client.
|
|
||||||
# Home page: <https://gitea.gch.icu/ge/imgs>
|
|
||||||
|
|
||||||
imgs_usage() {
|
|
||||||
cat <<- EOF
|
|
||||||
Upload images to remote imgs server.
|
|
||||||
|
|
||||||
Usage: imgs [--version] [--help] [-r | --remote <URL>] <file>...
|
|
||||||
|
|
||||||
Options:
|
|
||||||
-r, --remote remote imgs instance URI. Example:
|
|
||||||
'https://user:password@example.org'
|
|
||||||
--version print version and exit.
|
|
||||||
--help print this help message and exit.
|
|
||||||
|
|
||||||
Environment variables:
|
|
||||||
IMGSREMOTE remote imgs instance URI.
|
|
||||||
IMGSDEBUG enables verbose mode and logging.
|
|
||||||
IMGSLOG path to logfile. Default: ~/imgs_debug.log
|
|
||||||
|
|
||||||
You can set variables in ~/.imgsremote file instead of ~/.bashrc
|
|
||||||
See <https://gitea.gch.icu/ge/imgs> for more info.
|
|
||||||
EOF
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
imgs_check_vars() {
|
|
||||||
[ "$IMGSLOG" ] || IMGSLOG=$HOME/imgs_debug.log
|
|
||||||
[ "$IMGSREMOTE" ] && return 0 # exit from func if variable is set
|
|
||||||
|
|
||||||
if [ -f "$HOME/.imgsremote" ]; then
|
|
||||||
. $HOME/.imgsremote
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$IMGSREMOTE" ]; then
|
|
||||||
:
|
|
||||||
else
|
|
||||||
echo "$0: Error: IMGSREMOTE variable is not set." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
[[ "$@" ]] || imgs_usage
|
|
||||||
while (( "$#" )); do
|
|
||||||
case "$1" in
|
|
||||||
-r|--remote) if [ "$2" ] && [ "${2:0:1}" != '-' ]; then
|
|
||||||
IMGSREMOTE="$2"; shift
|
|
||||||
else
|
|
||||||
echo "$0: missing argument for $1" >&2; exit 1
|
|
||||||
fi; shift;;
|
|
||||||
--version) echo 'imgs CLI 1.0'; exit 0;;
|
|
||||||
--help) imgs_usage;;
|
|
||||||
-*) echo "$0: $1: bad option" >&2; exit 1;;
|
|
||||||
*) [ -f "$1" ] || { echo "$0: $1: no such file" >&2; exit 1; }
|
|
||||||
_files+=("$1"); shift;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
imgs_check_vars
|
|
||||||
|
|
||||||
[ "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Started" | tee -a "$IMGSLOG"
|
|
||||||
|
|
||||||
for file in "${_files[@]}"; do
|
|
||||||
filepath="$(realpath "$file")"
|
|
||||||
if [ "$IMGSDEBUG" ]; then
|
|
||||||
echo "Uploading $filepath" | tee -a "$IMGSLOG"
|
|
||||||
curl -v -L -F "image=@/$filepath" "$IMGSREMOTE" 2>&1 | tee -a "$IMGSLOG"
|
|
||||||
else
|
|
||||||
curl -L -F "image=@/$filepath" "$IMGSREMOTE"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
[ "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Finished" | tee -a "$IMGSLOG"
|
|
2
imgs.ini
2
imgs.ini
@ -1,6 +1,6 @@
|
|||||||
[imgs]
|
[imgs]
|
||||||
|
debug = False
|
||||||
base_url = http://localhost:5000/
|
base_url = http://localhost:5000/
|
||||||
image_name_lenght = 3
|
image_name_lenght = 3
|
||||||
uploads_dir = uploads
|
uploads_dir = uploads
|
||||||
#allowed_mime_types = * # allow any MIME type
|
|
||||||
allowed_mime_types = ['image/bmp', 'image/gif', 'image/jpeg', 'image/png', 'image/svg+xml', 'image/tiff', 'image/webp']
|
allowed_mime_types = ['image/bmp', 'image/gif', 'image/jpeg', 'image/png', 'image/svg+xml', 'image/tiff', 'image/webp']
|
||||||
|
36
imgs.py
36
imgs.py
@ -1,5 +1,3 @@
|
|||||||
__version__ = '1.1'
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
@ -50,38 +48,30 @@ def upload_image():
|
|||||||
# Handle request from CLI
|
# Handle request from CLI
|
||||||
if request.files.get('image'):
|
if request.files.get('image'):
|
||||||
file = request.files.get('image')
|
file = request.files.get('image')
|
||||||
rq = 'cli'
|
|
||||||
# Handle request from web-browser
|
|
||||||
elif request.files.get('image_web'):
|
|
||||||
file = request.files.get('image_web')
|
|
||||||
rq = 'web'
|
|
||||||
|
|
||||||
if config['imgs.allowed_mime_types'] == '*':
|
|
||||||
# Skip MIME checking.
|
|
||||||
image_name = upload_file(file)
|
|
||||||
else:
|
|
||||||
if file.content_type in config['imgs.allowed_mime_types']:
|
if file.content_type in config['imgs.allowed_mime_types']:
|
||||||
# Upload file!
|
|
||||||
image_name = upload_file(file)
|
image_name = upload_file(file)
|
||||||
|
return get_image_url(image_name) + '\n'
|
||||||
else:
|
else:
|
||||||
# Show MIME type error!
|
|
||||||
# Prevent recource leek. Force close buffered file
|
# Prevent recource leek. Force close buffered file
|
||||||
request.body.close()
|
request.body.close()
|
||||||
response.status = 415
|
response.status = 415
|
||||||
if rq == 'cli':
|
|
||||||
return 'Error: bad file MIME type\n'
|
return 'Error: bad file MIME type\n'
|
||||||
|
# Handle request from web-browser
|
||||||
|
elif request.files.get('image_web'):
|
||||||
|
file = request.files.get('image_web')
|
||||||
|
if file.content_type in config['imgs.allowed_mime_types']:
|
||||||
|
image_name = upload_file(file)
|
||||||
|
return template('index.tpl',
|
||||||
|
uploaded = True, not_found = False, bad_mime_type = False,
|
||||||
|
base_url = get_base_url(), image_url = get_image_url(image_name))
|
||||||
else:
|
else:
|
||||||
|
# Prevent recource leek. Force close buffered file
|
||||||
|
request.body.close()
|
||||||
|
response.status = 415
|
||||||
return template('index.tpl',
|
return template('index.tpl',
|
||||||
uploaded = False, not_found = False, bad_mime_type = True,
|
uploaded = False, not_found = False, bad_mime_type = True,
|
||||||
allowed_mime_types = config['imgs.allowed_mime_types'],
|
allowed_mime_types = config['imgs.allowed_mime_types'],
|
||||||
base_url = get_base_url(), image_url = 'None')
|
base_url = get_base_url(), image_url = 'None')
|
||||||
# Return 200 OK
|
|
||||||
if rq == 'cli':
|
|
||||||
return get_image_url(image_name) + '\n'
|
|
||||||
else:
|
|
||||||
return template('index.tpl',
|
|
||||||
uploaded = True, not_found = False, bad_mime_type = False,
|
|
||||||
base_url = get_base_url(), image_url = get_image_url(image_name))
|
|
||||||
|
|
||||||
@get('/<image_name>')
|
@get('/<image_name>')
|
||||||
def send_image(image_name):
|
def send_image(image_name):
|
||||||
@ -92,4 +82,4 @@ def send_style():
|
|||||||
return static_file('style.css', root = './')
|
return static_file('style.css', root = './')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
run()
|
run(debug = config['imgs.debug'])
|
||||||
|
@ -77,7 +77,7 @@
|
|||||||
<div class="logo">
|
<div class="logo">
|
||||||
<pre> __<br>|__| _____ ____ ______<br>| |/ \ / ___\/ ___/<br>| | Y Y / /_/ \___ \<br>|__|__|_| \___ /____ ><br> \/_____/ \/</pre>
|
<pre> __<br>|__| _____ ____ ______<br>| |/ \ / ___\/ ___/<br>| | Y Y / /_/ \___ \<br>|__|__|_| \___ /____ ><br> \/_____/ \/</pre>
|
||||||
</div>
|
</div>
|
||||||
<p><a href="https://gitea.gch.icu/ge/imgs" target="_blank">v1.1</a></p>
|
<p><a href="https://gitea.gch.icu/gd/imgs" target="_blank">v1.0</a></p>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user