Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
770B

  1. #!/bin/bash
  2. # A simple Bash script to delete an media from the Nginx cache.
  3. SCRIPTNAME=${0##*/}
  4. # NGINX cache directory
  5. CACHE_DIRECTORY="/tmp/pleroma-media-cache"
  6. function get_cache_files() {
  7. local max_parallel=${3-16}
  8. find $2 -maxdepth 1 -type d | xargs -P $max_parallel -n 1 grep -ERl "^KEY:.*$1" | sort -u
  9. }
  10. function purge_item() {
  11. local cache_files
  12. cache_files=$(get_cache_files "$1" "$2")
  13. if [ -n "$cache_files" ]; then
  14. for i in $cache_files; do
  15. [ -f $i ] || continue
  16. echo "Deleting $i from $2."
  17. rm $i
  18. done
  19. else
  20. echo "$1 is not cached."
  21. fi
  22. }
  23. function purge() {
  24. for url in "$@"
  25. do
  26. echo "$SCRIPTNAME delete $url from cache ($CACHE_DIRECTORY)"
  27. purge_item $url $CACHE_DIRECTORY
  28. done
  29. }
  30. purge $1