Compare commits
8 Commits
8800b519c0
...
721fda8b22
Author | SHA1 | Date | |
---|---|---|---|
721fda8b22 | |||
331a377c6b | |||
12f4433e8e | |||
0898b1f593 | |||
4ff6362c64 | |||
8e4ab793f9 | |||
87f6c3a048 | |||
397aeed123 |
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
||||
Copyright (c) 2021 gd <gechandev@gmail.com>
|
||||
Copyright (c) 2022 ge <gechandev@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
16
README.md
16
README.md
@ -10,3 +10,19 @@ 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**.
|
||||
|
36
Upload to imgs
Executable file
36
Upload to imgs
Executable file
@ -0,0 +1,36 @@
|
||||
#!/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
Normal file
BIN
favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
74
imgs
Executable file
74
imgs
Executable file
@ -0,0 +1,74 @@
|
||||
#!/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]
|
||||
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']
|
||||
|
36
imgs.py
36
imgs.py
@ -1,3 +1,5 @@
|
||||
__version__ = '1.1'
|
||||
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
@ -48,30 +50,38 @@ def upload_image():
|
||||
# Handle request from CLI
|
||||
if request.files.get('image'):
|
||||
file = request.files.get('image')
|
||||
if file.content_type in config['imgs.allowed_mime_types']:
|
||||
image_name = upload_file(file)
|
||||
return get_image_url(image_name) + '\n'
|
||||
else:
|
||||
# Prevent recource leek. Force close buffered file
|
||||
request.body.close()
|
||||
response.status = 415
|
||||
return 'Error: bad file MIME type\n'
|
||||
rq = 'cli'
|
||||
# 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']:
|
||||
rq = 'web'
|
||||
|
||||
if config['imgs.allowed_mime_types'] == '*':
|
||||
# Skip MIME checking.
|
||||
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:
|
||||
if file.content_type in config['imgs.allowed_mime_types']:
|
||||
# Upload file!
|
||||
image_name = upload_file(file)
|
||||
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))
|
||||
|
||||
@get('/<image_name>')
|
||||
def send_image(image_name):
|
||||
@ -82,4 +92,4 @@ def send_style():
|
||||
return static_file('style.css', root = './')
|
||||
|
||||
if __name__ == '__main__':
|
||||
run(debug = config['imgs.debug'])
|
||||
run()
|
||||
|
@ -77,7 +77,7 @@
|
||||
<div class="logo">
|
||||
<pre> __<br>|__| _____ ____ ______<br>| |/ \ / ___\/ ___/<br>| | Y Y / /_/ \___ \<br>|__|__|_| \___ /____ ><br> \/_____/ \/</pre>
|
||||
</div>
|
||||
<p><a href="https://gitea.gch.icu/gd/imgs" target="_blank">v1.0</a></p>
|
||||
<p><a href="https://gitea.gch.icu/ge/imgs" target="_blank">v1.1</a></p>
|
||||
|
||||
</main>
|
||||
</body>
|
||||
|
Loading…
Reference in New Issue
Block a user