Skip to content

Commit 2e55079

Browse files
authored
object lifecycle add archiveIR & fix batch rs host (#258)
1 parent 5c849f7 commit 2e55079

File tree

5 files changed

+80
-19
lines changed

5 files changed

+80
-19
lines changed

src/Qiniu/Storage/BatchInfo.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class BatchData
6060
/// 1 低频存储
6161
/// 2 归档存储
6262
/// 3 深度归档存储
63+
/// 4 归档直读存储
6364
/// </summary>
6465
[JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)]
6566
public int FileType { get; set; }
@@ -99,24 +100,32 @@ public class BatchData
99100

100101
/// <summary>
101102
/// 文件生命周期中转为低频存储的日期,Unix 时间戳格式。
102-
/// 文件在设置过期时间后才会返回该字段
103-
/// 历史文件过期仍会自动删除,但不会返回该字段,重新设置文件过期时间可使历史文件返回该字段
103+
/// 文件在设置低频存储转换时间后才会返回该字段
104+
/// 历史文件到期仍会自动转换,但不会返回该字段,重新设置文件转换时间可使历史文件返回该字段
104105
/// </summary>
105106
[JsonProperty("TransitionToIA", NullValueHandling = NullValueHandling.Ignore)]
106107
public int TransitionToIa { get; set; }
107108

109+
/// <summary>
110+
/// 文件生命周期中转为归档直读存储的日期,Unix 时间戳格式。
111+
/// 文件在设置归档直读存储转换时间后才会返回该字段。
112+
/// 历史文件到期仍会自动转换,但不会返回该字段,重新设置文件转换时间可使历史文件返回该字段。
113+
/// </summary>
114+
[JsonProperty("transitionToArchiveIR", NullValueHandling = NullValueHandling.Ignore)]
115+
public int TransitionToArchiveIr { get; set; }
116+
108117
/// <summary>
109118
/// 文件生命周期中转为归档存储的日期,Unix 时间戳格式。
110-
/// 文件在设置过期时间后才会返回该字段
111-
/// 历史文件过期仍会自动删除,但不会返回该字段,重新设置文件过期时间可使历史文件返回该字段
119+
/// 文件在设置归档存储转换时间后才会返回该字段
120+
/// 历史文件到期仍会自动转换,但不会返回该字段,重新设置文件转换时间可使历史文件返回该字段
112121
/// </summary>
113122
[JsonProperty("transitionToARCHIVE", NullValueHandling = NullValueHandling.Ignore)]
114123
public int TransitionToArchive { get; set; }
115124

116125
/// <summary>
117126
/// 文件生命周期中转为深度归档存储的日期,Unix 时间戳格式。
118-
/// 文件在设置过期时间后才会返回该字段
119-
/// 历史文件过期仍会自动删除,但不会返回该字段,重新设置文件过期时间可使历史文件返回该字段
127+
/// 文件在设置深度归档存储转换时间后才会返回该字段
128+
/// 历史文件到期仍会自动转换,但不会返回该字段,重新设置文件转换时间可使历史文件返回该字段
120129
/// </summary>
121130
[JsonProperty("transitionToDeepArchive", NullValueHandling = NullValueHandling.Ignore)]
122131
public int TransitionToDeepArchive { get; set; }

src/Qiniu/Storage/BucketManager.cs

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,14 @@ public HttpResult ChangeStatus(string bucket, string key, int status)
338338
/// </summary>
339339
/// <param name="bucket">空间名称</param>
340340
/// <param name="key">文件key</param>
341-
/// <param name="fileType">修改后的文件存储类型,0表示普通存储,1表示低频存储,2表示归档存储,3表示深度归档存储</param>
341+
/// <param name="fileType">
342+
/// 修改后的文件存储类型:
343+
/// 0 表示普通存储;
344+
/// 1 表示低频存储;
345+
/// 2 表示归档存储;
346+
/// 3 表示深度归档存储;
347+
/// 4 表示归档直读存储;
348+
/// </param>
342349
/// <returns>状态码为200时表示OK</returns>
343350
public HttpResult ChangeType(string bucket, string key, int fileType)
344351
{
@@ -414,11 +421,36 @@ private BatchResult Batch(string batchOps)
414421
{
415422
BatchResult result = new BatchResult();
416423

424+
string bucket = "";
425+
foreach (string op in batchOps.Split('&'))
426+
{
427+
string[] segments = op.Split('/');
428+
if (segments.Length < 3)
429+
{
430+
continue;
431+
}
432+
433+
string entry = Encoding.UTF8.GetString(Base64.UrlsafeBase64Decode(segments[2]));
434+
bucket = entry.Split(':')[0];
435+
436+
if (bucket.Length > 0)
437+
{
438+
break;
439+
}
440+
}
441+
442+
if (bucket.Length == 0)
443+
{
444+
result.Code = (int)HttpCode.INVALID_ARGUMENT;
445+
result.RefCode = (int)HttpCode.INVALID_ARGUMENT;
446+
result.Text = "{\"error\":\"bucket is Empty\"}";
447+
result.RefText = "bucket is Empty";
448+
return result;
449+
}
450+
417451
try
418452
{
419-
string scheme = this.config.UseHttps ? "https://" : "http://";
420-
string rsHost = string.Format("{0}{1}", scheme, Config.DefaultRsHost);
421-
string batchUrl = rsHost + "/batch";
453+
string batchUrl = string.Format("{0}/batch", this.config.RsHost(this.mac.AccessKey, bucket));
422454

423455
HttpResult hr = httpManager.PostForm(batchUrl, null, batchOps, auth);
424456
result.Shadow(hr);
@@ -707,7 +739,8 @@ public HttpResult SetObjectLifecycle(
707739
int toIaAfterDays = 0,
708740
int toArchiveAfterDays = 0,
709741
int toDeepArchiveAfterDays = 0,
710-
int deleteAfterDays = 0
742+
int deleteAfterDays = 0,
743+
int toArchiveIrAfterDays = 0
711744
)
712745
{
713746
return SetObjectLifecycle(
@@ -717,7 +750,8 @@ public HttpResult SetObjectLifecycle(
717750
toIaAfterDays,
718751
toArchiveAfterDays,
719752
toDeepArchiveAfterDays,
720-
deleteAfterDays
753+
deleteAfterDays,
754+
toArchiveIrAfterDays
721755
);
722756
}
723757

@@ -728,6 +762,7 @@ public HttpResult SetObjectLifecycle(
728762
/// <param name="key">文件key</param>
729763
/// <param name="cond">匹配条件,只有条件匹配才会设置成功,目前支持:hash、mime、fsize、putTime</param>
730764
/// <param name="toIaAfterDays">多少天后将文件转为低频存储,设置为 -1 表示取消已设置的转低频存储的生命周期规则,0 表示不修改转低频生命周期规则。</param>
765+
/// <param name="toArchiveIrAfterDays">多少天后将文件转为归档直读存储,设置为 -1 表示取消已设置的转归档直读存储的生命周期规则,0 表示不修改转归档直读生命周期规则。</param>
731766
/// <param name="toArchiveAfterDays">多少天后将文件转为归档存储,设置为 -1 表示取消已设置的转归档存储的生命周期规则,0 表示不修改转归档生命周期规则。</param>
732767
/// <param name="toDeepArchiveAfterDays">多少天后将文件转为深度归档存储,设置为 -1 表示取消已设置的转深度归档存储的生命周期规则,0 表示不修改转深度归档生命周期规则。</param>
733768
/// <param name="deleteAfterDays">多少天后将文件删除,设置为 -1 表示取消已设置的删除存储的生命周期规则,0 表示不修改删除存储的生命周期规则。</param>
@@ -739,15 +774,16 @@ public HttpResult SetObjectLifecycle(
739774
int toIaAfterDays = 0,
740775
int toArchiveAfterDays = 0,
741776
int toDeepArchiveAfterDays = 0,
742-
int deleteAfterDays = 0
777+
int deleteAfterDays = 0,
778+
int toArchiveIrAfterDays = 0
743779
)
744780
{
745781
HttpResult result = new HttpResult();
746782

747783
try
748784
{
749785
string updateUrl = string.Format("{0}{1}", this.config.RsHost(this.mac.AccessKey, bucket),
750-
SetObjectLifecycleOp(bucket, key, cond, toIaAfterDays, toArchiveAfterDays, toDeepArchiveAfterDays, deleteAfterDays));
786+
SetObjectLifecycleOp(bucket, key, cond, toIaAfterDays, toArchiveAfterDays, toDeepArchiveAfterDays, deleteAfterDays, toArchiveIrAfterDays));
751787
StringDictionary headers = new StringDictionary
752788
{
753789
{"Content-Type", ContentType.WWW_FORM_URLENC}
@@ -954,6 +990,7 @@ public string DeleteAfterDaysOp(string bucket, string key, int deleteAfterDays)
954990
/// <param name="key">文件key</param>
955991
/// <param name="cond">匹配条件,只有条件匹配才会设置成功,目前支持:hash、mime、fsize、putTime</param>
956992
/// <param name="toIaAfterDays">多少天后将文件转为低频存储,设置为 -1 表示取消已设置的转低频存储的生命周期规则,0 表示不修改转低频生命周期规则。</param>
993+
/// <param name="toArchiveIrAfterDays">多少天后将文件转为归档直读存储,设置为 -1 表示取消已设置的转归档直读存储的生命周期规则,0 表示不修改转归档直读生命周期规则。</param>
957994
/// <param name="toArchiveAfterDays">多少天后将文件转为归档存储,设置为 -1 表示取消已设置的转归档存储的生命周期规则,0 表示不修改转归档生命周期规则。</param>
958995
/// <param name="toDeepArchiveAfterDays">多少天后将文件转为深度归档存储,设置为 -1 表示取消已设置的转深度归档存储的生命周期规则,0 表示不修改转深度归档生命周期规则。</param>
959996
/// <param name="deleteAfterDays">多少天后将文件删除,设置为 -1 表示取消已设置的删除存储的生命周期规则,0 表示不修改删除存储的生命周期规则。</param>
@@ -965,13 +1002,14 @@ public string SetObjectLifecycleOp(
9651002
int toIaAfterDays = 0,
9661003
int toArchiveAfterDays = 0,
9671004
int toDeepArchiveAfterDays = 0,
968-
int deleteAfterDays = 0
1005+
int deleteAfterDays = 0,
1006+
int toArchiveIrAfterDays = 0
9691007
)
9701008
{
9711009
string entry = Base64.UrlSafeBase64Encode(bucket, key);
9721010
string result = string.Format(
973-
"/lifecycle/{0}/toIAAfterDays/{1}/toArchiveAfterDays/{2}/toDeepArchiveAfterDays/{3}/deleteAfterDays/{4}",
974-
entry, toIaAfterDays, toArchiveAfterDays, toDeepArchiveAfterDays, deleteAfterDays);
1011+
"/lifecycle/{0}/toIAAfterDays/{1}/toArchiveIRAfterDays/{2}/toArchiveAfterDays/{3}/toDeepArchiveAfterDays/{4}/deleteAfterDays/{5}",
1012+
entry, toIaAfterDays, toArchiveIrAfterDays, toArchiveAfterDays, toDeepArchiveAfterDays, deleteAfterDays);
9751013

9761014
if (cond != null)
9771015
{
@@ -980,7 +1018,6 @@ public string SetObjectLifecycleOp(
9801018

9811019
result += "/cond/" + Base64.UrlSafeBase64Encode(query);
9821020
}
983-
Console.WriteLine(result);
9841021

9851022
return result;
9861023
}

src/Qiniu/Storage/FileInfo.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class FileInfo
3737
/// 1 低频存储
3838
/// 2 归档存储
3939
/// 3 深度归档存储
40+
/// 4 归档直读存储
4041
/// </summary>
4142
[JsonProperty("type")]
4243
public int FileType { get; set; }
@@ -79,9 +80,17 @@ public class FileInfo
7980
/// 文件在设置过期时间后才会返回该字段。
8081
/// 历史文件过期仍会自动删除,但不会返回该字段,重新设置文件过期时间可使历史文件返回该字段。
8182
/// </summary>
82-
[JsonProperty("TransitionToIA", NullValueHandling = NullValueHandling.Ignore)]
83+
[JsonProperty("transitionToIA", NullValueHandling = NullValueHandling.Ignore)]
8384
public int TransitionToIa { get; set; }
8485

86+
/// <summary>
87+
/// 文件生命周期中转为归档直读存储的日期,Unix 时间戳格式。
88+
/// 文件在设置过期时间后才会返回该字段。
89+
/// 历史文件过期仍会自动删除,但不会返回该字段,重新设置文件过期时间可使历史文件返回该字段。
90+
/// </summary>
91+
[JsonProperty("transitionToArchiveIR", NullValueHandling = NullValueHandling.Ignore)]
92+
public int TransitionToArchiveIr { get; set; }
93+
8594
/// <summary>
8695
/// 文件生命周期中转为归档存储的日期,Unix 时间戳格式。
8796
/// 文件在设置过期时间后才会返回该字段。

src/Qiniu/Storage/ListItem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class ListItem
4242
/// 1 低频存储
4343
/// 2 归档存储
4444
/// 3 深度归档存储
45+
/// 4 归档直读存储
4546
/// </summary>
4647
[JsonProperty("type")]
4748
public int FileType { get; set; }

src/QiniuTests/Storage/BucketManagerTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ public void SetObjectLifecycleTest()
268268
20,
269269
30,
270270
40);
271+
// 40,
272+
// 15);
271273
if (ret.Code != (int)HttpCode.OK)
272274
{
273275
Assert.Fail("deleteAfterDays error: " + ret.ToString());
@@ -279,6 +281,7 @@ public void SetObjectLifecycleTest()
279281
Assert.Fail("stat error: " + statRet.ToString());
280282
}
281283
Assert.True(statRet.Result.TransitionToIa > 0);
284+
// Assert.True(statRet.Result.TransitionToArchiveIr > 0);
282285
Assert.True(statRet.Result.TransitionToArchive > 0);
283286
Assert.True(statRet.Result.TransitionToDeepArchive > 0);
284287
Assert.True(statRet.Result.Expiration > 0);
@@ -319,6 +322,8 @@ public void SetObjectLifecycleCondTest()
319322
20,
320323
30,
321324
40);
325+
// 40,
326+
// 15);
322327
if (ret.Code != (int)HttpCode.OK)
323328
{
324329
Assert.Fail("deleteAfterDays error: " + ret.ToString());

0 commit comments

Comments
 (0)