sso

qiniu.min.js 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /*! qiniu-js v1.0.16-beta | Copyright 2015 by Qiniu */
  2. !function (global) {
  3. function createCookie(a, b, c) {
  4. var d = new Date;
  5. d.setTime(d.getTime() + 24 * c * 60 * 60 * 1e3);
  6. var e = "; expires=" + d.toGMTString();
  7. document.cookie = a + "=" + b + e + "; path=/"
  8. }
  9. function readCookie(a) {
  10. var b = a + "=";
  11. var c = document.cookie.split(";");
  12. for (var d = 0, e = c.length; e > d; d++) {
  13. var f = c[d];
  14. while (" " === f.charAt(0)) f = f.substring(1, f.length);
  15. if (0 === f.indexOf(b)) return f.substring(b.length, f.length)
  16. }
  17. return null
  18. }
  19. window.localStorage || (window.localStorage = {
  20. setItem: function (a, b) {
  21. createCookie(a, b, 30)
  22. }, getItem: function (a) {
  23. return readCookie(a)
  24. }, removeItem: function (a) {
  25. createCookie(a, "", -1)
  26. }
  27. });
  28. function QiniuJsSDK() {
  29. var that = this;
  30. this.detectIEVersion = function () {
  31. var a = 4, b = document.createElement("div"), c = b.getElementsByTagName("i");
  32. while (b.innerHTML = "<!--[if gt IE " + a + "]><i></i><![endif]-->", c[0]) a++;
  33. return a > 4 ? a : !1
  34. };
  35. var logger = {MUTE: 0, FATA: 1, ERROR: 2, WARN: 3, INFO: 4, DEBUG: 5, TRACE: 6, level: 0};
  36. function log(a, b) {
  37. var c = "[qiniu-js-sdk][" + a + "]";
  38. var d = c;
  39. for (var e = 0; e < b.length; e++) d += "string" == typeof b[e] ? " " + b[e] : " " + that.stringifyJSON(b[e]);
  40. that.detectIEVersion() ? console.log(d) : (b.unshift(c), console.log.apply(console, b)), document.getElementById("qiniu-js-sdk-log") && (document.getElementById("qiniu-js-sdk-log").innerHTML += "<p>" + d + "</p>")
  41. }
  42. function makeLogFunc(a) {
  43. var b = a.toLowerCase();
  44. logger[b] = function () {
  45. if (window.console && window.console.log && logger.level >= logger[a]) {
  46. var c = Array.prototype.slice.call(arguments);
  47. log(b, c)
  48. }
  49. }
  50. }
  51. for (var property in logger) logger.hasOwnProperty(property) && "number" == typeof logger[property] && !logger.hasOwnProperty(property.toLowerCase()) && makeLogFunc(property);
  52. var qiniuUploadUrl;
  53. qiniuUploadUrl = "https:" === window.location.protocol ? "https://up.qbox.me" : "http://upload.qiniu.com";
  54. var qiniuUploadUrls = ["http://upload.qiniu.com", "http://up.qiniu.com"];
  55. var changeUrlTimes = 0;
  56. this.resetUploadUrl = function () {
  57. if ("https:" === window.location.protocol) qiniuUploadUrl = "https://up.qbox.me"; else {
  58. var a = changeUrlTimes % qiniuUploadUrls.length;
  59. qiniuUploadUrl = qiniuUploadUrls[a], changeUrlTimes++
  60. }
  61. logger.debug("resetUploadUrl: " + qiniuUploadUrl)
  62. }, this.resetUploadUrl(), this.isImage = function (a) {
  63. return a = a.split(/[?#]/)[0], /\.(png|jpg|jpeg|gif|bmp)$/i.test(a)
  64. }, this.getFileExtension = function (a) {
  65. var b = a.split(".");
  66. var c;
  67. return c = 1 === b.length || "" === b[0] && 2 === b.length ? "" : b.pop().toLowerCase()
  68. }, this.utf8_encode = function (a) {
  69. if (null === a || "undefined" == typeof a) return "";
  70. var b = a + "";
  71. var c = "", d, e, f = 0;
  72. d = e = 0, f = b.length;
  73. for (var g = 0; f > g; g++) {
  74. var h = b.charCodeAt(g);
  75. var i = null;
  76. if (128 > h) e++; else if (h > 127 && 2048 > h) i = String.fromCharCode(h >> 6 | 192, 63 & h | 128); else if (63488 & h ^ !0) i = String.fromCharCode(h >> 12 | 224, h >> 6 & 63 | 128, 63 & h | 128); else {
  77. if (64512 & h ^ !0) throw new RangeError("Unmatched trail surrogate at " + g);
  78. var j = b.charCodeAt(++g);
  79. if (64512 & j ^ !0) throw new RangeError("Unmatched lead surrogate at " + (g - 1));
  80. h = ((1023 & h) << 10) + (1023 & j) + 65536, i = String.fromCharCode(h >> 18 | 240, h >> 12 & 63 | 128, h >> 6 & 63 | 128, 63 & h | 128)
  81. }
  82. null !== i && (e > d && (c += b.slice(d, e)), c += i, d = e = g + 1)
  83. }
  84. return e > d && (c += b.slice(d, f)), c
  85. }, this.base64_encode = function (a) {
  86. var b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  87. var c, d, e, f, g, h, i, j, k = 0, l = 0, m = "", n = [];
  88. if (!a) return a;
  89. a = this.utf8_encode(a + "");
  90. do c = a.charCodeAt(k++), d = a.charCodeAt(k++), e = a.charCodeAt(k++), j = c << 16 | d << 8 | e, f = j >> 18 & 63, g = j >> 12 & 63, h = j >> 6 & 63, i = 63 & j, n[l++] = b.charAt(f) + b.charAt(g) + b.charAt(h) + b.charAt(i); while (k < a.length);
  91. switch (m = n.join(""), a.length % 3) {
  92. case 1:
  93. m = m.slice(0, -2) + "==";
  94. break;
  95. case 2:
  96. m = m.slice(0, -1) + "="
  97. }
  98. return m
  99. }, this.URLSafeBase64Encode = function (a) {
  100. return a = this.base64_encode(a), a.replace(/\//g, "_").replace(/\+/g, "-")
  101. }, this.createAjax = function (a) {
  102. var b = {};
  103. return b = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP")
  104. }, this.parseJSON = function (data) {
  105. if (window.JSON && window.JSON.parse) return window.JSON.parse(data);
  106. var rx_dangerous = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  107. var text = String(data);
  108. return rx_dangerous.lastIndex = 0, rx_dangerous.test(text) && (text = text.replace(rx_dangerous, function (a) {
  109. return "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
  110. })), eval("(" + text + ")")
  111. }, this.stringifyJSON = function (a) {
  112. if (window.JSON && window.JSON.stringify) return window.JSON.stringify(a);
  113. switch (typeof a) {
  114. case"string":
  115. return '"' + a.replace(/(["\\])/g, "\\$1") + '"';
  116. case"array":
  117. return "[" + a.map(that.stringifyJSON).join(",") + "]";
  118. case"object":
  119. if (a instanceof Array) {
  120. var b = [];
  121. var c = a.length;
  122. for (var d = 0; c > d; d++) b.push(that.stringifyJSON(a[d]));
  123. return "[" + b.join(",") + "]"
  124. }
  125. if (null === a) return "null";
  126. var e = [];
  127. for (var f in a) a.hasOwnProperty(f) && e.push(that.stringifyJSON(f) + ":" + that.stringifyJSON(a[f]));
  128. return "{" + e.join(",") + "}";
  129. case"number":
  130. return a;
  131. case!1:
  132. return a;
  133. case"boolean":
  134. return a
  135. }
  136. }, this.trim = function (a) {
  137. return null === a ? "" : a.replace(/^\s+|\s+$/g, "")
  138. }, this.uploader = function (a) {
  139. var b = function () {
  140. var b = that.detectIEVersion();
  141. var c, d, e;
  142. var f = "Safari" === mOxie.Env.browser && mOxie.Env.version <= 5 && "Windows" === mOxie.Env.os && "7" === mOxie.Env.osVersion || "Safari" === mOxie.Env.browser && "iOS" === mOxie.Env.os && "7" === mOxie.Env.osVersion;
  143. b && 9 > b && a.chunk_size && a.runtimes.indexOf("flash") >= 0 ? a.chunk_size = 0 : f ? a.chunk_size = 0 : (c = 20, d = 4 << c, e = plupload.parseSize(a.chunk_size), e > d && (a.chunk_size = d))
  144. };
  145. var c = function (b) {
  146. if (a.uptoken) return void(that.token = a.uptoken);
  147. {
  148. if (!a.uptoken_url) return a.uptoken_func ? (logger.debug("get uptoken from uptoken_func"), that.token = a.uptoken_func(b), void logger.debug("get new uptoken: ", that.token)) : void logger.error("one of [uptoken, uptoken_url, uptoken_func] settings in options is required!");
  149. logger.debug("get uptoken from: ", that.uptoken_url);
  150. var c = that.createAjax();
  151. if (c.open("GET", that.uptoken_url, !1), c.setRequestHeader("If-Modified-Since", "0"), c.send(), 200 === c.status) {
  152. var d = that.parseJSON(c.responseText);
  153. that.token = d.uptoken, logger.debug("get new uptoken: ", d.uptoken)
  154. } else logger.error("get uptoken error: ", c.responseText)
  155. }
  156. };
  157. var d = function (b, c, d) {
  158. var e = "", f = !1;
  159. if (!a.save_key) if (f = b.getOption && b.getOption("unique_names"), f = f || b.settings && b.settings.unique_names) {
  160. var g = that.getFileExtension(c.name);
  161. e = g ? c.id + "." + g : c.id
  162. } else e = "function" == typeof d ? d(b, c) : c.name;
  163. return e
  164. };
  165. if (a.log_level && (logger.level = a.log_level), !a.domain) throw"domain setting in options is required!";
  166. if (!a.browse_button) throw"browse_button setting in options is required!";
  167. if (!a.uptoken && !a.uptoken_url && !a.uptoken_func) throw"one of [uptoken, uptoken_url, uptoken_func] settings in options is required!";
  168. logger.debug("init uploader start"), logger.debug("environment: ", mOxie.Env), logger.debug("userAgent: ", navigator.userAgent);
  169. var e = {};
  170. var f = a.init && a.init.Error;
  171. var g = a.init && a.init.FileUploaded;
  172. a.init.Error = function () {
  173. }, a.init.FileUploaded = function () {
  174. }, that.uptoken_url = a.uptoken_url, that.token = "", that.key_handler = "function" == typeof a.init.Key ? a.init.Key : "", this.domain = a.domain;
  175. var h = "";
  176. var i = {isResumeUpload: !1, resumeFilesize: 0, startTime: "", currentTime: ""};
  177. b(), logger.debug("invoke reset_chunk_size()"), logger.debug("op.chunk_size: ", a.chunk_size), plupload.extend(e, a, {
  178. url: qiniuUploadUrl,
  179. multipart_params: {token: ""}
  180. }), logger.debug("option: ", e);
  181. var j = new plupload.Uploader(e);
  182. logger.debug("new plupload.Uploader(option)"), j.bind("Init", function (b, d) {
  183. logger.debug("Init event activated"), a.get_new_uptoken || c(null)
  184. }), logger.debug("bind Init event"), j.bind("FilesAdded", function (a, b) {
  185. logger.debug("FilesAdded event activated");
  186. var c = a.getOption && a.getOption("auto_start");
  187. c = c || a.settings && a.settings.auto_start, logger.debug("auto_start: ", c), logger.debug("files: ", b);
  188. var d = function () {
  189. return "ios" === mOxie.Env.OS.toLowerCase() ? !0 : !1
  190. };
  191. if (d()) for (var e = 0; e < b.length; e++) {
  192. var f = b[e];
  193. var g = that.getFileExtension(f.name);
  194. f.name = f.id + "." + g
  195. }
  196. c && setTimeout(function () {
  197. a.start(), logger.debug("invoke up.start()")
  198. }, 0), a.refresh()
  199. }), logger.debug("bind FilesAdded event"), j.bind("BeforeUpload", function (b, e) {
  200. logger.debug("BeforeUpload event activated"), e.speed = e.speed || 0, h = "", a.get_new_uptoken && c(e);
  201. var f = function (b, c, e) {
  202. i.startTime = (new Date).getTime();
  203. var f;
  204. f = a.save_key ? {token: that.token} : {
  205. key: d(b, c, e),
  206. token: that.token
  207. }, logger.debug("directUpload multipart_params_obj: ", f);
  208. var h = a.x_vars;
  209. if (void 0 !== h && "object" == typeof h) for (var j in h) h.hasOwnProperty(j) && ("function" == typeof h[j] ? f["x:" + j] = h[j](b, c) : "object" != typeof h[j] && (f["x:" + j] = h[j]));
  210. b.setOption({
  211. url: qiniuUploadUrl,
  212. multipart: !0,
  213. chunk_size: g() ? a.max_file_size : void 0,
  214. multipart_params: f
  215. })
  216. };
  217. var g = function () {
  218. var a = navigator.userAgent.toLowerCase();
  219. return (a.match(/MicroMessenger/i) || "QQBrowser" === mOxie.Env.browser || a.match(/V1_AND_SQ/i)) && "android" === mOxie.Env.OS.toLowerCase() ? !0 : !1
  220. };
  221. var k = b.getOption && b.getOption("chunk_size");
  222. if (k = k || b.settings && b.settings.chunk_size, logger.debug("uploader.runtime: ", j.runtime), logger.debug("chunk_size: ", k), "html5" !== j.runtime && "flash" !== j.runtime || !k) logger.debug("directUpload because uploader.runtime !== 'html5' || uploader.runtime !== 'flash' || !chunk_size"), f(b, e, that.key_handler); else if (e.size < k || g()) logger.debug("directUpload because file.size < chunk_size || is_android_weixin_or_qq()"), f(b, e, that.key_handler); else {
  223. var l = localStorage.getItem(e.name);
  224. var m = k;
  225. if (l) {
  226. l = that.parseJSON(l);
  227. var n = (new Date).getTime();
  228. var o = l.time || 0;
  229. var p = 864e5;
  230. p > n - o && 100 !== l.percent && e.size === l.total ? (e.percent = l.percent, e.loaded = l.offset, h = l.ctx, i.isResumeUpload = !0, i.resumeFilesize = l.offset, l.offset + m > e.size && (m = e.size - l.offset)) : localStorage.removeItem(e.name)
  231. }
  232. i.startTime = (new Date).getTime(), b.setOption({
  233. url: qiniuUploadUrl + "/mkblk/" + m,
  234. multipart: !1,
  235. chunk_size: k,
  236. required_features: "chunks",
  237. headers: {Authorization: "UpToken " + that.token},
  238. multipart_params: {}
  239. })
  240. }
  241. }), logger.debug("bind BeforeUpload event"), j.bind("UploadProgress", function (a, b) {
  242. logger.trace("UploadProgress event activated"), i.currentTime = (new Date).getTime();
  243. var c = i.currentTime - i.startTime;
  244. var d = b.loaded || 0;
  245. i.isResumeUpload && (d = b.loaded - i.resumeFilesize), b.speed = (d / c * 1e3).toFixed(0) || 0
  246. }), logger.debug("bind UploadProgress event"), j.bind("ChunkUploaded", function (a, b, c) {
  247. logger.debug("ChunkUploaded event activated"), logger.debug("file: ", b), logger.debug("info: ", c);
  248. var d = that.parseJSON(c.response);
  249. logger.debug("res: ", d), h = h ? h + "," + d.ctx : d.ctx;
  250. var e = c.total - c.offset;
  251. var f = a.getOption && a.getOption("chunk_size");
  252. f = f || a.settings && a.settings.chunk_size, f > e && (a.setOption({url: qiniuUploadUrl + "/mkblk/" + e}), logger.debug("up.setOption url: ", qiniuUploadUrl + "/mkblk/" + e)), localStorage.setItem(b.name, that.stringifyJSON({
  253. ctx: h,
  254. percent: b.percent,
  255. total: c.total,
  256. offset: c.offset,
  257. time: (new Date).getTime()
  258. }))
  259. }), logger.debug("bind ChunkUploaded event");
  260. var k = qiniuUploadUrls.length;
  261. var l = function (a) {
  262. return k-- > 0 ? (setTimeout(function () {
  263. that.resetUploadUrl(), a.status = plupload.QUEUED, j.stop(), j.start()
  264. }, 0), !0) : (k = qiniuUploadUrls.length, !1)
  265. };
  266. return j.bind("Error", function (a) {
  267. return function (b, c) {
  268. logger.error("Error event activated"), logger.error("err: ", c);
  269. var d = "";
  270. var e = c.file;
  271. if (e) {
  272. switch (c.code) {
  273. case plupload.FAILED:
  274. d = "\u4e0a\u4f20\u5931\u8d25\u3002\u8bf7\u7a0d\u540e\u518d\u8bd5\u3002";
  275. break;
  276. case plupload.FILE_SIZE_ERROR:
  277. var f = b.getOption && b.getOption("max_file_size");
  278. f = f || b.settings && b.settings.max_file_size, d = "\u6d4f\u89c8\u5668\u6700\u5927\u53ef\u4e0a\u4f20" + f + "\u3002\u66f4\u5927\u6587\u4ef6\u8bf7\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u3002";
  279. break;
  280. case plupload.FILE_EXTENSION_ERROR:
  281. d = "\u6587\u4ef6\u9a8c\u8bc1\u5931\u8d25\u3002\u8bf7\u7a0d\u540e\u91cd\u8bd5\u3002";
  282. break;
  283. case plupload.HTTP_ERROR:
  284. if ("" === c.response) {
  285. if (d = c.message || "\u672a\u77e5\u7f51\u7edc\u9519\u8bef\u3002", !l(e)) return;
  286. break
  287. }
  288. var g = that.parseJSON(c.response);
  289. var h = g.error;
  290. switch (c.status) {
  291. case 400:
  292. d = "\u8bf7\u6c42\u62a5\u6587\u683c\u5f0f\u9519\u8bef\u3002";
  293. break;
  294. case 401:
  295. d = "\u5ba2\u6237\u7aef\u8ba4\u8bc1\u6388\u6743\u5931\u8d25\u3002\u8bf7\u91cd\u8bd5\u6216\u63d0\u4ea4\u53cd\u9988\u3002";
  296. break;
  297. case 405:
  298. d = "\u5ba2\u6237\u7aef\u8bf7\u6c42\u9519\u8bef\u3002\u8bf7\u91cd\u8bd5\u6216\u63d0\u4ea4\u53cd\u9988\u3002";
  299. break;
  300. case 579:
  301. d = "\u8d44\u6e90\u4e0a\u4f20\u6210\u529f\uff0c\u4f46\u56de\u8c03\u5931\u8d25\u3002";
  302. break;
  303. case 599:
  304. if (d = "\u7f51\u7edc\u8fde\u63a5\u5f02\u5e38\u3002\u8bf7\u91cd\u8bd5\u6216\u63d0\u4ea4\u53cd\u9988\u3002", !l(e)) return;
  305. break;
  306. case 614:
  307. d = "\u6587\u4ef6\u5df2\u5b58\u5728\u3002";
  308. try {
  309. g = that.parseJSON(g.error), h = g.error || "file exists"
  310. } catch (i) {
  311. h = g.error || "file exists"
  312. }
  313. break;
  314. case 631:
  315. d = "\u6307\u5b9a\u7a7a\u95f4\u4e0d\u5b58\u5728\u3002";
  316. break;
  317. case 701:
  318. d = "\u4e0a\u4f20\u6570\u636e\u5757\u6821\u9a8c\u51fa\u9519\u3002\u8bf7\u91cd\u8bd5\u6216\u63d0\u4ea4\u53cd\u9988\u3002";
  319. break;
  320. default:
  321. if (d = "\u672a\u77e5\u9519\u8bef\u3002", !l(e)) return
  322. }
  323. d = d + "(" + c.status + "\uff1a" + h + ")";
  324. break;
  325. case plupload.SECURITY_ERROR:
  326. d = "\u5b89\u5168\u914d\u7f6e\u9519\u8bef\u3002\u8bf7\u8054\u7cfb\u7f51\u7ad9\u7ba1\u7406\u5458\u3002";
  327. break;
  328. case plupload.GENERIC_ERROR:
  329. d = "\u4e0a\u4f20\u5931\u8d25\u3002\u8bf7\u7a0d\u540e\u518d\u8bd5\u3002";
  330. break;
  331. case plupload.IO_ERROR:
  332. d = "\u4e0a\u4f20\u5931\u8d25\u3002\u8bf7\u7a0d\u540e\u518d\u8bd5\u3002";
  333. break;
  334. case plupload.INIT_ERROR:
  335. d = "\u7f51\u7ad9\u914d\u7f6e\u9519\u8bef\u3002\u8bf7\u8054\u7cfb\u7f51\u7ad9\u7ba1\u7406\u5458\u3002", j.destroy();
  336. break;
  337. default:
  338. if (d = c.message + c.details, !l(e)) return
  339. }
  340. a && a(b, c, d)
  341. }
  342. b.refresh()
  343. }
  344. }(f)), logger.debug("bind Error event"), j.bind("FileUploaded", function (b) {
  345. return function (c, e, f) {
  346. logger.debug("FileUploaded event activated"), logger.debug("file: ", e), logger.debug("info: ", f);
  347. var g = function (c, d, e) {
  348. if (a.downtoken_url) {
  349. var f = that.createAjax();
  350. f.open("POST", a.downtoken_url, !0), f.setRequestHeader("Content-type", "application/x-www-form-urlencoded"), f.onreadystatechange = function () {
  351. if (4 === f.readyState) if (200 === f.status) {
  352. var a;
  353. try {
  354. a = that.parseJSON(f.responseText)
  355. } catch (g) {
  356. throw"invalid json format"
  357. }
  358. var h = {};
  359. plupload.extend(h, that.parseJSON(e), a), b && b(c, d, that.stringifyJSON(h))
  360. } else j.trigger("Error", {
  361. status: f.status,
  362. response: f.responseText,
  363. file: d,
  364. code: plupload.HTTP_ERROR
  365. })
  366. }, f.send("key=" + that.parseJSON(e).key + "&domain=" + a.domain)
  367. } else b && b(c, d, e)
  368. };
  369. var i = that.parseJSON(f.response);
  370. if (h = h ? h : i.ctx, logger.debug("ctx: ", h), h) {
  371. var k = "";
  372. logger.debug("save_key: ", a.save_key), a.save_key || (k = d(c, e, that.key_handler), k = k ? "/key/" + that.URLSafeBase64Encode(k) : "");
  373. var l = "/fname/" + that.URLSafeBase64Encode(e.name);
  374. logger.debug("op.x_vars: ", a.x_vars);
  375. var m = a.x_vars, n = "", o = "";
  376. if (void 0 !== m && "object" == typeof m) for (var p in m) m.hasOwnProperty(p) && ("function" == typeof m[p] ? n = that.URLSafeBase64Encode(m[p](c, e)) : "object" != typeof m[p] && (n = that.URLSafeBase64Encode(m[p])), o += "/x:" + p + "/" + n);
  377. var q = qiniuUploadUrl + "/mkfile/" + e.size + k + l + o;
  378. var r = that.detectIEVersion();
  379. var s;
  380. r && 9 >= r ? (s = new mOxie.XMLHttpRequest, mOxie.Env.swf_url = a.flash_swf_url) : s = that.createAjax(), s.open("POST", q, !0), s.setRequestHeader("Content-Type", "text/plain;charset=UTF-8"), s.setRequestHeader("Authorization", "UpToken " + that.token);
  381. var t = function () {
  382. if (logger.debug("ajax.readyState: ", s.readyState), 4 === s.readyState) {
  383. localStorage.removeItem(e.name);
  384. var a;
  385. 200 === s.status ? (a = s.responseText, logger.debug("mkfile is success: ", a), g(c, e, a)) : (a = {
  386. status: s.status,
  387. response: s.responseText,
  388. file: e,
  389. code: -200
  390. }, logger.debug("mkfile is error: ", a), j.trigger("Error", a))
  391. }
  392. };
  393. r && 9 >= r ? s.bind("readystatechange", t) : s.onreadystatechange = t, s.send(h), logger.debug("mkfile: ", q)
  394. } else g(c, e, f.response)
  395. }
  396. }(g)), logger.debug("bind FileUploaded event"), j.init(), logger.debug("invoke uploader.init()"), logger.debug("init uploader end"), j
  397. }, this.getUrl = function (a) {
  398. if (!a) return !1;
  399. a = encodeURI(a);
  400. var b = this.domain;
  401. return "/" !== b.slice(b.length - 1) && (b += "/"), b + a
  402. }, this.imageView2 = function (a, b) {
  403. var c = a.mode || "", d = a.w || "", e = a.h || "", f = a.q || "", g = a.format || "";
  404. if (!c) return !1;
  405. if (!d && !e) return !1;
  406. var h = "imageView2/" + c;
  407. return h += d ? "/w/" + d : "", h += e ? "/h/" + e : "", h += f ? "/q/" + f : "", h += g ? "/format/" + g : "", b && (h = this.getUrl(b) + "?" + h), h
  408. }, this.imageMogr2 = function (a, b) {
  409. var c = a["auto-orient"] || "", d = a.thumbnail || "", e = a.strip || "", f = a.gravity || "",
  410. g = a.crop || "", h = a.quality || "", i = a.rotate || "", j = a.format || "", k = a.blur || "";
  411. var l = "imageMogr2";
  412. return l += c ? "/auto-orient" : "", l += d ? "/thumbnail/" + d : "", l += e ? "/strip" : "", l += f ? "/gravity/" + f : "", l += h ? "/quality/" + h : "", l += g ? "/crop/" + g : "", l += i ? "/rotate/" + i : "", l += j ? "/format/" + j : "", l += k ? "/blur/" + k : "", b && (l = this.getUrl(b) + "?" + l), l
  413. }, this.watermark = function (a, b) {
  414. var c = a.mode;
  415. if (!c) return !1;
  416. var d = "watermark/" + c;
  417. if (1 === c) {
  418. var e = a.image || "";
  419. if (!e) return !1;
  420. d += e ? "/image/" + this.URLSafeBase64Encode(e) : ""
  421. } else {
  422. if (2 !== c) return !1;
  423. var f = a.text ? a.text : "", g = a.font ? a.font : "", h = a.fontsize ? a.fontsize : "",
  424. i = a.fill ? a.fill : "";
  425. if (!f) return !1;
  426. d += f ? "/text/" + this.URLSafeBase64Encode(f) : "", d += g ? "/font/" + this.URLSafeBase64Encode(g) : "", d += h ? "/fontsize/" + h : "", d += i ? "/fill/" + this.URLSafeBase64Encode(i) : ""
  427. }
  428. var j = a.dissolve || "", k = a.gravity || "", l = a.dx || "", m = a.dy || "";
  429. return d += j ? "/dissolve/" + j : "", d += k ? "/gravity/" + k : "", d += l ? "/dx/" + l : "", d += m ? "/dy/" + m : "", b && (d = this.getUrl(b) + "?" + d), d
  430. }, this.imageInfo = function (a) {
  431. if (!a) return !1;
  432. var b = this.getUrl(a) + "?imageInfo";
  433. var c = this.createAjax();
  434. var d;
  435. var e = this;
  436. return c.open("GET", b, !1), c.onreadystatechange = function () {
  437. 4 === c.readyState && 200 === c.status && (d = e.parseJSON(c.responseText))
  438. }, c.send(), d
  439. }, this.exif = function (a) {
  440. if (!a) return !1;
  441. var b = this.getUrl(a) + "?exif";
  442. var c = this.createAjax();
  443. var d;
  444. var e = this;
  445. return c.open("GET", b, !1), c.onreadystatechange = function () {
  446. 4 === c.readyState && 200 === c.status && (d = e.parseJSON(c.responseText))
  447. }, c.send(), d
  448. }, this.get = function (a, b) {
  449. return b && a ? "exif" === a ? this.exif(b) : "imageInfo" === a ? this.imageInfo(b) : !1 : !1
  450. }, this.pipeline = function (a, b) {
  451. var c = "[object Array]" === Object.prototype.toString.call(a);
  452. var d, e, f = "";
  453. if (c) {
  454. for (var g = 0, h = a.length; h > g; g++) {
  455. if (d = a[g], !d.fop) return !1;
  456. switch (d.fop) {
  457. case"watermark":
  458. f += this.watermark(d) + "|";
  459. break;
  460. case"imageView2":
  461. f += this.imageView2(d) + "|";
  462. break;
  463. case"imageMogr2":
  464. f += this.imageMogr2(d) + "|";
  465. break;
  466. default:
  467. e = !0
  468. }
  469. if (e) return !1
  470. }
  471. if (b) {
  472. f = this.getUrl(b) + "?" + f;
  473. var i = f.length;
  474. "|" === f.slice(i - 1) && (f = f.slice(0, i - 1))
  475. }
  476. return f
  477. }
  478. return !1
  479. }
  480. }
  481. var Qiniu = new QiniuJsSDK;
  482. global.Qiniu = Qiniu, global.QiniuJsSDK = QiniuJsSDK
  483. }(window);