Skip to content

Commit

Permalink
feat(#74): rework upload func to use configurable google cloud storage
Browse files Browse the repository at this point in the history
closes #74
  • Loading branch information
meatwallace committed May 22, 2019
1 parent b2dfe34 commit 4f317ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export MEATBOX_LIBS_DIR="$MEATBOX_DIR/libs"
export MEATBOX_SCRIPTS_DIR="$MEATBOX_DIR/scripts"
export MEATLAB_DIR="$HOME/projects/meatlab"

export GSUTILS_DEFAULT_BUCKET="files.clusterfu.xyz"

# variables for different tools
export CLICOLOR=1
# export LSCOLORS="exfxcxdxbxegedabagacad"
Expand Down
27 changes: 9 additions & 18 deletions bin/upload
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,26 @@

usage() {
cat << HEREDOC
transfer
upload
Usage: transfer <file>
Usage: upload <file_name> [<uploaded_name>]
HEREDOC
}

transfer() {
upload() {
if [ $# -eq 0 ]; then
usage

return 0
fi

tmpfile=$(mktemp -t transferXXX)

if tty -s; then
basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g')

curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> "$tmpfile"
else
curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> "$tmpfile"
fi

url="$(cat "$tmpfile")"
input_file_name="$1"
upload_file_name="${2:-$1}"
bucket="$GSUTILS_DEFAULT_BUCKET"

rm -f "$tmpfile" >/dev/null 2>&1
gsutil cp "$input_file_name" "gs://$bucket/$upload_file_name"

echo "$url"
echo "https://$bucket/$upload_file_name"
}

transfer "$@"

upload "$@"

0 comments on commit 4f317ea

Please sign in to comment.