Compare commits

..

2 commits

Author SHA1 Message Date
3be7f2795f feat: add upload script
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-04-03 00:38:49 +02:00
97a8e9a2ba fix: stop propagation of key events on menu search 2023-04-03 00:37:54 +02:00
3 changed files with 77 additions and 3 deletions

72
scripts/upload.sh Executable file
View file

@ -0,0 +1,72 @@
#!/bin/bash
set -e
# Check for dependencies
which curl > /dev/null
which jq > /dev/null
# Assert required variables
if [ -z "$TALON_KEY" ]; then echo "TALON_KEY unset"; exit 1; fi
if [ -z "$TALON_URL" ]; then echo "TALON_URL unset"; exit 1; fi
if [ -z "$SUBDOMAIN" ]; then echo "SUBDOMAIN unset"; exit 1; fi
API_URL="$TALON_URL/api"
API_KEY_H="x-api-key: $TALON_KEY"
# Check if the website already exists
WEBSITE_STATUS=$(curl --head -o /dev/null -s -w "%{http_code}" "$API_URL/website/$SUBDOMAIN")
if [ "$WEBSITE_STATUS" = "200" ]; then
echo "Website '$SUBDOMAIN' found"
else
# Create the website if it does not exist
if [ -z "$WEBSITE_NAME" ]; then echo "WEBSITE_NAME unset"; exit 1; fi
CREATE_BODY=$(jq -c --null-input --arg name "$WEBSITE_NAME" --arg color "$WEBSITE_COLOR" \
--arg visibility "$WEBSITE_VISIBILITY" --arg source_url "$WEBSITE_SOURCE_URL" \
--arg source_icon "$WEBSITE_SOURCE_ICON" \
'{"name": $name, "color": $color, "visibility": $visibility, "source_url": $source_url, "source_icon": $source_icon} | delpaths([path(.[]| select(.==""))])')
echo "Creating website '$SUBDOMAIN': $CREATE_BODY"
curl -Ss --fail -X "PUT" -H "$API_KEY_H" -H "content-type: application/json" --data "$CREATE_BODY" "$API_URL/website/$SUBDOMAIN"
fi
# Check the upload directory
if [ ! -d "$1" ]; then echo "Upload directory does not exist"; exit 1; fi
if [ ! -f "$1/index.html" ]; then echo "Upload directory does not contain index.html"; exit 1; fi
# Validate fallback page param
if [ "$FALLBACK" ] && [ ! -f "$1/$FALLBACK" ]; then echo "fallback page $FALLBACK does not exist"; exit 1; fi
# Automatically detect fallback pages
if [ -z "$SPA" ] && [ -z "$FALLBACK" ]; then
if [ -f "$1/404.html" ]; then FALLBACK="404.html"; fi
if [ -f "$1/200.html" ]; then SPA=true; FALLBACK="200.html"; fi
fi
push_arg() {
if [ "$UPLOAD_ARGS" ]; then UPLOAD_ARGS="$UPLOAD_ARGS&"; fi
UPLOAD_ARGS="$UPLOAD_ARGS$1"
}
if [ "$FALLBACK" ]; then push_arg "fallback=$FALLBACK"; fi
if [ "$SPA" = "true" ]; then push_arg "spa=true"; fi
if [ "$UPLOAD_ARGS" ]; then UPLOAD_ARGS="?$UPLOAD_ARGS"; fi
if GIT_COMMIT=$(git rev-parse HEAD 2> /dev/null); then
echo "Git commit: $GIT_COMMIT";
push_arg "commit=$GIT_COMMIT"
fi
# Compress website
ARCHIVE=$(mktemp)
tar -cz --directory "$1" --file "$ARCHIVE" .
# Upload website
echo "Version params: $UPLOAD_ARGS"
echo "Uploading..."
curl --fail -X "POST" -H "$API_KEY_H" -H "content-type: application/octet-stream" --data-binary "@$ARCHIVE" "$API_URL/website/$SUBDOMAIN/upload$UPLOAD_ARGS"
rm "$ARCHIVE"
echo "Website uploaded ;-)"

View file

@ -49,7 +49,7 @@
closeSearch();
}
function searchKeypress(e: KeyboardEvent) {
function searchKeyup(e: KeyboardEvent) {
switch (e.key) {
case "Enter":
if (!searchText) {
@ -96,7 +96,7 @@
active={searchOpen || Boolean(searchText).valueOf()}
on:click={openSearch}
on:focusout={closeSearch}
on:keyup={searchKeypress}
on:keyup={searchKeyup}
bind:input={searchInput}
bind:text={searchText}
/>

View file

@ -26,7 +26,9 @@
bind:this={inputElm}
bind:value={text}
on:focusout
on:keyup
on:keypress|stopPropagation
on:keydown|stopPropagation
on:keyup|stopPropagation
use:selectTextOnFocus
/>
<Icon iconName="search" size={40} scale={0.6} />