packageParser.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. var packageParser = function () {
  2. return function () {
  3. this.init = function (c) {
  4. var a = {};
  5. var c = $.extend({
  6. singleAllow: 314572800,
  7. openLargeAppUpload: 0,
  8. qndomain: "",
  9. gettoken: "/source/qiniuoss/getToken.php",
  10. getsignature: "/source/aliyunoss/signature.php",
  11. uploadurl: "/source/pack/upload/index.php",
  12. flash_swf_url: "/static/default/images/Moxie.swf",
  13. silverlight_xap_url: "/static/default/images/Moxie.xap",
  14. autoClickUploadStart: 0,
  15. mime_types: [
  16. {title: "app files", extensions: "apk"},
  17. {title: "ipa files", extensions: "ipa"},
  18. {title: "mobileconfig files", extensions: "mobileconfig"}
  19. ],
  20. postField: {},
  21. upload: "",
  22. saveCallback: function () {
  23. },
  24. parseCallback: function () {
  25. }
  26. }, c);
  27. var config = {
  28. runtimes: 'html5,flash,silverlight,html4',
  29. browse_button: "uploadstart",
  30. container: "container",
  31. flash_swf_url: c.flash_swf_url,
  32. silverlight_xap_url: c.silverlight_xap_url,
  33. unique_names: !0,
  34. multi_selection: !1,
  35. max_retries: 3,
  36. dragdrop: !0,
  37. drop_element: "container",
  38. chunk_size: "0",
  39. filters: {
  40. max_file_size: "5000mb",
  41. prevent_duplicates: !0,
  42. mime_types: c.mime_types
  43. },
  44. init: {
  45. PostInit: function (u, a) {
  46. 0 != c.autoClickUploadStart && ($("#uploadstart").click())
  47. },
  48. FilesAdded: function (u, f) {
  49. plupload.each(f, function (i) {
  50. if (i.name && i.name.indexOf('mobileconfig') > -1) {
  51. a.ext = "mobileconfig";
  52. u.start();
  53. } else {
  54. new AppInfoParser(i.getNative()).parse().then(n => {
  55. //console.log(n);
  56. a.Exename=n.CFBundleExecutable,a.icon = n.icon, a.fileSize = i.size, a.originalName = i.name, n.package ? (a.appName = "string" == typeof n.application.label ? n.application.label : n.application.label[0], a.version = n.versionName, a.versionCode = n.versionCode, a.packageName = n.package, a.ext = "apk", a.minSdkVersion = n.usesSdk.minSdkVersion) : (a.appName = n.CFBundleDisplayName ? n.CFBundleDisplayName : n.CFBundleName, a.version = n.CFBundleShortVersionString, a.versionCode = n.CFBundleVersion, a.packageName = n.CFBundleIdentifier, a.ext = "ipa", a.minSdkVersion = n.MinimumOSVersion, a.teamName = n.mobileProvision.TeamName, a.udids = "", a.teamId = n.mobileProvision.TeamIdentifier, n.mobileProvision.ProvisionsAllDevices ? a.teamType = 1 : n.mobileProvision.ProvisionedDevices ? (n.mobileProvision.Entitlements["get-task-allow"] ? a.teamType = 2 : a.teamType = 3, a.udids = n.mobileProvision.ProvisionedDevices) : a.teamType = 4), c.parseCallback(i, a), $(".upload-app-icon").find("img").attr("src", a.icon), $("#upload-app-name").text(a.appName), u.start()
  57. }).catch(e => {
  58. alert(e, function () {
  59. try {
  60. u.splice(0, 1)
  61. } catch (e) {
  62. }
  63. })
  64. })
  65. }
  66. })
  67. },
  68. BeforeUpload: function (u, f) {
  69. if (config.multipart_params) {
  70. config.multipart_params.key = f.id + '.' + a.ext;
  71. u.setOption({multipart_params: config.multipart_params});
  72. }
  73. $(".tolsize").html("<span class='process100' style='width: auto;font-size: 14px;'></span> / " + (f.size / 1024 / 1024).toFixed(2) + "MB");
  74. $("#upprocess").show();
  75. $("#upbtn").hide()
  76. },
  77. UploadProgress: function (u, f) {
  78. $(".progress-bar").css("width", f.percent + "%"), $(".process100").html(f.percent + "%"), $(".moxie-shim").hide()
  79. },
  80. FileUploaded: function (u, f, r) {
  81. s = JSON.parse(r.response) || config.multipart_params;
  82. if (!s || !s.key) {
  83. return alert('上传失败');
  84. }
  85. a.apkName = s.key, function (i) {
  86. var a = $.extend({
  87. apkName: i.apkName,
  88. originalName: i.originalName,
  89. icon: i.icon,
  90. hext: i.ext,
  91. happName: i.appName,
  92. hversion: i.version,
  93. hpackageName: i.packageName,
  94. hversionCode: i.versionCode,
  95. iAppSize: i.fileSize,
  96. TeamName: i.teamName,
  97. TeamType: i.teamType,
  98. TeamId: i.teamId,
  99. udids: i.udids,
  100. MinimumOSVersion: i.minSdkVersion,
  101. Exename: i.Exename,
  102. }, c.postField);
  103. a.remote = c.remote;
  104. if (i.apkName && i.apkName.indexOf('mobileconfig') > -1) {
  105. $.post('/source/pack/upload/index-mobileconfig.php', a, c.saveCallback, "json")
  106. } else {
  107. $.post(c.upload, a, c.saveCallback, "json")
  108. }
  109. }(a)
  110. },
  111. Error: function (u, e, f) {
  112. return alert('【' + e.code + '】 ' + e.message), !1
  113. },
  114. UploadComplete: function (u, f) {
  115. },
  116. Key: function (e, i) {
  117. return i.name
  118. }
  119. }
  120. };
  121. if (c.remote == 1) {//七牛
  122. $.get(c.gettoken, {}, function (i) {
  123. Object.assign(config, {
  124. uptoken: i,
  125. save_key: !1,
  126. domain: c.qndomain,
  127. get_new_uptoken: !1,
  128. auto_start: !1
  129. });
  130. uploader = Qiniu.uploader(config);
  131. });
  132. } else if (c.remote == 2) {//阿里
  133. $.post(c.getsignature, {}, function (ret) {
  134. if (ret.data) {
  135. Object.assign(config, {
  136. url: ret.data.domain,
  137. multipart_params: {
  138. 'key': '',
  139. 'OSSAccessKeyId': ret.data.AccessKeyId,
  140. 'policy': ret.data.policy,
  141. 'signature': ret.data.signature,
  142. 'success_action_status': '200', //让服务端返回200,不然,默认会返回204
  143. }
  144. });
  145. uploader = new plupload.Uploader(config);
  146. uploader.init();
  147. }
  148. }, 'json');
  149. } else {
  150. Object.assign(config, {
  151. url: c.uploadurl
  152. });
  153. uploader = new plupload.Uploader(config);
  154. uploader.init();
  155. }
  156. $("#changest").click(function () {
  157. $(this).hasClass("pause") ? (uploader.start(), $(this).removeClass("pause"), $(this).text("暂停上传")) : ($(this).addClass("pause"), $(this).text("恢复上传"), uploader.stop())
  158. })
  159. }
  160. }
  161. }();