mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 07:46:07 -07:00
Add function to delete exported files
This commit is contained in:
parent
deb49d7ff9
commit
8b8afacaea
6 changed files with 116 additions and 9 deletions
|
@ -50,7 +50,7 @@ export_table_options = {
|
|||
$(td).html(cellData);
|
||||
}
|
||||
},
|
||||
"width": "7%",
|
||||
"width": "8%",
|
||||
"className": "no-wrap"
|
||||
},
|
||||
{
|
||||
|
@ -61,7 +61,7 @@ export_table_options = {
|
|||
$(td).html(cellData);
|
||||
}
|
||||
},
|
||||
"width": "7%",
|
||||
"width": "8%",
|
||||
"className": "no-wrap"
|
||||
},
|
||||
{
|
||||
|
@ -72,7 +72,7 @@ export_table_options = {
|
|||
$(td).html(cellData);
|
||||
}
|
||||
},
|
||||
"width": "7%",
|
||||
"width": "8%",
|
||||
"className": "no-wrap"
|
||||
},
|
||||
{
|
||||
|
@ -83,7 +83,7 @@ export_table_options = {
|
|||
$(td).html(cellData);
|
||||
}
|
||||
},
|
||||
"width": "55%",
|
||||
"width": "50%",
|
||||
"className": "no-wrap"
|
||||
},
|
||||
{
|
||||
|
@ -98,7 +98,17 @@ export_table_options = {
|
|||
$(td).html('<button class="btn btn-xs btn-dark" data-id="' + rowData['row_id'] + '" disabled><i class="fa fa-question-circle fa-fw"></i> Not Found</button>');
|
||||
}
|
||||
},
|
||||
"width": "7%"
|
||||
"width": "8%",
|
||||
"className": "export_download"
|
||||
},
|
||||
{
|
||||
"targets": [6],
|
||||
"data": null,
|
||||
"createdCell": function (td, cellData, rowData, row, col) {
|
||||
$(td).html('<button class="btn btn-xs btn-danger btn-edit pull-left" data-id="' + rowData['row_id'] + '"><i class="fa fa-trash-o fa-fw"></i> Delete</button>');
|
||||
},
|
||||
"width": "8%",
|
||||
"className": "export_delete"
|
||||
}
|
||||
],
|
||||
"drawCallback": function (settings) {
|
||||
|
@ -117,7 +127,7 @@ export_table_options = {
|
|||
}
|
||||
};
|
||||
|
||||
$('.export_table').on('click', '> tbody > tr > td > button.btn-download', function (e) {
|
||||
$('.export_table').on('click', '> tbody > tr > td.export_download > button', function (e) {
|
||||
var tr = $(this).closest('tr');
|
||||
var row = export_table.row(tr);
|
||||
var rowData = row.data();
|
||||
|
@ -125,3 +135,18 @@ $('.export_table').on('click', '> tbody > tr > td > button.btn-download', functi
|
|||
e.preventDefault();
|
||||
window.location.href = 'download_export?row_id=' + rowData['row_id'];
|
||||
});
|
||||
|
||||
$('.export_table').on('click', '> tbody > tr > td.export_delete > button', function (e) {
|
||||
var tr = $(this).closest('tr');
|
||||
var row = export_table.row(tr);
|
||||
var rowData = row.data();
|
||||
|
||||
var msg = 'Are you sure you want to delete the following export?<br /><br /><strong>' + rowData['filename'] + '</strong>';
|
||||
var url = 'delete_export?row_id=' + rowData['row_id'];
|
||||
confirmAjaxCall(url, msg, null, null, redrawExportTable);
|
||||
|
||||
});
|
||||
|
||||
function redrawExportTable() {
|
||||
export_table.draw();
|
||||
}
|
|
@ -339,6 +339,7 @@ DOCUMENTATION :: END
|
|||
<th align="left" id="file_format">Format</th>
|
||||
<th align="left" id="filename">Filename</th>
|
||||
<th align="left" id="complete">Download</th>
|
||||
<th align="left" id="delete">Delete</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
|
|
|
@ -2308,6 +2308,12 @@ $(document).ready(function() {
|
|||
confirmAjaxCall(url, msg);
|
||||
});
|
||||
|
||||
$("#clear_exports").click(function () {
|
||||
var msg = 'Are you sure you want to clear the Tautulli metadata exports?';
|
||||
var url = 'delete_export?delete_all=true';
|
||||
confirmAjaxCall(url, msg);
|
||||
});
|
||||
|
||||
$("#clear_logs").click(function () {
|
||||
var msg = 'Are you sure you want to clear the Tautulli logs?';
|
||||
var url = 'delete_logs';
|
||||
|
|
|
@ -216,6 +216,11 @@ def delete_recently_added():
|
|||
return clear_table('recently_added')
|
||||
|
||||
|
||||
def delete_exports():
|
||||
logger.info("Tautulli Database :: Clearing exported items from database.")
|
||||
return clear_table('exports')
|
||||
|
||||
|
||||
def delete_rows_from_table(table, row_ids):
|
||||
if row_ids and isinstance(row_ids, str):
|
||||
row_ids = list(map(helpers.cast_to_int, row_ids.split(',')))
|
||||
|
|
|
@ -970,6 +970,46 @@ def set_export_complete(export_id):
|
|||
db.upsert(table_name='exports', key_dict=keys, value_dict=values)
|
||||
|
||||
|
||||
def delete_export(export_id):
|
||||
db = database.MonitorDatabase()
|
||||
if str(export_id).isdigit():
|
||||
export_data = get_export(export_id=export_id)
|
||||
|
||||
logger.debug("Tautulli Exporter :: Deleting export_id %s from the database.", export_id)
|
||||
result = db.action('DELETE FROM exports WHERE id = ?', args=[export_id])
|
||||
|
||||
if export_data and export_data['exists']:
|
||||
filepath = get_export_filepath(export_data['filename'])
|
||||
logger.debug("Tautulli Exporter :: Deleting exported file from '%s'.", filepath)
|
||||
try:
|
||||
os.remove(filepath)
|
||||
except OSError as e:
|
||||
logger.error("Tautulli Exporter :: Failed to delete exported file '%s': %s", filepath, e)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def delete_all_exports():
|
||||
db = database.MonitorDatabase()
|
||||
result = db.select('SELECT filename FROM exports')
|
||||
|
||||
deleted_files = True
|
||||
for row in result:
|
||||
if check_export_exists(row['filename']):
|
||||
filepath = get_export_filepath(row['filename'])
|
||||
try:
|
||||
os.remove(filepath)
|
||||
except OSError as e:
|
||||
logger.error("Tautulli Exporter :: Failed to delete exported file '%s': %s", filepath, e)
|
||||
deleted_files = False
|
||||
break
|
||||
|
||||
if deleted_files:
|
||||
database.delete_exports()
|
||||
return True
|
||||
|
||||
|
||||
def get_export_datatable(section_id=None, rating_key=None, kwargs=None):
|
||||
default_return = {'recordsFiltered': 0,
|
||||
'recordsTotal': 0,
|
||||
|
@ -1004,7 +1044,7 @@ def get_export_datatable(section_id=None, rating_key=None, kwargs=None):
|
|||
join_evals=[],
|
||||
kwargs=kwargs)
|
||||
except Exception as e:
|
||||
logger.warn("Tautulli Exporter :: Unable to execute database query for get_export_datatable: %s." % e)
|
||||
logger.warn("Tautulli Exporter :: Unable to execute database query for get_export_datatable: %s.", e)
|
||||
return default_return
|
||||
|
||||
result = query['result']
|
||||
|
|
|
@ -6488,7 +6488,6 @@ class WebInterface(object):
|
|||
Required parameters:
|
||||
row_id (int): The row id of the exported file to download
|
||||
|
||||
|
||||
Optional parameters:
|
||||
None
|
||||
|
||||
|
@ -6517,7 +6516,6 @@ class WebInterface(object):
|
|||
Required parameters:
|
||||
row_id (int): The row id of the exported file to download
|
||||
|
||||
|
||||
Optional parameters:
|
||||
None
|
||||
|
||||
|
@ -6528,3 +6526,35 @@ class WebInterface(object):
|
|||
result = exporter.get_export(export_id=row_id)
|
||||
if result and result['complete'] and result['exists']:
|
||||
serve_download(path=exporter.get_export_filepath(result['filename']), name=result['filename'])
|
||||
|
||||
@cherrypy.expose
|
||||
@cherrypy.tools.json_out()
|
||||
@requireAuth(member_of("admin"))
|
||||
@addtoapi()
|
||||
def delete_export(self, row_id=None, delete_all=False, **kwargs):
|
||||
""" Delete exports from Tautulli.
|
||||
|
||||
```
|
||||
Required parameters:
|
||||
row_id (int): The row id of the exported file to delete
|
||||
|
||||
Optional parameters:
|
||||
delete_all (bool): 'true' to delete all exported files
|
||||
|
||||
Returns:
|
||||
None
|
||||
```
|
||||
"""
|
||||
if helpers.bool_true(delete_all):
|
||||
result = exporter.delete_all_exports()
|
||||
if result:
|
||||
return {'result': 'success', 'message': 'All exports deleted successfully.'}
|
||||
else:
|
||||
return {'result': 'error', 'message': 'Failed to delete all exports.'}
|
||||
|
||||
else:
|
||||
result = exporter.delete_export(export_id=row_id)
|
||||
if result:
|
||||
return {'result': 'success', 'message': 'Export deleted successfully.'}
|
||||
else:
|
||||
return {'result': 'error', 'message': 'Failed to delete export.'}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue