Skip to content

Commit b08dd93

Browse files
committed
feat: file prefix
1 parent d1efb7c commit b08dd93

File tree

3 files changed

+100
-203
lines changed

3 files changed

+100
-203
lines changed

AVOS/LeanCloudObjcTests/LCFileTestCase.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,27 @@ class LCFileTestCase: BaseTestCase {
3636
XCTAssertTrue(object0.fetch())
3737
XCTAssertTrue(object0[fileFieldKey] is LCFile)
3838
}
39+
40+
/*
41+
func testPathPrefix() {
42+
let prefixKey = "prefix"
43+
let prefixValue = "gamesaves"
44+
let file = LCFile(data: uuid.data(using: .utf8)!)
45+
file.setPathPrefix(prefixValue)
46+
XCTAssertEqual(file.metaData?[prefixKey] as? String, prefixValue)
47+
file.clearPathPrefix()
48+
XCTAssertNil(file.metaData?[prefixKey])
49+
file.setPathPrefix(prefixValue)
50+
expecting { exp in
51+
file.saveInBackground { succeeded, error in
52+
XCTAssertTrue(succeeded)
53+
XCTAssertNil(error)
54+
exp.fulfill()
55+
}
56+
}
57+
XCTAssertEqual(file.metaData?[prefixKey] as? String, prefixValue)
58+
XCTAssertNil(file.object(forKey: prefixKey))
59+
XCTAssertTrue((file.url ?? "").contains("/\(prefixValue)/"))
60+
}
61+
*/
3962
}

AVOS/Sources/Foundation/File/LCFile.h

Lines changed: 27 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef NS_OPTIONS(NSUInteger, LCFileDownloadOption) {
3636
*/
3737
@interface LCFile : NSObject <NSCoding>
3838

39-
// MARK: - Create
39+
// MARK: Create
4040

4141
/**
4242
Create file from NSData.
@@ -87,63 +87,22 @@ typedef NS_OPTIONS(NSUInteger, LCFileDownloadOption) {
8787
+ (instancetype)fileWithObjectId:(NSString *)objectId
8888
url:(NSString *)url;
8989

90-
// MARK: - Property
91-
92-
/*!
93-
The name of the file.
94-
*/
95-
- (NSString * _Nullable)name;
96-
97-
/*!
98-
The id of the file.
99-
*/
100-
- (NSString * _Nullable)objectId;
101-
102-
/*!
103-
The url of the file.
104-
*/
105-
- (NSString * _Nullable)url;
106-
107-
/*!
108-
File metadata, caller is able to store additional values here.
109-
*/
110-
@property (nonatomic, strong, nullable) NSDictionary *metaData;
111-
112-
/**
113-
Owner ID of file, Customizable.
114-
*/
115-
@property (nonatomic, strong, nullable) NSString *ownerId;
116-
117-
/**
118-
Checksum of file, Customizable.
119-
*/
120-
@property (nonatomic, strong, nullable) NSString *checksum;
121-
122-
/**
123-
Size of file.
124-
*/
125-
- (NSUInteger)size;
126-
127-
/**
128-
Path Extension of file.
129-
*/
130-
- (NSString * _Nullable)pathExtension;
131-
132-
/**
133-
MIME Type of file.
134-
*/
135-
- (NSString * _Nullable)mimeType;
136-
137-
/*!
138-
* The access control list for this file.
139-
*/
140-
@property (nonatomic, strong, nullable) LCACL *ACL;
141-
90+
/// The id of the file.
91+
@property (nonatomic, readonly, nullable) NSString *objectId;
92+
/// The url of the file.
93+
@property (nonatomic, readonly, nullable) NSString *url;
94+
/// The name of the file.
95+
@property (nonatomic, nullable) NSString *name;
96+
/// File metadata, caller is able to store additional values here.
97+
@property (nonatomic, nullable) NSDictionary *metaData;
98+
/// MIME Type of file.
99+
@property (nonatomic, nullable) NSString *mimeType;
100+
/// The access control list for this file.
101+
@property (nonatomic, nullable) LCACL *ACL;
142102
/// Created date.
143-
@property (nonatomic, strong, readonly, nullable) NSDate *createdAt;
144-
103+
@property (nonatomic, readonly, nullable) NSDate *createdAt;
145104
/// Updated date.
146-
@property (nonatomic, strong, readonly, nullable) NSDate *updatedAt;
105+
@property (nonatomic, readonly, nullable) NSDate *updatedAt;
147106

148107
/*!
149108
Request headers for file uploading.
@@ -152,7 +111,7 @@ typedef NS_OPTIONS(NSUInteger, LCFileDownloadOption) {
152111
Currently, it only supports files in US node, aka. the files hosted on AmazonS3.
153112
See https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html for all request headers.
154113
*/
155-
@property (nonatomic, strong, nullable) NSDictionary<NSString *, NSString *> *uploadingHeaders;
114+
@property (nonatomic, nullable) NSDictionary<NSString *, NSString *> *uploadingHeaders;
156115

157116
/**
158117
Returns the value associated with a given key.
@@ -162,7 +121,7 @@ typedef NS_OPTIONS(NSUInteger, LCFileDownloadOption) {
162121
*/
163122
- (id _Nullable)objectForKey:(id)key;
164123

165-
// MARK: - Upload
124+
// MARK: Upload
166125

167126
/**
168127
Upload Method. Use default option `LCFileUploadOptionCachingData`.
@@ -191,7 +150,7 @@ typedef NS_OPTIONS(NSUInteger, LCFileDownloadOption) {
191150
progress:(void (^ _Nullable)(NSInteger number))uploadProgressBlock
192151
completionHandler:(void (^)(BOOL succeeded, NSError * _Nullable error))completionHandler;
193152

194-
// MARK: - Download
153+
// MARK: Download
195154

196155
/**
197156
Download Method. Use default option `LCFileDownloadOptionCachedData`.
@@ -220,7 +179,7 @@ typedef NS_OPTIONS(NSUInteger, LCFileDownloadOption) {
220179
progress:(void (^ _Nullable)(NSInteger number))downloadProgressBlock
221180
completionHandler:(void (^)(NSURL * _Nullable filePath, NSError * _Nullable error))completionHandler;
222181

223-
// MARK: - Cancel
182+
// MARK: Cancel
224183

225184
/**
226185
Cancel Uploading Task.
@@ -232,7 +191,7 @@ typedef NS_OPTIONS(NSUInteger, LCFileDownloadOption) {
232191
*/
233192
- (void)cancelDownloading;
234193

235-
// MARK: - Cache
194+
// MARK: Cache
236195

237196
/**
238197
Set a Custom Persistent Cache Directory for files.
@@ -259,7 +218,7 @@ typedef NS_OPTIONS(NSUInteger, LCFileDownloadOption) {
259218
*/
260219
- (NSString * _Nullable)persistentCachePath;
261220

262-
// MARK: - Delete
221+
// MARK: Delete
263222

264223
/**
265224
Delete This File Object from server.
@@ -277,7 +236,7 @@ typedef NS_OPTIONS(NSUInteger, LCFileDownloadOption) {
277236
+ (void)deleteWithFiles:(NSArray<LCFile *> *)files
278237
completionHandler:(void (^)(BOOL succeeded, NSError * _Nullable error))completionHandler;
279238

280-
// MARK: - Get
239+
// MARK: Get
281240

282241
/**
283242
Get File Object from server.
@@ -288,7 +247,7 @@ typedef NS_OPTIONS(NSUInteger, LCFileDownloadOption) {
288247
+ (void)getFileWithObjectId:(NSString *)objectId
289248
completionHandler:(void (^)(LCFile * _Nullable file, NSError * _Nullable error))completionHandler;
290249

291-
// MARK: - Thumbnail
250+
// MARK: Thumbnail
292251

293252
/*!
294253
Get a thumbnail URL for image saved on Qiniu.
@@ -330,7 +289,7 @@ typedef NS_OPTIONS(NSUInteger, LCFileDownloadOption) {
330289
height:(int)height
331290
withBlock:(LCIdResultBlock)block;
332291

333-
// MARK: - Query
292+
// MARK: Query
334293

335294
/*!
336295
Create an LCFileQuery which returns files.
@@ -344,6 +303,9 @@ typedef NS_OPTIONS(NSUInteger, LCFileDownloadOption) {
344303
- (void)saveInBackgroundWithBlock:(void (^)(BOOL succeeded, NSError * _Nullable error))block
345304
progressBlock:(void (^ _Nullable)(NSInteger number))progressBlock;
346305

306+
- (void)setPathPrefix:(NSString *)prefix;
307+
- (void)clearPathPrefix;
308+
347309
@end
348310

349311
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)