{% extends "home/base_settings.html" %}
{% load static %}
{% block settings_content %}
<div class="title-bar">
    <h1>Actions</h1>
</div>
<div class="settings-group">
    <h2>Delete download queue</h2>
    <p>Delete your pending or previously ignored videos from your download queue.<p>
    <button onclick="deleteQueue(this)" id="ignore-button" data-id="ignore" title="Delete all previously ignored videos from the queue">Delete all ignored</button>
    <button onclick="deleteQueue(this)" id="pending-button" data-id="pending" title="Delete all pending videos from the queue">Delete all queued</button>
</div>
<div class="settings-group">
    <h2>Manual media files import.</h2>
    <p>Add files to the <span class="settings-current">cache/import</span> folder. Make sure to follow the instructions in the Github <a href="https://docs.tubearchivist.com/settings/actions/#manual-media-files-import" target="_blank">Wiki</a>.</p>
    <div id="manual-import">
        <button onclick="manualImport()">Start import</button>
    </div>
</div>
<div class="settings-group">
    <h2>Embed thumbnails into media file.</h2>
    <p>Set extracted youtube thumbnail as cover art of the media file.</p>
    <div id="re-embed">
        <button onclick="reEmbed()">Start process</button>
    </div>
</div>
<div class="settings-group">
    <h2>ZIP file index backup</h2>
    <p>Export your database to a zip file stored at <span class="settings-current">cache/backup</span>.</p>
    <p><i>Zip file backups are very slow for large archives and consistency is not guaranteed, use snapshots instead. Make sure no other tasks are running when creating a Zip file backup.</i></p>
    <div id="db-backup">
        <button onclick="dbBackup()">Start backup</button>
    </div>
</div>
<div class="settings-group">
    <h2>Restore from backup</h2>
    <p><span class="danger-zone">Danger Zone</span>: This will replace your existing index with the backup.</p>
    <p>Restore from available backup files from <span class="settings-current">cache/backup</span>.</p>
    {% if available_backups %}
        <div class="backup-grid-row">
            <span></span>
            <span>Timestamp</span>
            <span>Source</span>
            <span>Filename</span>
        </div>
        {% for backup in available_backups %}
            <div class="backup-grid-row" id="{{ backup.filename }}">
                <button onclick="dbRestore(this)" data-id="{{ backup.filename }}">Restore</button>
                <span>{{ backup.timestamp }}</span>
                <span>{{ backup.reason }}</span>
                <span>{{ backup.filename }}</span>
            </div>
        {% endfor %}
    {% else %}
        <p>No backups found.</p>
    {% endif %}
</div>
<div class="settings-group">
    <h2>Rescan filesystem</h2>
    <p><span class="danger-zone">Danger Zone</span>: This will delete the metadata of deleted videos from the filesystem.</p>
    <p>Rescan your media folder looking for missing videos and clean up index. More infos on the Github <a href="https://docs.tubearchivist.com/settings/actions/#rescan-filesystem" target="_blank">Wiki</a>.</p>
    <div id="fs-rescan">
        <button onclick="fsRescan()">Rescan filesystem</button>
    </div>
</div>
{% endblock settings_content %}
