Commit 5e3d1d66c6c7d48fb82890eea4c836180a833b3d

Authored by 杨泽宇
1 parent c4709a42

正式环境 测试数据 含加密

dist/audio.html deleted 100644 → 0
1   -<!DOCTYPE html>
2   -<html>
3   -
4   -<head>
5   - <meta charset="utf-8">
6   - <meta name="viewport" content="width=device-width,initial-scale=1.0">
7   - <title>CNLive Audio Panel</title>
8   - <meta http-equiv="Expires" CONTENT="0">
9   - <meta http-equiv="Cache-Control" CONTENT="no-cache">
10   - <meta http-equiv="Pragma" CONTENT="no-cache">
11   - <link rel="shortcut icon" href="/cms.ico" />
12   - <link rel="bookmark" href="/cms.ico" />
13   - <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/element-plus@1.1.0-beta.12/theme-chalk/index.css">
14   -</head>
15   -
16   -<body id="body" style="margin: 0; padding: 0">
17   - <div id="audioPage" class="page-container">
18   - <el-card>
19   - <template #header>
20   - <div class="card-header">
21   - <!-- <h3>歌曲征集</h3> -->
22   - <span style="font-size: 24px; font-weight: Semibold; color: #666666;">歌曲征集</span>
23   - <span style="font-size: 14px; color: #999999;"> / 带*号为必填项</span>
24   - </div>
25   - </template>
26   - <div>
27   - <el-form ref="songs" :model="form" label-width="120px" :rules="rules" style="display: flex; flex-wrap: wrap;" >
28   - <el-form-item label="类型" style="width: 100%" prop="channelId">
29   - <el-radio-group v-model="form.channelId" @change="handleChange">
30   - <el-radio :label="1278">热歌榜</el-radio>
31   - <el-radio :label="1279">优秀作词榜</el-radio>
32   - <el-radio :label="1280">优秀作曲榜</el-radio>
33   - <el-radio :label="1281">其他</el-radio>
34   - </el-radio-group>
35   - </el-form-item>
36   - <el-form-item label="歌曲名字" style="width: 50%" prop="songName">
37   - <el-input v-model.trim="form.songName" :maxlength="100" :minlength="1" placeholder="请输入歌曲名字"></el-input>
38   - </el-form-item>
39   - <el-form-item label="歌手" style="width: 50%" prop="singer">
40   - <el-input v-model.trim="form.singer" :maxlength="15" placeholder="请输入歌手名字"></el-input>
41   - </el-form-item>
42   - <el-form-item label="作词" style="width: 50%" prop="lyricist">
43   - <el-input v-model.trim="form.lyricist" :maxlength="15" placeholder="请输入作词人名字"></el-input>
44   - </el-form-item>
45   - <el-form-item label="作曲" style="width: 50%;" prop="songwriter">
46   - <el-input v-model.trim="form.songwriter" :maxlength="15" placeholder="请输入作曲人名字"></el-input>
47   - </el-form-item>
48   - <el-form-item label="编曲" style="width: 50%" prop="redact">
49   - <el-input v-model.trim="form.redact" :maxlength="15" placeholder="请输入编曲人名字"></el-input>
50   - </el-form-item>
51   - <el-form-item label="混音" style="width: 50%" prop="mixing">
52   - <el-input v-model.trim="form.mixing" :maxlength="15" placeholder="请输入混音人名字"></el-input>
53   - </el-form-item>
54   - <el-form-item label="歌词" style="width: 100%" prop="lyric">
55   - <el-input v-model="form.lyric" maxlength="2500" show-word-limit type="textarea" :rows="10" placeholder="请输入歌词"></el-input>
56   - </el-form-item>
57   - <el-form-item label="手机号码" style="width: 50%" prop="phone">
58   - <el-input v-model.trim="form.phone" :maxlength="11" placeholder="请输入手机号码"></el-input>
59   - </el-form-item>
60   - <el-form-item label="联系人姓名" style="width: 50%" prop="name">
61   - <el-input v-model.trim="form.name" :maxlength="50" placeholder="请输入联系人姓名"></el-input>
62   - </el-form-item>
63   - <el-form-item label="音频" style="width: 100%" prop="audioFile">
64   - <el-upload class="upload-demo" :action="uploadUrl" :auto-upload="false" :file-list="fileList" accept=".mp3"
65   - @change="getMp3" :on-exceed="exceed" :before-remove="handleRemove" :disabled="btnDisabled" :show-file-list="false">
66   - <el-button size="small" type="primary" :disabled="btnDisabled">选择文件</el-button>
67   - <span style="color: red; margin-left: 10px;">{{msgText}}</span>
68   - </el-upload>
69   - </el-form-item>
70   - <el-divider></el-divider>
71   - <el-form-item style="width: 50%; text-align: left;">
72   - <span style="color: #4A90E2; font-size: 20px">{{form.audioFile?.name}} </span>
73   - <span style="color: #4A90E2; font-size: 20px" v-if="percent > 0 && percent < 100"> 已上传{{Math.ceil(percent)}}%,请耐心等待……</span>
74   - <span style="color: #4A90E2; font-size: 20px" v-if="percent == 100"> 上传完成</span>
75   - </el-form-item>
76   - <el-form-item style="width: 50%; text-align: right;">
77   - <el-button @click="reset" v-if="form.channelId == 1279">取消</el-button>
78   - <el-button @click="reset" v-else :disabled="!form.audioFile || submitDisabled">取消</el-button>
79   -
80   - <!-- <el-button type="danger" @click="submit('songs')" v-if="form.channelId == 1279">确定上传</el-button>
81   - <el-button type="danger" @click="submit('songs')" v-if="form.channelId == 1279">确定上传</el-button>
82   - <el-button type="danger" @click="submit('songs')" v-else>确定上传</el-button> -->
83   - <!-- <el-button type="danger" @click="submit('songs')" v-else :disabled="!form.audioId">确定上传</el-button> -->
84   -
85   - <el-button type="danger" @click="submit('songs')" v-if="form.channelId == 1279">确定上传</el-button>
86   - <el-button type="danger" @click="submit('songs')" v-else :disabled="!form.audioFile || submitDisabled">确定上传</el-button>
87   - </el-form-item>
88   - </el-form>
89   - </div>
90   - </el-card>
91   - </div>
92   - <script src="https://cdn.jsdelivr.net/npm/vue@3.2.11/dist/vue.global.js"></script>
93   - <script src="https://cdn.jsdelivr.net/npm/element-plus@1.1.0-beta.12"></script>
94   - <script src="https://cdn.jsdelivr.net/npm/axios@0.17.1/dist/axios.min.js"></script>
95   - <script src="https://cdn.jsdelivr.net/npm/qiniu-js@2.5.5/dist/qiniu.min.js"></script>
96   -<script src="/bundle.js"></script></body>
97   -
98   -</html>
99 0 \ No newline at end of file
package-lock.json
... ... @@ -614,6 +614,12 @@
614 614 "resolved": "https://mirrors.huaweicloud.com/repository/npm/bytes/-/bytes-3.1.0.tgz",
615 615 "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==",
616 616 "dev": true
  617 + },
  618 + "qs": {
  619 + "version": "6.7.0",
  620 + "resolved": "https://mirrors.huaweicloud.com/repository/npm/qs/-/qs-6.7.0.tgz",
  621 + "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==",
  622 + "dev": true
617 623 }
618 624 }
619 625 },
... ... @@ -876,7 +882,6 @@
876 882 "version": "1.0.2",
877 883 "resolved": "https://mirrors.huaweicloud.com/repository/npm/call-bind/-/call-bind-1.0.2.tgz",
878 884 "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
879   - "dev": true,
880 885 "requires": {
881 886 "function-bind": "^1.1.1",
882 887 "get-intrinsic": "^1.0.2"
... ... @@ -920,6 +925,12 @@
920 925 }
921 926 }
922 927 },
  928 + "charenc": {
  929 + "version": "0.0.2",
  930 + "resolved": "https://mirrors.huaweicloud.com/repository/npm/charenc/-/charenc-0.0.2.tgz",
  931 + "integrity": "sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc=",
  932 + "dev": true
  933 + },
923 934 "chokidar": {
924 935 "version": "3.5.2",
925 936 "resolved": "https://mirrors.huaweicloud.com/repository/npm/chokidar/-/chokidar-3.5.2.tgz",
... ... @@ -1295,6 +1306,12 @@
1295 1306 }
1296 1307 }
1297 1308 },
  1309 + "crypt": {
  1310 + "version": "0.0.2",
  1311 + "resolved": "https://mirrors.huaweicloud.com/repository/npm/crypt/-/crypt-0.0.2.tgz",
  1312 + "integrity": "sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs=",
  1313 + "dev": true
  1314 + },
1298 1315 "crypto-browserify": {
1299 1316 "version": "3.12.0",
1300 1317 "resolved": "https://mirrors.huaweicloud.com/repository/npm/crypto-browserify/-/crypto-browserify-3.12.0.tgz",
... ... @@ -1940,6 +1957,12 @@
1940 1957 "resolved": "https://mirrors.huaweicloud.com/repository/npm/array-flatten/-/array-flatten-1.1.1.tgz",
1941 1958 "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=",
1942 1959 "dev": true
  1960 + },
  1961 + "qs": {
  1962 + "version": "6.7.0",
  1963 + "resolved": "https://mirrors.huaweicloud.com/repository/npm/qs/-/qs-6.7.0.tgz",
  1964 + "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==",
  1965 + "dev": true
1943 1966 }
1944 1967 }
1945 1968 },
... ... @@ -2207,8 +2230,7 @@
2207 2230 "function-bind": {
2208 2231 "version": "1.1.1",
2209 2232 "resolved": "https://mirrors.huaweicloud.com/repository/npm/function-bind/-/function-bind-1.1.1.tgz",
2210   - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
2211   - "dev": true
  2233 + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
2212 2234 },
2213 2235 "get-caller-file": {
2214 2236 "version": "2.0.5",
... ... @@ -2220,7 +2242,6 @@
2220 2242 "version": "1.1.1",
2221 2243 "resolved": "https://mirrors.huaweicloud.com/repository/npm/get-intrinsic/-/get-intrinsic-1.1.1.tgz",
2222 2244 "integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==",
2223   - "dev": true,
2224 2245 "requires": {
2225 2246 "function-bind": "^1.1.1",
2226 2247 "has": "^1.0.3",
... ... @@ -2348,7 +2369,6 @@
2348 2369 "version": "1.0.3",
2349 2370 "resolved": "https://mirrors.huaweicloud.com/repository/npm/has/-/has-1.0.3.tgz",
2350 2371 "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
2351   - "dev": true,
2352 2372 "requires": {
2353 2373 "function-bind": "^1.1.1"
2354 2374 }
... ... @@ -2368,8 +2388,7 @@
2368 2388 "has-symbols": {
2369 2389 "version": "1.0.2",
2370 2390 "resolved": "https://mirrors.huaweicloud.com/repository/npm/has-symbols/-/has-symbols-1.0.2.tgz",
2371   - "integrity": "sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw==",
2372   - "dev": true
  2391 + "integrity": "sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw=="
2373 2392 },
2374 2393 "has-tostringtag": {
2375 2394 "version": "1.0.0",
... ... @@ -3525,8 +3544,7 @@
3525 3544 "object-inspect": {
3526 3545 "version": "1.11.0",
3527 3546 "resolved": "https://mirrors.huaweicloud.com/repository/npm/object-inspect/-/object-inspect-1.11.0.tgz",
3528   - "integrity": "sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg==",
3529   - "dev": true
  3547 + "integrity": "sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg=="
3530 3548 },
3531 3549 "object-is": {
3532 3550 "version": "1.1.5",
... ... @@ -4045,10 +4063,12 @@
4045 4063 "dev": true
4046 4064 },
4047 4065 "qs": {
4048   - "version": "6.7.0",
4049   - "resolved": "https://mirrors.huaweicloud.com/repository/npm/qs/-/qs-6.7.0.tgz",
4050   - "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==",
4051   - "dev": true
  4066 + "version": "6.10.1",
  4067 + "resolved": "https://mirrors.huaweicloud.com/repository/npm/qs/-/qs-6.10.1.tgz",
  4068 + "integrity": "sha512-M528Hph6wsSVOBiYUnGf+K/7w0hNshs/duGsNXPUCLH5XAqjEtiPGwNONLV0tBH8NoGb0mvD5JubnUTrujKDTg==",
  4069 + "requires": {
  4070 + "side-channel": "^1.0.4"
  4071 + }
4052 4072 },
4053 4073 "querystring": {
4054 4074 "version": "0.2.0",
... ... @@ -4495,6 +4515,16 @@
4495 4515 "safe-buffer": "^5.0.1"
4496 4516 }
4497 4517 },
  4518 + "sha1": {
  4519 + "version": "1.1.1",
  4520 + "resolved": "https://mirrors.huaweicloud.com/repository/npm/sha1/-/sha1-1.1.1.tgz",
  4521 + "integrity": "sha1-rdqnqTFo85PxnrKxUJFhjicA+Eg=",
  4522 + "dev": true,
  4523 + "requires": {
  4524 + "charenc": ">= 0.0.1",
  4525 + "crypt": ">= 0.0.1"
  4526 + }
  4527 + },
4498 4528 "shebang-command": {
4499 4529 "version": "1.2.0",
4500 4530 "resolved": "https://mirrors.huaweicloud.com/repository/npm/shebang-command/-/shebang-command-1.2.0.tgz",
... ... @@ -4514,7 +4544,6 @@
4514 4544 "version": "1.0.4",
4515 4545 "resolved": "https://mirrors.huaweicloud.com/repository/npm/side-channel/-/side-channel-1.0.4.tgz",
4516 4546 "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==",
4517   - "dev": true,
4518 4547 "requires": {
4519 4548 "call-bind": "^1.0.0",
4520 4549 "get-intrinsic": "^1.0.2",
... ...
package.json
... ... @@ -19,6 +19,10 @@
19 19 "style-loader": "^2.0.0",
20 20 "webpack": "^4.42.1",
21 21 "webpack-cli": "^3.3.11",
22   - "webpack-dev-server": "^3.10.3"
  22 + "webpack-dev-server": "^3.10.3",
  23 + "sha1": "^1.1.1"
  24 + },
  25 + "dependencies": {
  26 + "qs": "^6.10.1"
23 27 }
24 28 }
... ...
src/html/index.html
... ... @@ -77,11 +77,6 @@
77 77 <el-button @click="reset" v-if="form.channelId == 1279">取消</el-button>
78 78 <el-button @click="reset" v-else :disabled="!form.audioFile || submitDisabled">取消</el-button>
79 79  
80   - <!-- <el-button type="danger" @click="submit('songs')" v-if="form.channelId == 1279">确定上传</el-button>
81   - <el-button type="danger" @click="submit('songs')" v-if="form.channelId == 1279">确定上传</el-button>
82   - <el-button type="danger" @click="submit('songs')" v-else>确定上传</el-button> -->
83   - <!-- <el-button type="danger" @click="submit('songs')" v-else :disabled="!form.audioId">确定上传</el-button> -->
84   -
85 80 <el-button type="danger" @click="submit('songs')" v-if="form.channelId == 1279">确定上传</el-button>
86 81 <el-button type="danger" @click="submit('songs')" v-else :disabled="!form.audioFile || submitDisabled">确定上传</el-button>
87 82 </el-form-item>
... ...
src/js/audios.js
... ... @@ -2,16 +2,6 @@ import * as all from &quot;./config&quot;;
2 2 // require('./../css/test.css')
3 3 // Init Vue
4 4 const Audio = {
5   - created() {
6   - all
7   - .request({
8   - url: all.urls.base + all.urls.token + "?spId=1423",
9   - method: "get",
10   - })
11   - .then((res) => {
12   - this.token = res.data;
13   - });
14   - },
15 5 data() {
16 6 return {
17 7 form: {
... ... @@ -33,7 +23,7 @@ const Audio = {
33 23 {
34 24 required: true,
35 25 trigger: "change",
36   - message: "请填写歌曲名字"
  26 + message: "请填写歌曲名字",
37 27 },
38 28 ],
39 29 name: [
... ... @@ -84,9 +74,11 @@ const Audio = {
84 74 this.rules.audioId[0].required = true;
85 75 }
86 76 },
  77 + // 文件数量超上限响应
87 78 exceed(e, d) {
88 79 this.$message.error("只能上传一个文件");
89 80 },
  81 + // 表单重置按钮响应
90 82 reset() {
91 83 for (let i in this.form) {
92 84 this.form[i] = null;
... ... @@ -95,6 +87,7 @@ const Audio = {
95 87 this.btnDisabled = false;
96 88 this.submitDisabled = false;
97 89 },
  90 + // 文件移除响应,暂未启用
98 91 handleRemove(file, list) {
99 92 if (this.percent < 100) {
100 93 this.$message({
... ... @@ -108,6 +101,7 @@ const Audio = {
108 101 this.percent = 0;
109 102 }
110 103 },
  104 + // 校验Md5
111 105 initMd5(fileObj) {
112 106 return new Promise((resolve, reject) => {
113 107 const fileName = fileObj.name.split(".")[0];
... ... @@ -126,6 +120,7 @@ const Audio = {
126 120 }
127 121 });
128 122 },
  123 + // 确认提交按钮响应,上传视频到七牛
129 124 submit(formName) {
130 125 this.$refs[formName].validate((valid) => {
131 126 if (valid) {
... ... @@ -148,21 +143,17 @@ const Audio = {
148 143  
149 144 multipleCategory: 100005,
150 145 tag: "test",
151   - synopsis: "test",
152   - mmsType: 0,
153   - videoType: 11003,
154   - videoType: 0,
155   - masterId: 10494974,
  146 + ts: this.getTs(),
  147 + timestamp: this.getTimeStamp(),
  148 + masterId: all.secretUrls.masterIdDev,
156 149 };
157 150 const fileInitObj = {
158 151 gfmt: this.form.audioFile.raw.name.split(".").reverse().shift(),
159 152 fileSize: this.form.audioFile.raw.size,
160   - videoType: 11003,
161   - ptpwVal: 0,
162   - archiveStatus: 0,
  153 + ts: this.getTs(),
  154 + timestamp: this.getTimeStamp(),
163 155 multipleCategory: 100005,
164   - uploadLine: 2,
165   - masterId: 10494974,
  156 + masterId: all.secretUrls.masterIdDev,
166 157 };
167 158 const fileWholeObj = {
168 159 file: this.form.audioFile.raw,
... ... @@ -173,14 +164,6 @@ const Audio = {
173 164 subscription: null,
174 165 };
175 166  
176   - if (this.token == null) {
177   - this.$message({
178   - type: "error",
179   - message: "获取七牛token失败,请联系管理员",
180   - });
181   - return false;
182   - }
183   -
184 167 const observer = {
185 168 next(res) {
186 169 if (res.total.percent >= 99) {
... ... @@ -193,35 +176,38 @@ const Audio = {
193 176 console.log(err);
194 177 },
195 178 complete(res) {
  179 + let apiDone = all.secretUrls.base + all.secretUrls.finish;
  180 + let apiStringSignDone = all.signFunction(
  181 + apiDone,
  182 + that.getParamsList({
  183 + hash: res.hash,
  184 + key: res.key,
  185 + vid: fileSaveObj.videoId,
  186 + timestamp: that.getTimeStamp(),
  187 + })
  188 + );
196 189 all
197 190 .request({
198   - url: all.urls.base + all.urls.save,
  191 + url: apiDone,
199 192 method: "get",
200   - params: {
201   - hash: res.hash,
202   - key: res.key,
203   - vid: fileSaveObj.videoId,
204   - },
  193 + params: all.parseQueryString(apiStringSignDone),
205 194 })
206 195 .then((res) => {
207   - console.log(res);
208   - })
209   - .catch((error) => {
  196 + let apiComplete = all.secretUrls.base + all.secretUrls.callback;
  197 + let apiStringSignComplete = all.signFunction(
  198 + apiComplete,
  199 + that.getParamsList({ ...fileBaseObj, ...fileSaveObj, ...{timestamp: that.getTimeStamp()} })
  200 + );
210 201 return all.request({
211   - url: all.urls.onlineUrl + all.urls.transcode,
212   - params: { ...fileBaseObj, ...fileSaveObj },
213   - method: "get",
214   - });
215   - })
216   - .then((data) => {
  202 + url: apiComplete,
  203 + method: 'get',
  204 + params: all.parseQueryString(apiStringSignComplete),
  205 + })
  206 + }).then(data => {
217 207 that.form.audioId = data.data.data.obj;
218   - // that.btnDisabled = false;
219 208 that.percent = 100;
220   - that.postCms();
  209 + that.postCms()
221 210 })
222   - .catch((error) => {
223   - console.log(error);
224   - });
225 211 },
226 212 };
227 213  
... ... @@ -231,18 +217,37 @@ const Audio = {
231 217 all.validateNameLength(fileBaseObj.videoName),
232 218 ])
233 219 .then((check) => {
  220 + return this.getToken();
  221 + })
  222 + .then((d) => {
  223 + if (d && d.data) {
  224 + this.token = d.data;
  225 + }
234 226 return this.initMd5(this.form.audioFile.raw);
235 227 })
236 228 .then((n) => {
  229 + if (!this.token) {
  230 + this.$message({
  231 + type: "error",
  232 + message: "鉴权失败",
  233 + duration: 5000,
  234 + });
  235 + return false;
  236 + }
237 237 fileBaseObj.md5 = n;
  238 + let apiInit = all.secretUrls.base + all.secretUrls.init;
  239 + let apiStringSignInit = all.signFunction(
  240 + apiInit,
  241 + this.getParamsList({ ...fileBaseObj, ...fileInitObj })
  242 + );
238 243 return all.request({
239   - url: all.urls.onlineUrl + all.urls.initFileOnline,
  244 + url: all.secretUrls.base + all.secretUrls.init,
240 245 method: "get",
241   - params: { ...fileBaseObj, ...fileInitObj },
  246 + params: all.parseQueryString(apiStringSignInit),
242 247 });
243 248 })
244 249 .then((res) => {
245   - if (res && res.data) {
  250 + if (res && res.data && res.data.data && res.data.data.code == 0) {
246 251 fileSaveObj.videoId = res.data.data.obj.vid;
247 252 fileWholeObj.fileKey = res.data.data.obj.originPath;
248 253 all.putExtra.params["x:name"] = fileWholeObj.fileKey;
... ... @@ -279,6 +284,43 @@ const Audio = {
279 284 }
280 285 });
281 286 },
  287 + // 对象参数转数组格式
  288 + getParamsList(params) {
  289 + let list = [];
  290 + for (let i in params) {
  291 + if(i == 'hash' || i == 'key' || i == 'x:name') {
  292 + list.push(`${i}=${encodeURI(params[i])}`)
  293 + } else {
  294 + list.push(`${i}=${params[i]}`);
  295 + }
  296 + }
  297 + return list;
  298 + },
  299 + // 获取时间戳
  300 + getTimeStamp() {
  301 + return Math.round(new Date().getTime() / 1000);
  302 + },
  303 + // 获取时间戳加四位随机数
  304 + getTs() {
  305 + return (
  306 + this.getTimeStamp().toString() +
  307 + Math.floor(Math.random() * 10000).toString()
  308 + );
  309 + },
  310 + // 获取认证token
  311 + getToken() {
  312 + let api = all.secretUrls.base + all.secretUrls.auth;
  313 + let apiStringSign = all.signFunction(api, [
  314 + "ts=" + this.getTs(),
  315 + "timestamp=" + this.getTimeStamp(),
  316 + ]);
  317 + return all.request({
  318 + url: all.secretUrls.base + all.secretUrls.auth,
  319 + method: "get",
  320 + params: all.parseQueryString(apiStringSign),
  321 + });
  322 + },
  323 + // cms接口提交videoId和表单内容
282 324 postCms() {
283 325 this.form.lyric = this.form.lyric ? this.form.lyric.trim() : "";
284 326 all
... ... @@ -294,7 +336,7 @@ const Audio = {
294 336 },
295 337 })
296 338 .then((res) => {
297   - if (res.data) {
  339 + if (res.data) {
298 340 setTimeout(() => {
299 341 console.log("jump");
300 342 // window.location.replace("./success.html");
... ... @@ -314,6 +356,7 @@ const Audio = {
314 356 this.submitDisabled = false;
315 357 });
316 358 },
  359 + // 获取txt文件内容,暂未启用
317 360 getTxt(e) {
318 361 this.form.txtFile = e.raw;
319 362 let file = e.raw;
... ... @@ -325,147 +368,9 @@ const Audio = {
325 368 };
326 369 reader.readAsArrayBuffer(file);
327 370 },
  371 + // 选择上传文件
328 372 getMp3(file) {
329   - // this.btnDisabled = true;
330 373 this.form.audioFile = file;
331   - console.log(this.fileList);
332   - return false;
333   - const fileName = file.raw.name.split(".");
334   - fileName.splice(fileName.length - 1, 1);
335   - this.curFile = file.name;
336   - this.form.audioId = null;
337   - const that = this;
338   - const fileBaseObj = {
339   - videoName: fileName.join("."),
340   - md5: null,
341   - };
342   - const fileSaveObj = {
343   - videoId: null,
344   -
345   - multipleCategory: 100005,
346   - tag: "test",
347   - synopsis: "test",
348   - mmsType: 0,
349   - videoType: 11003,
350   - videoType: 0,
351   - masterId: 10494974,
352   - };
353   - const fileInitObj = {
354   - gfmt: file.raw.name.split(".").reverse().shift(),
355   - fileSize: file.raw.size,
356   - videoType: 11003,
357   - ptpwVal: 0,
358   - archiveStatus: 0,
359   - multipleCategory: 100005,
360   - uploadLine: 2,
361   - masterId: 10494974,
362   - };
363   - const fileWholeObj = {
364   - file: file.raw,
365   - uploadStatus: "ready",
366   - proCount: 0,
367   - fileKey: null,
368   - observable: null,
369   - subscription: null,
370   - };
371   -
372   - if (this.token == null) {
373   - this.$message({
374   - type: "error",
375   - message: "获取七牛token失败,请联系管理员",
376   - });
377   - return false;
378   - }
379   -
380   - const observer = {
381   - next(res) {
382   - if (res.total.percent >= 99) {
383   - that.percent = 99;
384   - } else {
385   - that.percent = Math.ceil(res.total.percent);
386   - }
387   - },
388   - error(err) {
389   - console.log(err);
390   - },
391   - complete(res) {
392   - all
393   - .request({
394   - url: all.urls.base + all.urls.save,
395   - method: "get",
396   - params: {
397   - hash: res.hash,
398   - key: res.key,
399   - vid: fileSaveObj.videoId,
400   - },
401   - })
402   - .then((res) => {
403   - console.log(res);
404   - })
405   - .catch((error) => {
406   - return all.request({
407   - url: all.urls.onlineUrl + all.urls.transcode,
408   - params: { ...fileBaseObj, ...fileSaveObj },
409   - method: "get",
410   - });
411   - })
412   - .then((data) => {
413   - that.form.audioId = data.data.data.obj;
414   - // that.msgText = '音频上传成功'
415   - that.btnDisabled = false;
416   - that.percent = 100;
417   - })
418   - .catch((error) => {
419   - console.log(error);
420   - });
421   - },
422   - };
423   -
424   - Promise.all([
425   - all.validateVideoSize(fileInitObj.fileSize),
426   - all.validateVideoFormat(fileInitObj.gfmt),
427   - all.validateNameLength(fileBaseObj.videoName),
428   - ])
429   - .then((check) => {
430   - return this.initMd5(file.raw);
431   - })
432   - .then((n) => {
433   - fileBaseObj.md5 = n;
434   - return all.request({
435   - url: all.urls.onlineUrl + all.urls.initFileOnline,
436   - method: "get",
437   - params: { ...fileBaseObj, ...fileInitObj },
438   - });
439   - })
440   - .then((res) => {
441   - if (res && res.data) {
442   - fileSaveObj.videoId = res.data.data.obj.vid;
443   - fileWholeObj.fileKey = res.data.data.obj.originPath;
444   - all.putExtra.params["x:name"] = fileWholeObj.fileKey;
445   - fileWholeObj.observable = qiniu.upload(
446   - file.raw,
447   - fileWholeObj.fileKey,
448   - this.token,
449   - all.putExtra,
450   - all.cdnConfig
451   - );
452   - fileWholeObj.subscription =
453   - fileWholeObj.observable.subscribe(observer);
454   - } else {
455   - this.$message({
456   - type: "error",
457   - duration: 0,
458   - message: "未知错误,请联系管理员。",
459   - });
460   - }
461   - })
462   - .catch((error) => {
463   - this.$message({
464   - type: "error",
465   - message: error,
466   - duration: 0,
467   - });
468   - });
469 374 },
470 375 },
471 376 };
... ...
src/js/config.js
1 1 const basicConfig = {
2 2 baseUrl: "http://cmstest.cnlive.com/cms",
3   -}
  3 +};
4 4  
5 5 const urls = {
6 6 base: "http://test.mam.innerapi.cnlive.com/v1/inner/",
7   - onlineUrl: 'https://api.cnlive.com/open/api2/vod_epg/material/',
  7 + onlineUrl: "https://api.cnlive.com/open/api2/vod_epg/material/",
8 8 token: "material/getQNToken",
9 9 save: "material/saveQNComplete",
10   - initFileOnline: 'uploadFileInit?appId=1423_kbrrnni803',
  10 + initFileOnline: "uploadFileInit?appId=1423_kbrrnni803",
11 11 transcode: "pendingTranscodeTask?appId=1423_kbrrnni803",
12 12 };
13 13  
  14 +const secretUrls = {
  15 + base: "https://api.cnlive.com/open/api2/vod_epg/videoPgc",
  16 + auth: "/getUploadAuth",
  17 + init: "/uploadFileInit",
  18 + callback: "/uploadCallback",
  19 + finish: "/uploadSuccess",
  20 + masterIdDev: 10505921,
  21 + masterIdMaster: 10494974,
  22 + appIdDev: "802_ji9ojo9w63",
  23 + appIdMaster: "1423_kbrrnni803",
  24 + appKeyDev: '06138c3527f48e7020261b9225660792d0a45d76b1cd4d',
  25 + appKeyMaster: '459d0881107ea2ddff78fb1ab31b1f134cc331982807a7'
  26 +};
  27 +
14 28 const cdnConfig = {
15 29 useCdnDomain: true,
16 30 disableStatisticsReport: true,
17 31 retryCount: 6,
18   - region: qiniu.region.z1
19   -}
  32 + region: qiniu.region.z1,
  33 +};
20 34  
21 35 const putExtra = {
22 36 fname: "",
23 37 params: {},
24   - mimeType: null
  38 + mimeType: null,
25 39 };
26 40  
27   -
28   -
29 41 // Rewrite Request Method
30   -// const baseUrl = "http://cmstest.cnlive.com/cms";
31 42 const request = axios.create({
32   - timeout: 10000
  43 + timeout: 10000,
33 44 });
34 45  
35   -// QiNiu Configs
36   -// const cdnConfig = {
37   -// useCdnDomain: true,
38   -// disableStatisticsReport: true,
39   -// retryCount: 6,
40   -// region: qiniu.region.z1
41   -// };
42   -// const putExtra = {
43   -// fname: "",
44   -// params: {},
45   -// mimeType: null
46   -// };
47   -// const urls = {
48   -// base: "http://test.mam.innerapi.cnlive.com/v1/inner/",
49   -// onlineUrl: 'https://api.cnlive.com/open/api2/vod_epg/material/',
50   -// token: "material/getQNToken",
51   -// save: "material/saveQNComplete",
52   -// initFileOnline: 'uploadFileInit?appId=802_k8ho7qks68',
53   -// transcode: "pendingTranscodeTask?appId=802_k8ho7qks68",
54   -// };
  46 +
  47 +// Init signature
  48 +const signFunction = function (api, list) {
  49 + let sha1 = require('sha1')
  50 + //数组合并
  51 + let arrApi = ["appId=" + secretUrls.appIdDev];
  52 + arrApi = arrApi.concat(list); //对数组进行升序处理,并拼成一个字符串
  53 +
  54 + let stringSign = arrApi.sort().join("&"); //key要放在字符串最后,对字符串进行sha1加密处理,并转换为大写
  55 +
  56 + let signValue = sha1(stringSign + "&key=" + secretUrls.appKeyDev).toUpperCase(); //生成最终的请求参数
  57 +
  58 + let apiStringSign = api + "?" + stringSign + "&sign=" + signValue;
  59 +
  60 + return apiStringSign;
  61 +};
  62 +
  63 +const parseQueryString = function (url) {
  64 + var reg_url = /^[^\?]+\?([\w\W]+)$/,
  65 + reg_para = /([^&=]+)=([\w\W]*?)(&|$|#)/g,
  66 + arr_url = reg_url.exec(url),
  67 + ret = {};
  68 + if (arr_url && arr_url[1]) {
  69 + var str_para = arr_url[1],
  70 + result;
  71 + while ((result = reg_para.exec(str_para)) != null) {
  72 + ret[result[1]] = result[2];
  73 + }
  74 + }
  75 + return ret;
  76 +};
55 77  
56 78 // File And Form Validate
57   -const validateVideoSize = function(curSize) {
  79 +const validateVideoSize = function (curSize) {
58 80 const sizeLimitation = 1024 * 1024 * 500; // 500M
59 81 return new Promise((resolve, reject) => {
60 82 if (parseInt(curSize) <= sizeLimitation) {
... ... @@ -65,7 +87,7 @@ const validateVideoSize = function(curSize) {
65 87 });
66 88 };
67 89  
68   -const validateNameLength = function(name) {
  90 +const validateNameLength = function (name) {
69 91 return new Promise((resolve, reject) => {
70 92 if (name.length < 1 || name.length > 100) {
71 93 reject("文件名称最小长度为2,上限长度为100!");
... ... @@ -75,7 +97,7 @@ const validateNameLength = function(name) {
75 97 });
76 98 };
77 99  
78   -const validateVideoFormat = function(curFormat) {
  100 +const validateVideoFormat = function (curFormat) {
79 101 // const formats = [
80 102 // "mp3",
81 103 // "wma",
... ... @@ -93,12 +115,7 @@ const validateVideoFormat = function(curFormat) {
93 115 // "ogg",
94 116 // "mp2"
95 117 // ];
96   - const formats = [
97   - "mp3",
98   - "flac",
99   - "wav",
100   - "ogg"
101   - ];
  118 + const formats = ["mp3", "flac", "wav", "ogg"];
102 119 return new Promise((resolve, reject) => {
103 120 if (formats.includes(curFormat)) {
104 121 resolve("格式可以");
... ... @@ -127,7 +144,7 @@ const validateName = (rules, value, callback) =&gt; {
127 144 }
128 145 };
129 146  
130   -const initVideoMd5 = function(e) {
  147 +const initVideoMd5 = function (e) {
131 148 function i(e) {
132 149 var i = (e >>> 0).toString(16);
133 150 return "00000000".substr(0, 8 - i.length) + i;
... ... @@ -172,10 +189,7 @@ const initVideoMd5 = function(e) {
172 189 if (e.charCodeAt(t) <= 127) i.push(e.charCodeAt(t));
173 190 else
174 191 for (
175   - var r = encodeURIComponent(e.charAt(t))
176   - .substr(1)
177   - .split("%"),
178   - l = 0;
  192 + var r = encodeURIComponent(e.charAt(t)).substr(1).split("%"), l = 0;
179 193 l < r.length;
180 194 l++
181 195 )
... ... @@ -313,33 +327,32 @@ const initVideoMd5 = function(e) {
313 327 typeof e == "string"
314 328 ? (m = c(e))
315 329 : e.constructor == Array
316   - ? e.length === 0
317   - ? (m = e)
318   - : typeof e[0] == "string"
319   - ? (m = t(e))
320   - : typeof e[0] == "number"
321   - ? (m = e)
322   - : (v = typeof e[0])
323   - : typeof ArrayBuffer != "undefined"
324   - ? e instanceof ArrayBuffer
325   - ? (m = u(new Uint8Array(e)))
326   - : e instanceof Uint8Array || e instanceof Int8Array
327   - ? (m = u(e))
328   - : e instanceof Uint32Array ||
329   - e instanceof Int32Array ||
330   - e instanceof Uint16Array ||
331   - e instanceof Int16Array ||
332   - e instanceof Float32Array ||
333   - e instanceof Float64Array
334   - ? (m = u(new Uint8Array(e.buffer)))
335   - : (v = typeof e)
336   - : (v = typeof e),
  330 + ? e.length === 0
  331 + ? (m = e)
  332 + : typeof e[0] == "string"
  333 + ? (m = t(e))
  334 + : typeof e[0] == "number"
  335 + ? (m = e)
  336 + : (v = typeof e[0])
  337 + : typeof ArrayBuffer != "undefined"
  338 + ? e instanceof ArrayBuffer
  339 + ? (m = u(new Uint8Array(e)))
  340 + : e instanceof Uint8Array || e instanceof Int8Array
  341 + ? (m = u(e))
  342 + : e instanceof Uint32Array ||
  343 + e instanceof Int32Array ||
  344 + e instanceof Uint16Array ||
  345 + e instanceof Int16Array ||
  346 + e instanceof Float32Array ||
  347 + e instanceof Float64Array
  348 + ? (m = u(new Uint8Array(e.buffer)))
  349 + : (v = typeof e)
  350 + : (v = typeof e),
337 351 v && alert("MD5 type mismatch, cannot process " + v),
338 352 d()
339 353 );
340 354 };
341 355  
342   -
343 356 export {
344 357 initVideoMd5,
345 358 validateName,
... ... @@ -347,9 +360,12 @@ export {
347 360 validateVideoFormat,
348 361 validateNameLength,
349 362 validateVideoSize,
  363 + signFunction,
  364 + parseQueryString,
350 365 request,
351 366 putExtra,
352 367 cdnConfig,
353 368 basicConfig,
354   - urls
355   -}
  369 + urls,
  370 + secretUrls,
  371 +};
... ...
webpack.config.js
... ... @@ -10,7 +10,7 @@ module.exports = {
10 10 entry: path.join(__dirname, "src", "/js/audios.js"), //__dirname指的是当前目录,是目录形成绝对路径
11 11 output: {
12 12 //输入的文件名
13   - filename: "bundle.js",
  13 + filename: "prodtestdata.js",
14 14 // filename: '[name].[hash:7].js',
15 15 publicPath: "/",
16 16 //输入的路径 webpack会自动打包生成
... ... @@ -24,7 +24,7 @@ module.exports = {
24 24 //文件中找到的路径
25 25 template: path.join(__dirname, "src", "html/index.html"),
26 26 //打包输出的路径
27   - filename: "audio.html",
  27 + filename: "prodtestdata.html",
28 28 }),
29 29 new CleanWebpackPlugin(),
30 30 ],
... ...