Add object detection, tracking, mobile notifications, and search to any security camera.
clean events a bit
roryclearc4b6547db31b
diff --git a/clearcam/FileServer.m b/clearcam/FileServer.mindex b23e107..59cd1bc 100644--- a/clearcam/FileServer.m+++ b/clearcam/FileServer.m@@ -806,34 +806,49 @@- (BOOL)deleteEventWithTimeStamp:(NSTimeInterval)timeStamp {__block BOOL success = NO;- [self.context performBlockAndWait:^{- NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"EventEntity"];- double epsilon = 1;- fetchRequest.predicate = [NSPredicate predicateWithFormat:@"(timeStamp >= %lf) AND (timeStamp <= %lf)", timeStamp - epsilon, timeStamp + epsilon];- NSError *error = nil;- NSArray *events = [self.context executeFetchRequest:fetchRequest error:&error];- if (error) {- NSLog(@"Fetch error: %@", error.localizedDescription);- success = NO;- return;- }- if (events.count == 0) {- success = YES;- return;- }- for (NSManagedObject *event in events) {- [self.context deleteObject:event];- }- if ([self.context save:&error]) {- success = YES;- } else {- NSLog(@"Save error: %@", error.localizedDescription);- success = NO;+ const int maxRetries = 3;+ int attempt = 0;++ while (attempt < maxRetries) {+ attempt++;+ [self.context performBlockAndWait:^{+ NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"EventEntity"];+ double epsilon = 1;+ fetchRequest.predicate = [NSPredicate predicateWithFormat:@"(timeStamp >= %lf) AND (timeStamp <= %lf)", timeStamp - epsilon, timeStamp + epsilon];++ NSError *error = nil;+ NSArray *events = [self.context executeFetchRequest:fetchRequest error:&error];+ if (error) {+ NSLog(@"Fetch error (attempt %d): %@", attempt, error.localizedDescription);+ success = NO;+ return;+ }+ if (events.count == 0) {+ success = YES;+ return;+ }+ for (NSManagedObject *event in events) {+ [self.context deleteObject:event];+ }+ if ([self.context save:&error]) {+ success = YES;+ } else {+ NSLog(@"Save error (attempt %d): %@", attempt, error.localizedDescription);+ success = NO;+ }+ }];++ if (success) {+ break;}- }];++ NSLog(@"Retrying delete (attempt %d/%d)...", attempt, maxRetries);+ }+return success;}+- (NSArray *)fetchFramesForURL:(NSString *)url context:(NSManagedObjectContext *)context {if (!context) {NSLog(@"Context is nil, skipping fetch.");@@ -956,6 +971,10 @@- (NSArray *)fetchEventDataFromCoreData:(NSManagedObjectContext *)context {NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"EventEntity"];+ NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timeStamp"+ ascending:YES];+ [fetchRequest setSortDescriptors:@[sortDescriptor]];+NSError *error = nil;NSArray *fetchedEvents = [context executeFetchRequest:fetchRequest error:&error];@@ -981,7 +1000,6 @@};[eventDataArray addObject:eventDict];}-return eventDataArray;}diff --git a/clearcam/events.html b/clearcam/events.htmlindex 79cc0d3..1179c1d 100644--- a/clearcam/events.html+++ b/clearcam/events.html@@ -79,7 +79,7 @@}, 1000); // Wait 1 second before retrying} else {// Max retries reached, show a fallback- imgElement.src = 'path/to/placeholder-image.jpg'; // Replace with your placeholder image+ imgElement.removeAttribute('src');imgElement.alt = 'Image failed to load';imgElement.style.opacity = '0.5'; // Optional: dim the placeholderimgElement.onclick = null; // Disable click if image fails