Skip to content

Commit 87e27b0

Browse files
committed
extend file info and add ChangeStatus
1 parent db03ad2 commit 87e27b0

File tree

5 files changed

+206
-8
lines changed

5 files changed

+206
-8
lines changed

src/Qiniu/Storage/BatchInfo.cs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,70 @@ public class BatchData
5555
public long PutTime { get; set; }
5656

5757
/// <summary>
58-
/// 文件存储类型
58+
/// 文件存储类型。
59+
/// 0 标准存储
60+
/// 1 低频存储
61+
/// 2 归档存储
62+
/// 3 深度归档存储
5963
/// </summary>
6064
[JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)]
6165
public int FileType { get; set; }
66+
67+
/// <summary>
68+
/// 文件解冻状态。
69+
/// 1 解冻中
70+
/// 2 已解冻
71+
/// 0 如果是归档/深度归档,但处于冻结,后端不返回此字段,因此默认值为 0。请勿依赖 0 判断冻结状态
72+
/// </summary>
73+
[JsonProperty("restoreStatus", NullValueHandling = NullValueHandling.Ignore)]
74+
public int RestoreStatus { get; set; }
75+
76+
/// <summary>
77+
/// 文件的存储状态。
78+
/// 0 启用,非禁用后端不返回此字段,因此默认值为 0。
79+
/// 1 禁用
80+
/// </summary>
81+
[JsonProperty("status", NullValueHandling = NullValueHandling.Ignore)]
82+
public int Status { get; set; }
83+
84+
/// <summary>
85+
/// 文件的 md5 值。
86+
/// 服务端不确保一定返回此字段,详见:
87+
/// https://developer.qiniu.com/kodo/1308/stat#:~:text=%E8%AF%A5%E5%AD%97%E6%AE%B5%E3%80%82-,md5,-%E5%90%A6
88+
/// </summary>
89+
[JsonProperty("md5", NullValueHandling = NullValueHandling.Ignore)]
90+
public string Md5 { get; set; }
91+
92+
/// <summary>
93+
/// 文件过期删除日期,Unix 时间戳格式。
94+
/// 文件在设置过期时间后才会返回该字段。
95+
/// 历史文件过期仍会自动删除,但不会返回该字段,重新设置文件过期时间可使历史文件返回该字段。
96+
/// </summary>
97+
[JsonProperty("expiration", NullValueHandling = NullValueHandling.Ignore)]
98+
public int Expiration { get; set; }
99+
100+
/// <summary>
101+
/// 文件生命周期中转为低频存储的日期,Unix 时间戳格式。
102+
/// 文件在设置过期时间后才会返回该字段。
103+
/// 历史文件过期仍会自动删除,但不会返回该字段,重新设置文件过期时间可使历史文件返回该字段。
104+
/// </summary>
105+
[JsonProperty("TransitionToIA", NullValueHandling = NullValueHandling.Ignore)]
106+
public int TransitionToIa { get; set; }
107+
108+
/// <summary>
109+
/// 文件生命周期中转为归档存储的日期,Unix 时间戳格式。
110+
/// 文件在设置过期时间后才会返回该字段。
111+
/// 历史文件过期仍会自动删除,但不会返回该字段,重新设置文件过期时间可使历史文件返回该字段。
112+
/// </summary>
113+
[JsonProperty("transitionToARCHIVE", NullValueHandling = NullValueHandling.Ignore)]
114+
public int TransitionToArchive { get; set; }
115+
116+
/// <summary>
117+
/// 文件生命周期中转为深度归档存储的日期,Unix 时间戳格式。
118+
/// 文件在设置过期时间后才会返回该字段。
119+
/// 历史文件过期仍会自动删除,但不会返回该字段,重新设置文件过期时间可使历史文件返回该字段。
120+
/// </summary>
121+
[JsonProperty("transitionToDeepArchive", NullValueHandling = NullValueHandling.Ignore)]
122+
public int TransitionToDeepArchive { get; set; }
62123
}
63124
}

src/Qiniu/Storage/BucketManager.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,38 @@ public HttpResult ChangeMime(string bucket, string key, string mimeType)
302302
return result;
303303
}
304304

305+
public HttpResult ChangeStatus(string bucket, string key, int status)
306+
{
307+
HttpResult result = new HttpResult();
308+
309+
try
310+
{
311+
string chStatusUrl = string.Format("{0}{1}", this.config.RsHost(this.mac.AccessKey, bucket),
312+
ChangeStatusOp(bucket, key, status));
313+
314+
result = httpManager.Post(chStatusUrl, null, auth);
315+
}
316+
catch (QiniuException ex)
317+
{
318+
StringBuilder sb = new StringBuilder();
319+
sb.AppendFormat("[{0}] [chstatus] Error: ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff"));
320+
Exception e = ex;
321+
while (e != null)
322+
{
323+
sb.Append(e.Message + " ");
324+
e = e.InnerException;
325+
}
326+
sb.AppendLine();
327+
328+
result.Code = ex.HttpResult.Code;
329+
result.RefCode = ex.HttpResult.Code;
330+
result.Text = ex.HttpResult.Text;
331+
result.RefText += sb.ToString();
332+
}
333+
334+
return result;
335+
}
336+
305337
/// <summary>
306338
/// 修改文件存储类型
307339
/// </summary>
@@ -839,6 +871,12 @@ public string ChangeMimeOp(string bucket, string key, string mimeType)
839871
Base64.UrlSafeBase64Encode(mimeType));
840872
}
841873

874+
public string ChangeStatusOp(string bucket, string key, int status)
875+
{
876+
return string.Format("/chstatus/{0}/status/{1}", Base64.UrlSafeBase64Encode(bucket, key),
877+
status);
878+
}
879+
842880
/// <summary>
843881
/// 生成chtype操作字符串
844882
/// </summary>

src/Qiniu/Storage/FileInfo.cs

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Newtonsoft.Json;
2+
23
namespace Qiniu.Storage
34
{
45
/// <summary>
@@ -31,10 +32,70 @@ public class FileInfo
3132
public long PutTime { set; get; }
3233

3334
/// <summary>
34-
/// 文件存储类型
35+
/// 文件存储类型。
36+
/// 0 标准存储
37+
/// 1 低频存储
38+
/// 2 归档存储
39+
/// 3 深度归档存储
3540
/// </summary>
3641
[JsonProperty("type")]
3742
public int FileType { get; set; }
3843

44+
/// <summary>
45+
/// 文件解冻状态。
46+
/// 1 解冻中
47+
/// 2 已解冻
48+
/// 0 如果是归档/深度归档,但处于冻结,后端不返回此字段,因此默认值为 0。请勿依赖 0 判断冻结状态
49+
/// </summary>
50+
[JsonProperty("restoreStatus", NullValueHandling = NullValueHandling.Ignore)]
51+
public int RestoreStatus { get; set; }
52+
53+
/// <summary>
54+
/// 文件的存储状态。
55+
/// 0 启用,非禁用后端不返回此字段,因此默认值为 0。
56+
/// 1 禁用
57+
/// </summary>
58+
[JsonProperty("status", NullValueHandling = NullValueHandling.Ignore)]
59+
public int Status { get; set; }
60+
61+
/// <summary>
62+
/// 文件的 md5 值。
63+
/// 服务端不确保一定返回此字段,详见:
64+
/// https://developer.qiniu.com/kodo/1308/stat#:~:text=%E8%AF%A5%E5%AD%97%E6%AE%B5%E3%80%82-,md5,-%E5%90%A6
65+
/// </summary>
66+
[JsonProperty("md5", NullValueHandling = NullValueHandling.Ignore)]
67+
public string Md5 { get; set; }
68+
69+
/// <summary>
70+
/// 文件过期删除日期,Unix 时间戳格式。
71+
/// 文件在设置过期时间后才会返回该字段。
72+
/// 历史文件过期仍会自动删除,但不会返回该字段,重新设置文件过期时间可使历史文件返回该字段。
73+
/// </summary>
74+
[JsonProperty("expiration", NullValueHandling = NullValueHandling.Ignore)]
75+
public int Expiration { get; set; }
76+
77+
/// <summary>
78+
/// 文件生命周期中转为低频存储的日期,Unix 时间戳格式。
79+
/// 文件在设置过期时间后才会返回该字段。
80+
/// 历史文件过期仍会自动删除,但不会返回该字段,重新设置文件过期时间可使历史文件返回该字段。
81+
/// </summary>
82+
[JsonProperty("TransitionToIA", NullValueHandling = NullValueHandling.Ignore)]
83+
public int TransitionToIa { get; set; }
84+
85+
/// <summary>
86+
/// 文件生命周期中转为归档存储的日期,Unix 时间戳格式。
87+
/// 文件在设置过期时间后才会返回该字段。
88+
/// 历史文件过期仍会自动删除,但不会返回该字段,重新设置文件过期时间可使历史文件返回该字段。
89+
/// </summary>
90+
[JsonProperty("transitionToARCHIVE", NullValueHandling = NullValueHandling.Ignore)]
91+
public int TransitionToArchive { get; set; }
92+
93+
/// <summary>
94+
/// 文件生命周期中转为深度归档存储的日期,Unix 时间戳格式。
95+
/// 文件在设置过期时间后才会返回该字段。
96+
/// 历史文件过期仍会自动删除,但不会返回该字段,重新设置文件过期时间可使历史文件返回该字段。
97+
/// </summary>
98+
[JsonProperty("transitionToDeepArchive", NullValueHandling = NullValueHandling.Ignore)]
99+
public int TransitionToDeepArchive { get; set; }
39100
}
40-
}
101+
}

src/Qiniu/Storage/ListItem.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
namespace Qiniu.Storage
33
{
44
/// <summary>
5-
/// 文件描述(stat操作返回消息中包含的有效内容)
6-
/// 与StatInfo一致
5+
/// 文件描述
76
/// </summary>
87
public class ListItem
98
{
@@ -39,14 +38,35 @@ public class ListItem
3938

4039
/// <summary>
4140
/// 文件存储类型
41+
/// 0 标准存储
42+
/// 1 低频存储
43+
/// 2 归档存储
44+
/// 3 深度归档存储
4245
/// </summary>
4346
[JsonProperty("type")]
4447
public int FileType { get; set; }
4548

4649
/// <summary>
47-
/// EndUser字段
50+
/// 资源内容的唯一属主标识
51+
/// 详见上传策略:https://developer.qiniu.com/kodo/1206/put-policy
4852
/// </summary>
49-
[JsonProperty("endUser")]
53+
[JsonProperty("endUser", NullValueHandling = NullValueHandling.Ignore)]
5054
public string EndUser { get; set; }
55+
56+
/// <summary>
57+
/// 文件的存储状态
58+
/// 0 启用
59+
/// 1 禁用
60+
/// </summary>
61+
[JsonProperty("status")]
62+
public int Status { get; set; }
63+
64+
/// <summary>
65+
/// 文件的 md5 值
66+
/// 服务端不确保一定返回此字段,详见:
67+
/// https://developer.qiniu.com/kodo/1284/list#:~:text=%E3%80%82%0A%0A%E7%B1%BB%E5%9E%8B%EF%BC%9A%E6%95%B0%E5%AD%97-,md5,-%E5%90%A6
68+
/// </summary>
69+
[JsonProperty("md5", NullValueHandling = NullValueHandling.Ignore)]
70+
public string Md5 { get; set; }
5171
}
5272
}

src/QiniuTests/Storage/BucketManagerTests.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public void StatTest()
2626
Console.WriteLine(statRet.Result.Hash);
2727
Console.WriteLine(statRet.Result.MimeType);
2828
Console.WriteLine(statRet.Result.Fsize);
29-
Console.WriteLine(statRet.Result.MimeType);
3029
Console.WriteLine(statRet.Result.FileType);
3130
}
3231

@@ -100,6 +99,25 @@ public void ChangeMimeTest()
10099
Console.WriteLine(ret.ToString());
101100
}
102101

102+
[Test]
103+
public void ChangeStatusTest()
104+
{
105+
Config config = new Config();
106+
config.Zone = Zone.ZONE_CN_East;
107+
Mac mac = new Mac(AccessKey, SecretKey);
108+
BucketManager bucketManager = new BucketManager(mac, config);
109+
HttpResult ret = bucketManager.ChangeStatus(Bucket, "qiniu.png", 1);
110+
if (ret.Code != (int)HttpCode.OK)
111+
{
112+
Assert.Fail("change status error: " + ret.ToString());
113+
}
114+
ret = bucketManager.ChangeStatus(Bucket, "qiniu.png", 0);
115+
if (ret.Code != (int)HttpCode.OK)
116+
{
117+
Assert.Fail("change status error: " + ret.ToString());
118+
}
119+
}
120+
103121
[Test]
104122
public void ChangeTypeTest()
105123
{

0 commit comments

Comments
 (0)