From 97a8e9a2bad70ce3fcbdd08002a0ae23e6ed896e Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Mon, 3 Apr 2023 00:37:54 +0200 Subject: [PATCH 1/2] fix: stop propagation of key events on menu search --- ui/menu/src/components/Menu.svelte | 4 ++-- ui/menu/src/components/MenuItemInput.svelte | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ui/menu/src/components/Menu.svelte b/ui/menu/src/components/Menu.svelte index 727d6fe..c29bc92 100644 --- a/ui/menu/src/components/Menu.svelte +++ b/ui/menu/src/components/Menu.svelte @@ -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} /> diff --git a/ui/menu/src/components/MenuItemInput.svelte b/ui/menu/src/components/MenuItemInput.svelte index 0a80adf..6d8a7f2 100644 --- a/ui/menu/src/components/MenuItemInput.svelte +++ b/ui/menu/src/components/MenuItemInput.svelte @@ -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 /> From 3be7f2795f17ff3277fb892dc011ab27f5b07e20 Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Mon, 3 Apr 2023 00:38:49 +0200 Subject: [PATCH 2/2] feat: add upload script --- scripts/upload.sh | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 scripts/upload.sh diff --git a/scripts/upload.sh b/scripts/upload.sh new file mode 100755 index 0000000..3101253 --- /dev/null +++ b/scripts/upload.sh @@ -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 ;-)"