From 95f68a1fb12926c3a514577727793a3569c1acd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E9=A3=9E?= Date: Thu, 11 Jan 2024 14:41:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=A4=E7=A7=8D=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/App.vue | 3 +- src/utils/oss.js | 77 ++++++++++++++++++- .../attachment/components/attachmentForm.vue | 1 + 4 files changed, 77 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 200dbf0c..7d59d226 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "scripts": { "dev": "vue-cli-service serve --open", - "build": "vue-cli-service --max_old_space_size=10000 build", + "build": "vue-cli-service build", "build:prod": "vue-cli-service build --mode prod", "build:uat": "vue-cli-service build --mode uat", "build:usa": "vue-cli-service build --mode usa", diff --git a/src/App.vue b/src/App.vue index 95d559ec..283a4316 100644 --- a/src/App.vue +++ b/src/App.vue @@ -102,7 +102,8 @@ export default { return ~this.$path.indexOf(v.Code) }) this.tableData = Object.assign([], tableData) - console.log(this.tableData) + console.log(JSON.stringify(this.$path)) + console.log(JSON.stringify(this.tableData)) } } } diff --git a/src/utils/oss.js b/src/utils/oss.js index 56388093..a22ee9c7 100644 --- a/src/utils/oss.js +++ b/src/utils/oss.js @@ -1,5 +1,8 @@ const OSS = require('ali-oss') -import Minio from 'minio' + +const Minio = require('minio') +const stream = require('stream') +console.log(Minio) import Vue from 'vue' const { GenerateSTS, GetObjectStoreToken } = require('../api/user.js') import { getToken } from '@/utils/auth' @@ -7,21 +10,87 @@ import { getToken } from '@/utils/auth' Vue.prototype.OSSclientConfig = { } +function blobToBuffer(blob, fileName) { + return new Promise((resolve, reject) => { + const file = new File([blob], fileName); + resolve(file) + }) +} async function ossGenerateSTS() { let res = await GetObjectStoreToken() - Vue.prototype.OSSclientConfig = { ...res.Result[res.Result.ObjectStoreUse] } + let ObjectStoreUse = 'AWS' + // Vue.prototype.OSSclientConfig = { ...res.Result[res.Result.ObjectStoreUse] } + Vue.prototype.OSSclientConfig = { ...res.Result[ObjectStoreUse] } Vue.prototype.OSSclientConfig.basePath = Vue.prototype.OSSclientConfig.viewEndpoint // let minioClient = new Minio.Client(Vue.prototype.OSSclientConfig); - switch (res.Result.ObjectStoreUse) { + // switch (res.Result.ObjectStoreUse) { + switch (ObjectStoreUse) { case 'AliyunOSS': Vue.prototype.OSSclientConfig.bucket = Vue.prototype.OSSclientConfig.bucketName Vue.prototype.OSSclient = new OSS(Vue.prototype.OSSclientConfig) break case 'MinIO': let minioClient = new Minio.Client(Vue.prototype.OSSclientConfig); - // Vue.prototype.OSSclient = new OSS(Vue.prototype.OSSclientConfig) + Vue.prototype.OSSclient = { + put: function (objectName, object) { + return new Promise(async (resolve, reject) => { + try { + var name = objectName.split('/')[objectName.split('/').length - 1] + const reader = new FileReader(); + reader.onload = (ex) => { + const bufferStream = new stream.PassThrough() + bufferStream.end(Buffer.from(ex.target.result)) + minioClient.putObject(Vue.prototype.OSSclientConfig.bucketName, objectName, bufferStream, function(err,etag) { + if (err) { + console.log(err) + reject() + } else { + resolve({ + name: objectName, + url: 'http://www.abc.com' + objectName + }) + } + }) + }; + reader.readAsArrayBuffer(object); + } catch (e) { + console.log(e) + } + }) + } + } break + case 'AWS': + let aws = new Minio.Client(Vue.prototype.OSSclientConfig); + Vue.prototype.OSSclient = { + put: function (objectName, object) { + return new Promise(async (resolve, reject) => { + try { + var name = objectName.split('/')[objectName.split('/').length - 1] + const reader = new FileReader(); + reader.onload = (ex) => { + const bufferStream = new stream.PassThrough() + bufferStream.end(Buffer.from(ex.target.result)) + aws.putObject(Vue.prototype.OSSclientConfig.bucketName, objectName, bufferStream, function(err,etag) { + if (err) { + console.log(err) + reject() + } else { + resolve({ + name: objectName, + url: 'http://www.abc.com' + objectName + }) + } + }) + }; + reader.readAsArrayBuffer(object); + } catch (e) { + console.log(e) + } + }) + } + } } return } diff --git a/src/views/trials/trials-panel/setting/attachment/components/attachmentForm.vue b/src/views/trials/trials-panel/setting/attachment/components/attachmentForm.vue index b4bf3454..4463216e 100644 --- a/src/views/trials/trials-panel/setting/attachment/components/attachmentForm.vue +++ b/src/views/trials/trials-panel/setting/attachment/components/attachmentForm.vue @@ -234,6 +234,7 @@ export default { this.loading = true var file = await this.fileToBlob(param.file) const trialId = this.$route.query.trialId + console.log(this.OSSclient.put) const res = await this.OSSclient.put(`/${trialId}/DocumentToSign/${param.file.name}`, file) this.fileList.push({ name: param.file.name, path: this.$getObjectName(res.url), url: this.$getObjectName(res.url) }) this.form.Path = this.$getObjectName(res.url)