Ver Fonte

add file.js

reghao há 1 ano atrás
pai
commit
5ad81c5d87
2 ficheiros alterados com 44 adições e 4 exclusões
  1. 8 4
      src/api/file.js
  2. 36 0
      src/components/upload/PublishVideo.vue

+ 8 - 4
src/api/file.js

@@ -1,9 +1,13 @@
 import { post } from '@/utils/request'
 
-const diskApi = {
-  ossServerApi: '/api/disk/oss/serverinfo'
+const fileApi = {
+  ossServerApi: '/api/file/oss/serverinfo'
 }
 
-export function getServerInfo(channelId) {
-  return post(diskApi.ossServerApi + '?channelId=' + channelId)
+export function getAvatarChannelInfo() {
+  return post(fileApi.ossServerApi + '/avatar')
+}
+
+export function getVideoChannelInfo() {
+  return post(fileApi.ossServerApi + '/video')
 }

+ 36 - 0
src/components/upload/PublishVideo.vue

@@ -118,6 +118,7 @@
 <script>
 import { getServerInfo } from '@/api/content'
 import { videoRegion, addVideoPost } from '@/api/video'
+import {getVideoChannelInfo} from "@/api/file";
 
 export default {
   name: 'PublishVideo',
@@ -165,6 +166,41 @@ export default {
     }
   },
   created() {
+    getVideoChannelInfo().then(res => {
+      if (res.code === 0) {
+        const resData = res.data
+        this.options = {
+          target: resData.ossUrl,
+          chunkSize: resData.maxSize,
+          fileParameterName: 'file',
+          testChunks: false,
+          query: (file, chunk) => {
+            return {
+              channelId: this.form.channelId
+            }
+          },
+          headers: {
+            Authorization: 'Bearer ' + resData.token
+          },
+          withCredentials: false
+        }
+      } else {
+        this.$notify({
+          title: '提示',
+          message: '获取 OSS 服务器地址失败, 暂时无法上传视频文件',
+          type: 'error',
+          duration: 3000
+        })
+      }
+    }).catch(error => {
+      this.$notify({
+        title: '提示',
+        message: '获取 OSS 服务器地址失败, 暂时无法上传视频文件',
+        type: 'warning',
+        duration: 3000
+      })
+    })
+
     getServerInfo(this.form.channelId).then(res => {
       if (res.code === 0) {
         const resData = res.data