Add API to delete local files

This commit is contained in:
Vishnu 2021-06-28 15:42:12 +05:30
parent 73fc9a42a7
commit 41ca328009
2 changed files with 44 additions and 0 deletions

View file

@ -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(

View file

@ -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));
}
}