I'd like to use Slink as a hosted service to allow users to share their images, even as guests.
Unfortunately, since disk space isn't infinite, it'd be nice to have the option to define an expiry time on the config and/or a selection for guests.
Meanwhile, I "hacked" my way with this bash script, when using SQLite database:
#!/bin/bash
# Slink cleanup script - deletes images older than a configurable time window
# -------- CONFIG --------
DB="/etc/slink/slink/var/data/slink.db" # path to slink.db
UPLOADS="/etc/slink/slink/images" # path to Slink images folder
EXPIRE_WINDOW="-24 hours" # files older than 24h will be deleted
LOG="/var/log/slink/cleanup.log" # the folder most exist and be owned by the user running the bash script
# ------------------------
{
echo "===== $(date) ====="
echo "Slink cleanup started..."
echo "Expiry window: $EXPIRE_WINDOW"
# Delete files
sqlite3 "$DB" "
SELECT uuid FROM image
WHERE created_at < datetime('now', '$EXPIRE_WINDOW');
" | while read uuid; do
rm -f "$UPLOADS/$uuid".*
echo "Deleted file: $UPLOADS/$uuid.*"
done
# Delete DB entries in correct order
sqlite3 "$DB" <<EOF
DELETE FROM short_url
WHERE share_id IN (
SELECT uuid FROM share
WHERE image_id IN (SELECT uuid FROM image WHERE created_at < datetime('now', '$EXPIRE_WINDOW'))
);
DELETE FROM share
WHERE image_id IN (SELECT uuid FROM image WHERE created_at < datetime('now', '$EXPIRE_WINDOW'));
DELETE FROM bookmark
WHERE image_id IN (SELECT uuid FROM image WHERE created_at < datetime('now', '$EXPIRE_WINDOW'));
DELETE FROM image_to_tag
WHERE image_id IN (SELECT uuid FROM image WHERE created_at < datetime('now', '$EXPIRE_WINDOW'));
DELETE FROM image WHERE created_at < datetime('now', '$EXPIRE_WINDOW');
EOF
# Vacuum DB
sqlite3 "$DB" "VACUUM;"
echo "Slink cleanup completed."
echo ""
} >> "$LOG" 2>&1
I'd like to use Slink as a hosted service to allow users to share their images, even as guests.
Unfortunately, since disk space isn't infinite, it'd be nice to have the option to define an expiry time on the config and/or a selection for guests.
Meanwhile, I "hacked" my way with this bash script, when using SQLite database: