Compare commits

..

No commits in common. "721fda8b220044e84e92d6b58dd4a4dd282fbf48" and "8800b519c01c6b392d20b8cc2477d28d1950ec90" have entirely different histories.

8 changed files with 22 additions and 158 deletions

View File

@ -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
a copy of this software and associated documentation files (the

View File

@ -10,19 +10,3 @@ Features:
* MIME type detecting
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**.

View File

@ -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"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

74
imgs
View File

@ -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"

View File

@ -1,6 +1,6 @@
[imgs]
debug = False
base_url = http://localhost:5000/
image_name_lenght = 3
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']

48
imgs.py
View File

@ -1,5 +1,3 @@
__version__ = '1.1'
import os
import random
import string
@ -50,38 +48,30 @@ def upload_image():
# Handle request from CLI
if 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']:
# Upload file!
image_name = upload_file(file)
return get_image_url(image_name) + '\n'
else:
# Show MIME type error!
# Prevent recource leek. Force close buffered file
request.body.close()
response.status = 415
if rq == 'cli':
return 'Error: bad file MIME type\n'
else:
return template('index.tpl',
uploaded = False, not_found = False, bad_mime_type = True,
allowed_mime_types = config['imgs.allowed_mime_types'],
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))
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:
# Prevent recource leek. Force close buffered file
request.body.close()
response.status = 415
return template('index.tpl',
uploaded = False, not_found = False, bad_mime_type = True,
allowed_mime_types = config['imgs.allowed_mime_types'],
base_url = get_base_url(), image_url = 'None')
@get('/<image_name>')
def send_image(image_name):
@ -92,4 +82,4 @@ def send_style():
return static_file('style.css', root = './')
if __name__ == '__main__':
run()
run(debug = config['imgs.debug'])

View File

@ -77,7 +77,7 @@
<div class="logo">
<pre> __<br>|__| _____ ____ ______<br>| |/ \ / ___\/ ___/<br>| | Y Y / /_/ \___ \<br>|__|__|_| \___ /____ ><br> \/_____/ \/</pre>
</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>
</body>