QNUploadFileInfo.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // QNUploadData.m
  3. // QiniuSDK_Mac
  4. //
  5. // Created by yangsen on 2020/4/30.
  6. // Copyright © 2020 Qiniu. All rights reserved.
  7. //
  8. #import "QNUploadFileInfo.h"
  9. @interface QNUploadData()
  10. @property(nonatomic, assign)long long offset;
  11. @property(nonatomic, assign)long long size;
  12. @property(nonatomic, assign)NSInteger index;
  13. @end
  14. @implementation QNUploadData
  15. + (instancetype)dataFromDictionary:(NSDictionary *)dictionary{
  16. if (![dictionary isKindOfClass:[NSDictionary class]]) {
  17. return nil;
  18. }
  19. QNUploadData *data = [[QNUploadData alloc] init];
  20. data.offset = [dictionary[@"offset"] longLongValue];
  21. data.size = [dictionary[@"size"] longLongValue];
  22. data.index = [dictionary[@"index"] integerValue];
  23. data.etag = dictionary[@"etag"];
  24. data.isCompleted = [dictionary[@"isCompleted"] boolValue];
  25. if (data.isCompleted) {
  26. data.progress = 1;
  27. } else {
  28. data.progress = 0;
  29. }
  30. return data;
  31. }
  32. - (instancetype)initWithOffset:(long long)offset
  33. dataSize:(long long)dataSize
  34. index:(NSInteger)index {
  35. if (self = [super init]) {
  36. _offset = offset;
  37. _size = dataSize;
  38. _index = index;
  39. _etag = nil;
  40. _isCompleted = NO;
  41. _progress = 0;
  42. }
  43. return self;
  44. }
  45. - (BOOL)isFirstData{
  46. return self.index == 1;
  47. }
  48. - (void)clearUploadState{
  49. self.isCompleted = NO;
  50. self.isUploading = NO;
  51. self.etag = nil;
  52. }
  53. - (NSDictionary *)toDictionary{
  54. NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
  55. dictionary[@"offset"] = @(self.offset);
  56. dictionary[@"size"] = @(self.size);
  57. dictionary[@"index"] = @(self.index);
  58. dictionary[@"etag"] = self.etag;
  59. dictionary[@"isCompleted"] = @(self.isCompleted);
  60. return [dictionary copy];
  61. }
  62. @end
  63. @interface QNUploadFileInfo()
  64. @property(nonatomic, assign)long long size;
  65. @property(nonatomic, assign)NSInteger modifyTime;
  66. @end
  67. @implementation QNUploadFileInfo
  68. + (instancetype)infoFromDictionary:(NSDictionary *)dictionary{
  69. if (![dictionary isKindOfClass:[NSDictionary class]]) {
  70. return nil;
  71. }
  72. QNUploadFileInfo *fileInfo = [[self alloc] init];
  73. fileInfo.size = [dictionary[@"size"] longLongValue];
  74. fileInfo.modifyTime = [dictionary[@"modifyTime"] integerValue];
  75. return fileInfo;
  76. }
  77. - (void)clearUploadState{
  78. }
  79. - (BOOL)isAllUploaded{
  80. return NO;
  81. }
  82. - (float)progress{
  83. return 0;
  84. }
  85. - (BOOL)isEmpty{
  86. return NO;
  87. }
  88. - (BOOL)isValid{
  89. return YES;
  90. }
  91. - (NSDictionary *)toDictionary{
  92. NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
  93. dictionary[@"size"] = @(self.size);
  94. dictionary[@"modifyTime"] = @(self.modifyTime);
  95. return [dictionary copy];
  96. }
  97. @end