QNServerUserConfig.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // QNServerUserConfig.m
  3. // QiniuSDK
  4. //
  5. // Created by yangsen on 2021/8/30.
  6. // Copyright © 2021 Qiniu. All rights reserved.
  7. //
  8. #import "QNServerUserConfig.h"
  9. @interface QNServerUserConfig()
  10. @property(nonatomic, strong)NSDictionary *info;
  11. @property(nonatomic, assign)double timestamp;
  12. @property(nonatomic, assign)long ttl;
  13. @property(nonatomic, strong)NSNumber *http3Enable;
  14. @property(nonatomic, strong)NSNumber *retryMax;
  15. @property(nonatomic, strong)NSNumber *networkCheckEnable;
  16. @end
  17. @implementation QNServerUserConfig
  18. + (instancetype)config:(NSDictionary *)info {
  19. QNServerUserConfig *config = [[QNServerUserConfig alloc] init];
  20. config.ttl = [info[@"ttl"] longValue];
  21. config.http3Enable = info[@"http3"][@"enabled"];
  22. config.networkCheckEnable = info[@"network_check"][@"enabled"];
  23. if (config.ttl < 10) {
  24. config.ttl = 10;
  25. }
  26. NSMutableDictionary *mutableInfo = [info mutableCopy];
  27. if (info[@"timestamp"] != nil) {
  28. config.timestamp = [info[@"timestamp"] doubleValue];
  29. }
  30. if (config.timestamp == 0) {
  31. config.timestamp = [[NSDate date] timeIntervalSince1970];
  32. mutableInfo[@"timestamp"] = @(config.timestamp);
  33. }
  34. config.info = [mutableInfo copy];
  35. return config;
  36. }
  37. - (BOOL)isValid {
  38. return [[NSDate date] timeIntervalSince1970] < (self.timestamp + self.ttl);
  39. }
  40. @end