Skip to content

Commit 4b4f671

Browse files
committed
Merge pull request #85 from liangchaoboy/addForce
add force
2 parents 09e6376 + d8a6cc5 commit 4b4f671

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

Qiniu/RS/RSClient.cs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ OPS [(int)op],
8080
return Call(url);
8181
}
8282

83+
84+
/// <summary>
85+
/// </summary>
86+
/// <param name="op"></param>
87+
/// <param name="pair"></param>
88+
/// <param name="force"></param>
89+
/// <returns></returns>
90+
private CallRet op2(FileHandle op, EntryPathPair pair, bool force)
91+
{
92+
93+
string url = string.Format("{0}/{1}/{2}/{3}/force/{4}",
94+
Config.RS_HOST,
95+
OPS[(int)op],
96+
Base64URLSafe.Encode(pair.URISrc),
97+
Base64URLSafe.Encode(pair.URIDest), force);
98+
return Call(url);
99+
}
100+
83101
private CallRet opFetch(FileHandle op, string fromUrl, EntryPath entryPath)
84102
{
85103
string url = string.Format("{0}/{1}/{2}/to/{3}",
@@ -126,6 +144,21 @@ public CallRet Move (EntryPathPair pathPair)
126144
return op2 (FileHandle.MOVE, pathPair);
127145
}
128146

147+
148+
/// <summary>
149+
/// 移动文件
150+
/// </summary>
151+
/// <param name="bucketSrc">文件所属的源空间名称</param>
152+
/// <param name="keySrc">源key</param>
153+
/// <param name="bucketDest">目标空间名称</param>
154+
/// <param name="keyDest">目标key</param>
155+
/// <param name="force">强制覆盖</param>
156+
/// <returns>见<see cref="CallRet">CallRet</see></returns>
157+
public CallRet Move(EntryPathPair pathPair, bool force)
158+
{
159+
return op2(FileHandle.MOVE, pathPair, force);
160+
}
161+
129162
/// <summary>
130163
/// 复制
131164
/// </summary>
@@ -139,6 +172,22 @@ public CallRet Copy (EntryPathPair pathPair)
139172
return op2 (FileHandle.COPY, pathPair);
140173
}
141174

175+
/// <summary>
176+
/// 复制
177+
/// </summary>
178+
/// <param name="bucketSrc">文件所属的空间名称</param>
179+
/// <param name="keySrc">需要复制的文件key</param>
180+
/// <param name="bucketDest">复制至目标空间</param>
181+
/// <param name="keyDest">复制的副本文件key</param>
182+
/// <param name="force">复制是否强制覆盖目标文件</param>
183+
/// <returns>见<see cref="CallRet">CallRet</see></returns>
184+
public CallRet Copy(EntryPathPair pathPair, bool force)
185+
{
186+
187+
return op2(FileHandle.COPY, pathPair, force);
188+
189+
}
190+
142191
/// <summary>
143192
/// 抓取资源
144193
/// </summary>
@@ -195,6 +244,33 @@ OPS [(int)op],
195244
return sb.Append (litem).ToString ();
196245
}
197246

247+
/// <summary>
248+
///
249+
/// </summary>
250+
/// <param name="op"></param>
251+
/// <param name="keys"></param>
252+
/// <param name="force"></param>
253+
/// <returns></returns>
254+
private string getBatchOp_2(FileHandle op, EntryPathPair[] keys, bool force)
255+
{
256+
if (keys.Length < 1)
257+
return string.Empty;
258+
StringBuilder sb = new StringBuilder();
259+
for (int i = 0; i < keys.Length - 1; i++)
260+
{
261+
string item = string.Format("op=/{0}/{1}/{2}/force/{3}/&",
262+
OPS[(int)op],
263+
Base64URLSafe.Encode(keys[i].URISrc),
264+
Base64URLSafe.Encode(keys[i].URIDest), force);
265+
sb.Append(item);
266+
}
267+
string litem = string.Format("op=/{0}/{1}/{2}/force/{3}", OPS[(int)op],
268+
Base64URLSafe.Encode(keys[keys.Length - 1].URISrc),
269+
Base64URLSafe.Encode(keys[keys.Length - 1].URIDest), force);
270+
return sb.Append(litem).ToString();
271+
}
272+
273+
198274
private CallRet batch(string requestBody)
199275
{
200276
return CallWithBinary(Conf.Config.RS_HOST + "/batch", "application/x-www-form-urlencoded", StreamEx.ToStream(requestBody), requestBody.Length);
@@ -241,6 +317,18 @@ public CallRet BatchMove (EntryPathPair[] entryPathPairs)
241317
return batch (requestBody);
242318
}
243319

320+
/// <summary>
321+
/// batch
322+
/// </summary>
323+
/// <param name="entryPathPairs"></param>
324+
/// <param name="force"></param>
325+
/// <returns></returns>
326+
public CallRet BatchMove(EntryPathPair[] entryPathPairs, bool force)
327+
{
328+
string requestBody = getBatchOp_2(FileHandle.MOVE, entryPathPairs, force);
329+
return batch(requestBody);
330+
}
331+
244332
/// <summary>
245333
///
246334
/// </summary>
@@ -252,6 +340,18 @@ public CallRet BatchCopy (EntryPathPair[] entryPathPari)
252340
return batch (requestBody);
253341
}
254342

343+
/// <summary>
344+
/// 批量复制
345+
/// </summary>
346+
/// <param name="entryPathPari"></param>
347+
/// <param name="force"></param>
348+
/// <returns></returns>
349+
public CallRet BatchCopy(EntryPathPair[] entryPathPari, bool force)
350+
{
351+
string requestBody = getBatchOp_2(FileHandle.COPY, entryPathPari, force);
352+
return batch(requestBody);
353+
}
354+
255355
/// <summary>
256356
/// 批量删除
257357
/// </summary>

0 commit comments

Comments
 (0)