Compare commits

..

No commits in common. "71e1d87d323d899c52c3ad3dbe291b1e57bf16a5" and "aed21e14a3d15280e5fd87b07344d22a45350519" have entirely different histories.

5 changed files with 141 additions and 158 deletions

View File

@ -18,18 +18,14 @@ Clone repository and edit **imgs.ini**.
Build Docker image: Build Docker image:
```shell ```bash
docker build --tag imgs . docker build --tag imgs .
``` ```
Run container from image. Replace **/path/to/your/uploads/dir** with path to directory where you want to store images: Run container from image. Replace **/path/to/your/uploads/dir** with path to directory where you want to store images:
```shell ```
docker run -d \ sudo docker run --rm --name imgs --detach --publish 127.0.0.1:5000:5000 --volume /path/to/your/uploads/dir:/opt/imgs/uploads imgs
--name imgs \
--publish 127.0.0.1:5000:5000 \
--volume /path/to/your/uploads/dir:/opt/imgs/uploads \
imgs
``` ```
imgs will launched on `127.0.0.1:5000`. Set up reverse proxy server. I recommed to use basic authentication to prevent abuses. Nginx virtual host example: imgs will launched on `127.0.0.1:5000`. Set up reverse proxy server. I recommed to use basic authentication to prevent abuses. Nginx virtual host example:
@ -63,7 +59,7 @@ server {
imgs has a simple CLI tool based on curl. Copy **imgs** script to your PATH. imgs has a simple CLI tool based on curl. Copy **imgs** script to your PATH.
```shell ```bash
sudo cp imgs /usr/bin/imgs sudo cp imgs /usr/bin/imgs
``` ```
@ -72,7 +68,3 @@ sudo cp imgs /usr/bin/imgs
Push files to your imgs instance via GNOME Files (former name: Nautilus). Depends on: curl, libnotify (notify-send utility). Push files to your imgs instance via GNOME Files (former name: Nautilus). Depends on: curl, libnotify (notify-send utility).
Just place **Upload to imgs** script into **~/.local/share/nautilus/scripts/** directory. Just place **Upload to imgs** script into **~/.local/share/nautilus/scripts/** directory.
```shell
DIR=~/.local/share/nautilus/scripts/; mkdir -p $DIR && cp Upload\ to\ imgs $DIR
```

View File

@ -1,32 +1,38 @@
#!/bin/sh #!/usr/bin/env bash
# This is an imgs https://git.nxhs.cloud/ge/imgs "integration" for Nautilus. # This is an imgs <https://gitea.gch.icu/ge/imgs> "integration" for Nautilus.
# Place this script into path: $HOME/.local/share/nautilus/scripts # Place this script into path: $HOME/.local/share/nautilus/scripts
# See more info at: <https://help.ubuntu.com/community/NautilusScriptsHowto> # See more info at: <https://help.ubuntu.com/community/NautilusScriptsHowto>
IMGSLOG="${IMGSLOG:-$HOME/imgs_debug.log}" imgs_check_vars() {
[ -n "$IMGSREMOTE" ] && return 0 # exit from func if variable is set [ "$IMGSLOG" ] || IMGSLOG=$HOME/imgs_debug.log
[ "$IMGSREMOTE" ] && return 0 # exit from func if variable is set
if [ -f "$HOME"/.imgsremote ]; then if [ -f "$HOME/.imgsremote" ]; then
# shellcheck source=/dev/null . $HOME/.imgsremote
. "$HOME"/.imgsremote fi
fi
if [ -z "$IMGSREMOTE" ]; then if [ "$IMGSREMOTE" ]; then
echo "$0: Error: IMGSREMOTE variable is not set." >&2; exit 1 :
fi else
echo "$0: Error: IMGSREMOTE variable is not set." >&2
exit 1
fi
}
[ -n "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Started" >> "$IMGSLOG" imgs_check_vars
echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | while read -r file; do [ "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Started" >> "$IMGSLOG"
[ -z "$file" ] && break
if [ -n "$IMGSDEBUG" ]; then while read -r file; do
[ "$file" ] || break
if [ "$IMGSDEBUG" ]; then
image="$(curl -v -L -F "image=@$file" "$IMGSREMOTE" 2>&1 | tee -a "$IMGSLOG")" image="$(curl -v -L -F "image=@$file" "$IMGSREMOTE" 2>&1 | tee -a "$IMGSLOG")"
image="$(echo "$image" | tail -n 1)" image="$(tail -n 1 <<< "$image")"
else else
image="$(curl -L -F "image=@$file" "$IMGSREMOTE")" image="$(curl -L -F "image=@$file" "$IMGSREMOTE")"
fi fi
[ -n "$IMGSDEBUG" ] && echo "$(date +"[%d %b %Y %H:%M:%S]") $file --> $image" >> "$IMGSLOG" [ "$IMGSDEBUG" ] && echo "$(date +"[%d %b %Y %H:%M:%S]") $file --> $image" >> "$IMGSLOG"
notify-send "File uploaded to imgs!" "$image" notify-send "File uploaded to imgs!" "$image"
done done <<< "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"
[ -n "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Finished" >> "$IMGSLOG" [ "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Finished" >> "$IMGSLOG"

100
imgs
View File

@ -1,74 +1,74 @@
#!/bin/sh #!/usr/bin/env bash
# imgs CLI https://git.nxhs.cloud/ge/imgs # imgs CLI client.
# Home page: <https://gitea.gch.icu/ge/imgs>
imgs_usage() { imgs_usage() {
cat <<- EOF cat <<- EOF
Upload images to remote imgs server. Upload images to remote imgs server.
Usage: imgs [-rvh] <file>... Usage: imgs [--version] [--help] [-r | --remote <URL>] <file>...
Options: Options:
-r, --remote remote imgs instance URI e.g. https://user:password@example.org -r, --remote remote imgs instance URI. Example:
-v, --version print version and exit. 'https://user:password@example.org'
-h, --help print this help message and exit. --version print version and exit.
--help print this help message and exit.
Environment variables: Environment variables:
IMGSREMOTE remote imgs instance URI. IMGSREMOTE remote imgs instance URI.
IMGSDEBUG enables verbose mode and logging. IMGSDEBUG enables verbose mode and logging.
IMGSLOG path to logfile. Default: ~/imgs_debug.log IMGSLOG path to logfile. Default: ~/imgs_debug.log
You can set variables in ~/.imgsremote file instead of ~/.bashrc You can set variables in ~/.imgsremote file instead of ~/.bashrc
See <https://git.nxhs.cloud/ge/imgs> for more info. See <https://gitea.gch.icu/ge/imgs> for more info.
EOF EOF
exit 0
} }
[ "$#" -eq 0 ] && { imgs_usage; exit 1; } imgs_check_vars() {
[ "$IMGSLOG" ] || IMGSLOG=$HOME/imgs_debug.log
[ "$IMGSREMOTE" ] && return 0 # exit from func if variable is set
# Transform long options to short ones if [ -f "$HOME/.imgsremote" ]; then
for arg in "$@"; do . $HOME/.imgsremote
shift fi
case "$arg" in
--remote) set -- "$@" "-r";; if [ "$IMGSREMOTE" ]; then
--help) set -- "$@" "-h";; :
--version) set -- "$@" "-v";; else
*) set -- "$@" "$arg";; 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 esac
done done
while getopts r:vh OPT; do imgs_check_vars
case "$OPT" in
r) IMGSREMOTE="$OPTARG";;
v) echo 'imgs CLI 1.1'; exit 0;;
h) imgs_usage; exit 0;;
*) echo "$0: Unknown option: $OPT" >&2; exit 1;;
esac
done
shift $((OPTIND - 1)) # shift for parse positional args [ "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Started" | tee -a "$IMGSLOG"
# Check variables for file in "${_files[@]}"; do
IMGSLOG="${IMGSLOG:-$HOME/imgs_debug.log}"
[ -n "$IMGSREMOTE" ] && return 0 # exit from func if variable is set
if [ -f "$HOME"/.imgsremote ]; then
# shellcheck source=/dev/null
. "$HOME"/.imgsremote
fi
if [ -z "$IMGSREMOTE" ]; then
echo "$0: Error: IMGSREMOTE variable is not set." >&2; exit 1
fi
[ -n "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Started" | tee -a "$IMGSLOG"
for file in "$@"; do
filepath="$(realpath "$file")" filepath="$(realpath "$file")"
if [ -n "$IMGSDEBUG" ]; then if [ "$IMGSDEBUG" ]; then
echo "Uploading $filepath ..." | tee -a "$IMGSLOG" echo "Uploading $filepath" | tee -a "$IMGSLOG"
curl -v -L -F "image=@/$filepath" "$IMGSREMOTE" 2>&1 | tee -a "$IMGSLOG" curl -v -L -F "image=@/$filepath" "$IMGSREMOTE" 2>&1 | tee -a "$IMGSLOG"
else else
curl -L -F "image=@/$filepath" "$IMGSREMOTE" curl -L -F "image=@/$filepath" "$IMGSREMOTE"
fi fi
done done
[ -n "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Finished" | tee -a "$IMGSLOG" [ "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Finished" | tee -a "$IMGSLOG"

View File

@ -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://git.nxhs.cloud/ge/imgs" target="_blank">v1.1</a></p> <p><a href="https://gitea.gch.icu/ge/imgs" target="_blank">v1.1</a></p>
</main> </main>
</body> </body>

View File

@ -1,18 +1,5 @@
:root {
--b: #000;
--w: #fff;
}
@media (prefers-color-scheme: dark) {
:root {
--b: #fff;
--w: #000;
}
}
body { body {
color: var(--b); background-color: #fff;
background-color: var(--w);
font-family: 'Ubuntu Mono', monospace; font-family: 'Ubuntu Mono', monospace;
max-width: 720px; max-width: 720px;
margin: 0 auto; margin: 0 auto;
@ -20,14 +7,11 @@ body {
} }
main { margin: 4rem 2rem; } main { margin: 4rem 2rem; }
a, a:visited { color: var(--b); }
img { width: 100%; }
.not-found, .bad-mime-type { margin-bottom: 2rem; } .not-found, .bad-mime-type { margin-bottom: 2rem; }
.logo pre {
display: flex; a, a:visited { color: #000; }
justify-content: center;
text-align: left; img { width: 100%; }
}
/* Drag and Drop */ /* Drag and Drop */
.drop-area { .drop-area {
@ -39,7 +23,9 @@ img { width: 100%; }
padding: 25px; padding: 25px;
border: 3px dashed #e1e1e1; border: 3px dashed #e1e1e1;
} }
.drop-area.dragover { border-color: var(--b); }
.drop-area.dragover { border-color: #000; }
.file-input { .file-input {
position: absolute; position: absolute;
left: 0; left: 0;
@ -50,6 +36,7 @@ img { width: 100%; }
align-items: center; align-items: center;
opacity: 0; opacity: 0;
} }
.file-input-label { .file-input-label {
display: block; display: block;
margin-top: 1rem; margin-top: 1rem;
@ -59,17 +46,17 @@ img { width: 100%; }
.copy-to-clipboard { .copy-to-clipboard {
display: flex; display: flex;
margin: 2rem 0; margin: 2rem 0;
border: 1px solid var(--b); border: 1px solid #000000;
} }
.copy-to-clipboard input[type=text] { .copy-to-clipboard input[type=text] {
flex: 50%; flex: 50%;
width: 100%; width: 100%;
padding: 12px 20px; padding: 12px 20px;
border: none; border: none;
outline: none; outline: none;
background-color: var(--w);
color: var(--b);
} }
.copy-to-clipboard button { .copy-to-clipboard button {
padding: 12px 20px; padding: 12px 20px;
margin: 0; margin: 0;
@ -77,8 +64,8 @@ img { width: 100%; }
cursor: pointer; cursor: pointer;
text-align: center; text-align: center;
border: none; border: none;
background-color: var(--b); background-color: #000000;
color: var(--w); color: #ffffff;
} }
/* cURL command */ /* cURL command */
@ -86,15 +73,13 @@ img { width: 100%; }
text-align: left; text-align: left;
padding: 12px 20px; padding: 12px 20px;
font-size: 14px; font-size: 14px;
background: var(--b); background: #000000;
color: var(--w); color: #ffffff;
overflow-x: auto; overflow-x: auto;
} }
/* SVG */ .logo pre {
svg { display: flex;
color: var(--b); justify-content: center;
} text-align: left;
svg path {
stroke: currentcolor;
} }