Skip to content

Commit da6aaac

Browse files
committed
Merge pull request #68 from qiniu/develop
Release v6.1.5
2 parents d1cfc54 + de1b7d3 commit da6aaac

File tree

3 files changed

+136
-21
lines changed

3 files changed

+136
-21
lines changed

Qiniu/Conf/Config.cs

+31-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Qiniu.Conf
55
{
66
public class Config
77
{
8-
public static string VERSION = "6.1.4";
8+
public static string VERSION = "6.1.5";
99

1010
public static string USER_AGENT = getUa();
1111
#region 帐户信息
@@ -26,7 +26,7 @@ public class Config
2626
/// <summary>
2727
/// 七牛资源上传服务器地址.
2828
/// </summary>
29-
public static string UP_HOST = "http://upload.qiniu.com";
29+
public static string UP_HOST = "http://up.qiniu.com";
3030
/// <summary>
3131
/// 七牛资源列表服务器地址.
3232
/// </summary>
@@ -44,15 +44,36 @@ public class Config
4444
/// <summary>
4545
/// 初始化七牛帐户、请求地址等信息,不应在客户端调用。
4646
/// </summary>
47-
public static void Init()
47+
public static void Init()
4848
{
49-
USER_AGENT = System.Configuration.ConfigurationManager.AppSettings["USER_AGENT"];
50-
ACCESS_KEY = System.Configuration.ConfigurationManager.AppSettings["ACCESS_KEY"];
51-
SECRET_KEY = System.Configuration.ConfigurationManager.AppSettings["SECRET_KEY"];
52-
RS_HOST = System.Configuration.ConfigurationManager.AppSettings["RS_HOST"];
53-
UP_HOST = System.Configuration.ConfigurationManager.AppSettings["UP_HOST"];
54-
RSF_HOST = System.Configuration.ConfigurationManager.AppSettings["RSF_HOST"];
55-
PREFETCH_HOST = System.Configuration.ConfigurationManager.AppSettings["PREFETCH_HOST"];
49+
if (System.Configuration.ConfigurationManager.AppSettings["USER_AGENT"] != null)
50+
{
51+
USER_AGENT = System.Configuration.ConfigurationManager.AppSettings["USER_AGENT"];
52+
}
53+
if (System.Configuration.ConfigurationManager.AppSettings["ACCESS_KEY"] != null)
54+
{
55+
ACCESS_KEY = System.Configuration.ConfigurationManager.AppSettings["ACCESS_KEY"];
56+
}
57+
if (System.Configuration.ConfigurationManager.AppSettings["SECRET_KEY"] != null)
58+
{
59+
SECRET_KEY = System.Configuration.ConfigurationManager.AppSettings["SECRET_KEY"];
60+
}
61+
if (System.Configuration.ConfigurationManager.AppSettings["RS_HOST"] != null)
62+
{
63+
RS_HOST = System.Configuration.ConfigurationManager.AppSettings["RS_HOST"];
64+
}
65+
if (System.Configuration.ConfigurationManager.AppSettings["UP_HOST"] != null)
66+
{
67+
UP_HOST = System.Configuration.ConfigurationManager.AppSettings["UP_HOST"];
68+
}
69+
if (System.Configuration.ConfigurationManager.AppSettings["RSF_HOST"] != null)
70+
{
71+
RSF_HOST = System.Configuration.ConfigurationManager.AppSettings["RSF_HOST"];
72+
}
73+
if (System.Configuration.ConfigurationManager.AppSettings["PREFETCH_HOST"] != null)
74+
{
75+
PREFETCH_HOST = System.Configuration.ConfigurationManager.AppSettings["PREFETCH_HOST"];
76+
}
5677
}
5778
private static string getUa()
5879
{

Qiniu/PFOP/Mkzip.cs

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using Qiniu.Auth;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using Qiniu.RS;
7+
using Qiniu.RPC;
8+
using Qiniu.Conf;
9+
using Qiniu.Util;
10+
using Newtonsoft.Json;
11+
12+
namespace Qiniu.PFOP
13+
{
14+
public class Mkzip
15+
{
16+
17+
/// <summary>
18+
/// 多文件压缩存储为用户提供了批量文件的压缩存储功能
19+
/// POST /pfop/ HTTP/1.1
20+
/// Host: api.qiniu.com
21+
/// Content-Type: application/x-www-form-urlencoded
22+
/// Authorization: <AccessToken>
23+
/// bucket = <bucket>
24+
/// mkzip/<mode>
25+
/// /url/<Base64EncodedURL>
26+
/// /alias/<Base64EncodedAlias>
27+
/// /url/<Base64EncodedURL>
28+
/// ...
29+
/// </summary>
30+
public String doMkzip(String bucket, String existKey, String newFileName, String[] urls, string pipeline)
31+
{
32+
if (bucket == null || string.IsNullOrEmpty(existKey) || string.IsNullOrEmpty(newFileName) || urls.Length < 0 || pipeline == null)
33+
{
34+
throw new Exception("params error");
35+
}
36+
String entryURI = bucket + ":" + newFileName;
37+
String urlString = "";
38+
for (int i = 0; i < urls.Length; i++)
39+
{
40+
String urlEntry = "/url/" + Qiniu.Util.Base64URLSafe.ToBase64URLSafe(urls[i]);
41+
urlString += urlEntry;
42+
}
43+
String fop = System.Web.HttpUtility.UrlEncode("mkzip/1" + urlString + "|saveas/" + Qiniu.Util.Base64URLSafe.ToBase64URLSafe(entryURI));
44+
45+
string body = string.Format("bucket={0}&key={1}&fops={2}&pipeline={3}", bucket, existKey, fop, pipeline);
46+
47+
System.Text.Encoding curEncoding = System.Text.Encoding.UTF8;
48+
49+
QiniuAuthClient authClient = new QiniuAuthClient();
50+
CallRet ret = authClient.CallWithBinary(Config.API_HOST + "/pfop/", "application/x-www-form-urlencoded", StreamEx.ToStream(body), body.Length);
51+
if (ret.OK)
52+
{
53+
try
54+
{
55+
PersistentId pid = JsonConvert.DeserializeObject<PersistentId>(ret.Response);
56+
return pid.persistentId;
57+
}
58+
catch (Exception e)
59+
{
60+
throw e;
61+
}
62+
}
63+
else
64+
{
65+
throw new Exception(ret.Response);
66+
}
67+
}
68+
}
69+
}

Qiniu/RS/RSClient.cs

+36-11
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,23 @@ public enum FileHandle
2929
/// <summary>
3030
/// 删除delete
3131
/// </summary>
32-
DELETE
32+
DELETE,
33+
/// <summary>
34+
/// 抓取资源fetch
35+
/// </summary>
36+
FETCH
3337
}
3438

3539
/// <summary>
36-
/// 资源存储客户端,提供对文件的查看(stat),移动(move),复制(copy),删除(delete)操作
40+
/// 资源存储客户端,提供对文件的查看(stat),移动(move),复制(copy),删除(delete), 抓取资源(fetch) 操作
3741
/// 以及与这些操作对应的批量操作
3842
/// </summary>
39-
public class RSClient :QiniuAuthClient
43+
public class RSClient : QiniuAuthClient
4044
{
41-
private static string[] OPS = new string[] { "stat", "move", "copy", "delete" };
45+
private static string[] OPS = new string[] { "stat", "move", "copy", "delete", "fetch" };
4246

43-
public RSClient (Mac mac=null)
44-
: base(mac)
47+
public RSClient(Mac mac = null)
48+
: base(mac)
4549
{
4650
}
4751

@@ -73,6 +77,16 @@ private CallRet op2 (FileHandle op, EntryPathPair pair)
7377
OPS [(int)op],
7478
Base64URLSafe.Encode (pair.URISrc),
7579
Base64URLSafe.Encode (pair.URIDest));
80+
return Call(url);
81+
}
82+
83+
private CallRet opFetch(FileHandle op, string fromUrl, EntryPath entryPath)
84+
{
85+
string url = string.Format("{0}/{1}/{2}/to/{3}",
86+
Config.RS_HOST,
87+
OPS[(int)op],
88+
Base64URLSafe.Encode(fromUrl),
89+
Base64URLSafe.Encode(entryPath.URI));
7690
return Call (url);
7791
}
7892

@@ -125,6 +139,17 @@ public CallRet Copy (EntryPathPair pathPair)
125139
return op2 (FileHandle.COPY, pathPair);
126140
}
127141

142+
/// <summary>
143+
/// 抓取资源
144+
/// </summary>
145+
/// <param name="fromUrl">需要抓取的文件URL</param>
146+
/// <param name="entryPath">目标entryPath</param>
147+
/// <returns>见<see cref="CallRet">CallRet</see></returns>
148+
public CallRet Fetch(string fromUrl, EntryPath entryPath)
149+
{
150+
return opFetch(FileHandle.FETCH, fromUrl, entryPath);
151+
}
152+
128153
/// <summary>
129154
/// 获取一元批操作http request Body
130155
/// </summary>
@@ -168,11 +193,11 @@ OPS [(int)op],
168193
Base64URLSafe.Encode (keys [keys.Length - 1].URISrc),
169194
Base64URLSafe.Encode (keys [keys.Length - 1].URIDest));
170195
return sb.Append (litem).ToString ();
171-
}
172-
173-
private CallRet batch(string requestBody)
174-
{
175-
return CallWithBinary(Conf.Config.RS_HOST + "/batch", "application/x-www-form-urlencoded", StreamEx.ToStream(requestBody), requestBody.Length);
196+
}
197+
198+
private CallRet batch(string requestBody)
199+
{
200+
return CallWithBinary(Conf.Config.RS_HOST + "/batch", "application/x-www-form-urlencoded", StreamEx.ToStream(requestBody), requestBody.Length);
176201
}
177202

178203
/// <summary>

0 commit comments

Comments
 (0)