Add API to delete local files
This commit is contained in:
parent
73fc9a42a7
commit
41ca328009
2 changed files with 44 additions and 0 deletions
|
@ -561,6 +561,34 @@ class FilesDB {
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> deleteLocalFiles(List<String> localIDs) async {
|
||||
String inParam = "";
|
||||
for (final localID in localIDs) {
|
||||
inParam += "'" + localID + "',";
|
||||
}
|
||||
inParam = inParam.substring(0, inParam.length - 1);
|
||||
final db = await instance.database;
|
||||
await db.rawQuery('''
|
||||
UPDATE $table
|
||||
SET $columnLocalID = NULL
|
||||
WHERE $columnLocalID IN ($inParam);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<List<File>> getLocalFiles(List<String> localIDs) async {
|
||||
String inParam = "";
|
||||
for (final localID in localIDs) {
|
||||
inParam += "'" + localID + "',";
|
||||
}
|
||||
inParam = inParam.substring(0, inParam.length - 1);
|
||||
final db = await instance.database;
|
||||
final results = await db.query(
|
||||
table,
|
||||
where: '$columnLocalID IN ($inParam)',
|
||||
);
|
||||
return _convertToFiles(results);
|
||||
}
|
||||
|
||||
Future<int> deleteFromCollection(int uploadedFileID, int collectionID) async {
|
||||
final db = await instance.database;
|
||||
return db.delete(
|
||||
|
|
|
@ -135,3 +135,19 @@ Future<void> deleteFilesOnDeviceOnly(
|
|||
}
|
||||
await dialog.hide();
|
||||
}
|
||||
|
||||
Future<void> deleteLocalFiles(List<String> localIDs) async {
|
||||
List<String> deletedIDs = [];
|
||||
try {
|
||||
deletedIDs = await PhotoManager.editor.deleteWithIds(localIDs);
|
||||
} catch (e, s) {
|
||||
_logger.severe("Could not delete files", e, s);
|
||||
}
|
||||
if (deletedIDs.isNotEmpty) {
|
||||
final deletedFiles = await FilesDB.instance.getLocalFiles(deletedIDs);
|
||||
await FilesDB.instance.deleteLocalFiles(deletedIDs);
|
||||
_logger.info(deletedFiles.length.toString() + " files deleted locally");
|
||||
Bus.instance
|
||||
.fire(LocalPhotosUpdatedEvent(deletedFiles, type: EventType.deleted));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue