Add object detection, tracking, mobile notifications, and search to any security camera.
clean posts
roryclear39ab0edb19aa
diff --git a/clearcam/AppDelegate.m b/clearcam/AppDelegate.mindex a7056de..99cb701 100644--- a/clearcam/AppDelegate.m+++ b/clearcam/AppDelegate.m@@ -2,6 +2,7 @@#import <UserNotifications/UserNotifications.h>#import "GalleryViewController.h"#import "StoreManager.h"+#import "FileServer.h"@interface AppDelegate () <UNUserNotificationCenterDelegate>@property (nonatomic, strong) NSDictionary *pendingNotification;@@ -134,34 +135,21 @@return;}- NSURL *url = [NSURL URLWithString:@"https://rors.ai/add_device"];- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];- request.HTTPMethod = @"POST";- [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];-- NSDictionary *body = @{- @"device_token": deviceToken,- @"session_token": sessionToken- };- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:body options:0 error:nil];- request.HTTPBody = jsonData;-- NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request- completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {+ [FileServer performPostRequestWithURL:@"https://rors.ai/add_device"+ method:@"POST"+ contentType:@"application/json"+ body:@{@"device_token": deviceToken, @"session_token": sessionToken}+ completionHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {if (error) {NSLog(@"Error sending device token: %@", error.localizedDescription);return;}-- NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;- if (httpResponse.statusCode == 200) {+ if (response.statusCode == 200) {NSLog(@"Device token successfully sent to server");} else {- NSLog(@"Failed to send device token, server responded with status code: %ld", (long)httpResponse.statusCode);+ NSLog(@"Failed to send device token, server responded with status code: %ld", (long)response.statusCode);}}];-- [task resume];}- (void)userNotificationCenter:(UNUserNotificationCenter *)centerdiff --git a/clearcam/Email.m b/clearcam/Email.mindex 193bb32..d20fc68 100644--- a/clearcam/Email.m+++ b/clearcam/Email.m@@ -1,6 +1,7 @@#import "Email.h"#import "SecretManager.h"#import "StoreManager.h"+#import "FileServer.h"#import <UIKit/UIKit.h>@implementation Email@@ -77,7 +78,7 @@[bodyData appendData:fileData];[bodyData appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];- // Include session_token only if not using own email server+ // Include session_token if not using own email serverif (![[NSUserDefaults standardUserDefaults] boolForKey:@"use_own_server_enabled"]) {NSString *sessionToken = [[StoreManager sharedInstance] retrieveSessionTokenFromKeychain];if (sessionToken) {@@ -89,25 +90,19 @@NSLog(@"Warning: No session token found in Keychain.");}}-[bodyData appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];- NSURL *url = [NSURL URLWithString:[server stringByAppendingString:endpoint]];- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];- [request setHTTPMethod:@"POST"];- [request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary] forHTTPHeaderField:@"Content-Type"];- [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)bodyData.length] forHTTPHeaderField:@"Content-Length"];- [request setHTTPBody:bodyData];-- NSURLSession *session = [NSURLSession sharedSession];- NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {+ [FileServer performPostRequestWithURL:[server stringByAppendingString:endpoint]+ method:@"POST"+ contentType:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]+ body:bodyData+ completionHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {if (error) {NSLog(@"Error: %@", error.localizedDescription);} else {NSLog(@"Send request completed successfully.");}}];- [task resume];}@enddiff --git a/clearcam/FileServer.h b/clearcam/FileServer.hindex dc28734..d3454d3 100644--- a/clearcam/FileServer.h+++ b/clearcam/FileServer.h@@ -12,6 +12,11 @@startTime:(NSTimeInterval)startTimeStampendTime:(NSTimeInterval)endTimeStampcontext:(NSManagedObjectContext *)context;++ (void)performPostRequestWithURL:(NSString *)urlString+ method:(NSString *)method+ contentType:(NSString *)contentType+ body:(id)body+ completionHandler:(void (^)(NSData *data, NSHTTPURLResponse *response, NSError *error))completion;@property (nonatomic, assign) NSInteger segment_length;@property (nonatomic, strong) NSDate *last_req_time;@property (nonatomic, strong) PortScanner *scanner;diff --git a/clearcam/FileServer.m b/clearcam/FileServer.mindex 8bb43e1..f3ed1c5 100644--- a/clearcam/FileServer.m+++ b/clearcam/FileServer.m@@ -892,6 +892,37 @@return framesForURL;}++ (void)performPostRequestWithURL:(NSString *)urlString+ method:(NSString *)method+ contentType:(NSString *)contentType+ body:(id)body+ completionHandler:(void (^)(NSData *data, NSHTTPURLResponse *response, NSError *error))completion {+ NSURL *url = [NSURL URLWithString:urlString];+ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];+ request.HTTPMethod = method;+ [request setValue:contentType forHTTPHeaderField:@"Content-Type"];++ // Handle body based on content type+ if ([contentType isEqualToString:@"application/json"] && [body isKindOfClass:[NSDictionary class]]) {+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:body options:0 error:nil];+ request.HTTPBody = jsonData;+ } else if ([contentType containsString:@"multipart/form-data"] && [body isKindOfClass:[NSData class]]) {+ [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[(NSData *)body length]] forHTTPHeaderField:@"Content-Length"];+ request.HTTPBody = body;+ } else if (body && [body isKindOfClass:[NSData class]]) {+ request.HTTPBody = body; // Raw data for other cases+ }++ NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request+ completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {+ NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;+ if (completion) {+ completion(data, httpResponse, error);+ }+ }];+ [task resume];+}+- (void)concatenateMP4Files:(NSArray<NSString *> *)filePaths completion:(void (^)(NSString *outputPath, NSError *error))completion {AVMutableComposition *composition = [AVMutableComposition composition];AVMutableCompositionTrack *videoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];diff --git a/clearcam/SettingsViewController.m b/clearcam/SettingsViewController.mindex 8ad2109..00b0eea 100644--- a/clearcam/SettingsViewController.m+++ b/clearcam/SettingsViewController.m@@ -4,6 +4,7 @@#import "StoreManager.h"#import "NumberSelectionViewController.h"#import "Email.h"+#import "FileServer.h"#import "ScheduleManagementViewController.h"#import <UserNotifications/UserNotifications.h>@@ -263,34 +264,21 @@return;}- NSURL *url = [NSURL URLWithString:@"https://rors.ai/add_device"];- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];- request.HTTPMethod = @"POST";- [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];-- NSDictionary *body = @{- @"device_token": deviceToken,- @"session_token": sessionToken- };- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:body options:0 error:nil];- request.HTTPBody = jsonData;-- NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request- completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {+ [FileServer performPostRequestWithURL:@"https://rors.ai/add_device"+ method:@"POST"+ contentType:@"application/json"+ body:@{@"device_token": deviceToken, @"session_token": sessionToken}+ completionHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {if (error) {NSLog(@"Error sending device token: %@", error.localizedDescription);return;}-- NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;- if (httpResponse.statusCode == 200) {+ if (response.statusCode == 200) {NSLog(@"Device token successfully sent to server");} else {- NSLog(@"Failed to send device token, server responded with status code: %ld", (long)httpResponse.statusCode);+ NSLog(@"Failed to send device token, server responded with status code: %ld", (long)response.statusCode);}}];-- [task resume];}- (void)deleteDeviceTokenFromServer {@@ -309,7 +297,7 @@return;}- NSURL *url = [NSURL URLWithString:@"https://web.ai/delete_device"];+ NSURL *url = [NSURL URLWithString:@"https://rors.ai/delete_device"];NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];request.HTTPMethod = @"DELETE"; // Changed from POST to DELETE[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];diff --git a/clearcam/StoreManager.m b/clearcam/StoreManager.mindex 4935d5f..7618d79 100644--- a/clearcam/StoreManager.m+++ b/clearcam/StoreManager.m@@ -1,4 +1,5 @@#import "StoreManager.h"+#import "FileServer.h"// Define the notification nameNSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreManagerSubscriptionStatusDidChangeNotification";@@ -160,15 +161,12 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreManreturn;}- NSURL *url = [NSURL URLWithString:@"https://rors.ai/verify_receipt"];- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];- request.HTTPMethod = @"POST";- request.HTTPBody = jsonData;- [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];-- NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {- isRequestInProgress = NO; // Reset flag when request completes-+ [FileServer performPostRequestWithURL:@"https://rors.ai/verify_receipt"+ method:@"POST"+ contentType:@"application/json"+ body:jsonData // Assuming jsonData is already an NSData object+ completionHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {+ isRequestInProgress = NO;if (error) {NSLog(@"Error verifying receipt: %@", error.localizedDescription);[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isSubscribed"];@@ -176,9 +174,7 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMancompletion(NO, nil);return;}-NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];-if (!jsonResponse || ![jsonResponse isKindOfClass:[NSDictionary class]]) {NSLog(@"Invalid response from server.");[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isSubscribed"];@@ -186,9 +182,7 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMancompletion(NO, nil);return;}-BOOL isSubscribed = [jsonResponse[@"valid"] boolValue];-if (isSubscribed) {NSString *sessionToken = jsonResponse[@"session_token"];if (sessionToken && [sessionToken isKindOfClass:[NSString class]]) {@@ -197,20 +191,15 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMan} else {NSLog(@"Warning: No valid session_token in response.");}-[[NSNotificationCenter defaultCenter] postNotificationName:StoreManagerSubscriptionStatusDidChangeNotification object:nil];} else {[self clearSessionTokenFromKeychain];NSLog(@"🚨 Subscription has expired.");}-[[NSUserDefaults standardUserDefaults] setBool:isSubscribed forKey:@"isSubscribed"];[[NSUserDefaults standardUserDefaults] synchronize];-completion(isSubscribed, nil);}];-- [task resume];}