chemokita13 / BeRealGate

BeRealGate, a new way to BeReal (not oficcial) where you can see posts without posting yours, download posts, comment and more!
https://berealgate.vercel.app
15 stars 1 forks source link

I don’t know if its my fault but I can’t post a real BeReal only lates #11

Open Leandro12341 opened 10 months ago

chemokita13 commented 10 months ago

I think Bereal Server compares the request date with the datetime sended in the request, the only way to post a real bereal is sending it on time. Have you tryied in Bereal time?

Leandro12341 commented 9 months ago

I think Bereal Server compares the request date with the datetime sended in the request, the only way to post a real bereal is sending it on time. Have you tryied in Bereal time?

yes i tryied but not working

chemokita13 commented 9 months ago

let me some time to work on it!

Lukas1h commented 9 months ago

I think Bereal Server compares the request date with the datetime sended in the request, the only way to post a real bereal is sending it on time. Have you tryied in Bereal time?

FYI, Bae is able to spoof whether or not the BeReal is late when uploading and allows you to post multiple times late, so it should be possible to implement.

chemokita13 commented 9 months ago

I think Bereal Server compares the request date with the datetime sended in the request, the only way to post a real bereal is sending it on time. Have you tryied in Bereal time?

FYI, Bae is able to spoof whether or not the BeReal is late when uploading and allows you to post multiple times late, so it should be possible to implement.

let me see it!

Lukas1h commented 9 months ago

I think Bereal Server compares the request date with the datetime sended in the request, the only way to post a real bereal is sending it on time. Have you tryied in Bereal time?

FYI, Bae is able to spoof whether or not the BeReal is late when uploading and allows you to post multiple times late, so it should be possible to implement.

let me see it!

From https://github.com/yandevelop/Bea/blob/main/Utilities/UploadTask/BeaUploadTask.m:


- (void)postBeRealWithFrontPath:(NSString *)frontPath backPath:(NSString *)backPath frontBucket:(NSString *)frontBucket backBucket:(NSString *)backBucket completion:(void (^)(BOOL success, NSError *error))completion {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];

    if (![self.userDictionary[@"isLate"] boolValue] && self.lastMoment) {
        // randomize the taken at to be between the startDate and endDate because its
        // logically impossible to "post" on the start time
        NSDate *moment = [dateFormatter dateFromString:self.lastMoment];
        NSInteger randomSeconds = arc4random_uniform(105 - 60) + 60;
        NSDate *dateInRange = [moment dateByAddingTimeInterval:randomSeconds];
        NSString *dateString = [dateFormatter stringFromDate:dateInRange];
        self.takenAt = dateString;
    } else {
        NSDate *currentDate = [NSDate date];
        self.takenAt = [dateFormatter stringFromDate:currentDate];
    }

    NSMutableDictionary *payload = [NSMutableDictionary dictionaryWithDictionary:@{
        @"visibility": @[@"friends"],
        @"isLate": @([self.userDictionary[@"isLate"] boolValue]),
        @"retakeCounter": self.userDictionary[@"retakeCounter"] ?: @0,
        @"takenAt": self.takenAt,
        @"backCamera": @{
            @"bucket": backBucket,
            @"height": @2000,
            @"width": @1500,
            @"path": backPath
        },
        @"frontCamera": @{
            @"bucket": frontBucket,
            @"height": @2000,
            @"width": @1500,
            @"path": frontPath
        }
    }];

    if (self.userDictionary[@"music"]) {
        [payload setObject:self.userDictionary[@"music"] forKey:@"music"];
    }

    if (self.userDictionary[@"longitude"] && self.userDictionary[@"latitude"]) {
        NSDictionary *locationDict = @{
            @"latitude": self.userDictionary[@"latitude"],
            @"longitude": self.userDictionary[@"longitude"]
        };
        [payload setObject:locationDict forKey:@"location"];
    }

    if (self.userDictionary[@"caption"]) {
        [payload setObject:self.userDictionary[@"caption"] forKey:@"caption"];
    }

    NSData *payloadJSON = [NSJSONSerialization dataWithJSONObject:payload options:NSJSONWritingWithoutEscapingSlashes error:nil];

    NSURL *postBeRealURL = [NSURL URLWithString:@"https://mobile.bereal.com/api/content/posts"];
    NSMutableURLRequest *postBeRealRequest = [NSMutableURLRequest requestWithURL:postBeRealURL];

    [postBeRealRequest setHTTPMethod:@"POST"];

    [postBeRealRequest setValue:@"application/json" forHTTPHeaderField:@"content-type"];
    [self.headers enumerateKeysAndObjectsUsingBlock:^(NSString *field, NSString *value, BOOL *stop) {
        [postBeRealRequest setValue:value forHTTPHeaderField:field];
    }];

    NSURLSessionUploadTask *uploadTask = [[NSURLSession sharedSession] uploadTaskWithRequest:postBeRealRequest fromData:payloadJSON completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
        if (error || httpResponse.statusCode > 299) {
            NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
            //NSString *message = [NSString stringWithFormat:@"1 - Uploading failed: %@: %@", responseDictionary[@"statusCode"], responseDictionary[@"errorKey"]];
            NSString *message = [NSString stringWithFormat:@"%@, %@, %@", responseDictionary[@"error"], responseDictionary[@"message"], responseDictionary[@"errorKey"]];
            [self handleErrorWithTitle:@"API Error" message:message completion:completion];
            return;
        }

        if (data) {
            // the upload succeded
            completion(YES, nil);
        }
    }];

    [uploadTask resume];
}
chemokita13 commented 9 months ago

@Lukas1h @Leandro12341 I think I did it! But its remainint testing, may you test it and give feedback? Branch url: https://be-real-gate-git-postlateissue-chemokita13.vercel.app/ (is the same web but with another branch deployed in)