Tools to interface with Teknik Services.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env bash
  2. # name: teknik-upload
  3. # creator: KittyKatt
  4. # requires: bash 4.0+, curl
  5. # Common Functions/Variables
  6. displayUsage() {
  7. printf "
  8. Teknik Upload Script in BASH
  9. Usage : $(basename ${0}) -[ e (s) | d | h ]
  10. Options:
  11. -h, --help\t Display this help message.
  12. -d, --deletion\t Generate a deletion key."
  13. }
  14. # Options
  15. while getopts ":heds" flags; do
  16. case $flags in
  17. h) displayUsage; exit 0 ;;
  18. d) deletion="1"; shift ;;
  19. ?) printf "Error! That flag doesn't exist."; exit 1 ;;
  20. esac
  21. done
  22. # Let's build our request
  23. # Defaults: encryption, server-side savekey
  24. files="$@"
  25. encrypt="true"
  26. savekey="true"
  27. deletionkey="false"
  28. if [[ "${deletion}" == "1" ]]; then
  29. deletionkey="true"
  30. fi
  31. # Main
  32. if [[ -z "${files}" ]]; then
  33. printf 'You must submit a file to be uploaded!\n'
  34. exit 1
  35. else
  36. printf 'Uploading file(s) now!'
  37. n=1
  38. for i in "$@"; do
  39. # Upload those files!
  40. printf "\nUploading file #${n} . . . "
  41. # Special case for .png files
  42. iext="${i##*.}"
  43. if [[ "${iext}" == "png" || "${iext}" == "PNG" ]]; then
  44. out=$(curl -sf -F "contentType=image/png" -F "encrypt=${encrypt}" -F "saveKey=${savekey}" -F "genDeletionKey=${deletionkey}" -F file="@${i}" https://api.teknik.io/v1/Upload)
  45. else
  46. out=$(curl -sf -F "encrypt=${encrypt}" -F "saveKey=${savekey}" -F "genDeletionKey=${deletionkey}" -F file="@${i}" https://api.teknik.io/v1/Upload)
  47. fi
  48. if [[ "${out}" =~ "error" ]]; then
  49. printf 'error uploading file!\n'
  50. exit 1
  51. else
  52. id="${out##*Name\":\"}"
  53. id="${id%%\"*}"
  54. printf "uploaded! Your file can be found at https://u.teknik.io/${id}\n"
  55. if [[ "${deletionkey}" == "true" ]]; then
  56. dkey="${out##*deletionKey\":\"}"
  57. dkey="${dkey%%\"*}"
  58. printf "(Deletion Key: ${dkey})"
  59. fi
  60. fi
  61. ((n++))
  62. done
  63. fi