diff --git a/package-lock.json b/package-lock.json index e882e48..f658e2f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "cloudmind_front", "version": "0.0.0", "dependencies": { + "cos-js-sdk-v5": "^1.6.0", "element-plus": "^2.5.1", "pinia": "^2.1.7", "postcss": "^8.4.33", @@ -2089,6 +2090,14 @@ "url": "https://github.com/sponsors/antfu" } }, + "node_modules/@xmldom/xmldom": { + "version": "0.8.10", + "resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.10.tgz", + "integrity": "sha512-2WALfTl4xo2SkGCYRt6rDTFfk9R1czmBvUQy12gK2KuRKIpWEhcbbzy8EZXtz/jkRqHX8bFEc6FC1HjX4TUWYw==", + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/abbrev": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-2.0.0.tgz", @@ -3149,6 +3158,14 @@ "node": ">= 0.10" } }, + "node_modules/cos-js-sdk-v5": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/cos-js-sdk-v5/-/cos-js-sdk-v5-1.6.0.tgz", + "integrity": "sha512-RvjjPFz3fi1f+M8bPhpEa0wo3Od9CC+gL1ReFjxPx9fmejScFBMjiXbmFS90oXstwFq+2zweuxbi4DiuIgVC3w==", + "dependencies": { + "@xmldom/xmldom": "^0.8.6" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", diff --git a/package.json b/package.json index 6af8636..536df2e 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "format": "prettier --write src/" }, "dependencies": { + "cos-js-sdk-v5": "^1.6.0", "element-plus": "^2.5.1", "pinia": "^2.1.7", "postcss": "^8.4.33", diff --git a/src/utils/cos.ts b/src/utils/cos.ts new file mode 100644 index 0000000..63b34d7 --- /dev/null +++ b/src/utils/cos.ts @@ -0,0 +1,49 @@ +import COS from 'cos-js-sdk-v5' +import { post } from './request' + +/* +创建cos(全局唯一的,用来上传文件的) -> +用户需要上传文件-> cos.UploadFile(options,密钥) +-> getAuthorization(options, callback) -> 获取临时密钥 +-> callback()将密钥传回UploadFile -> 上传文件 +*/ + +const Bucket = 'cloudmind-1318210890' +const Region = 'ap-guangzhou' +const cos = new COS({ + getAuthorization: (options: any, callback: any) => { + // users/md5.suffix 从该字符传中提取md5和suffix + const md5 = options.Key.split('.')[0].split('/').pop() + const suffix = options.Key.split('.')[1] + // options.Key = users/md5.suffix + post('/sts/applySignedUrl', { + md5, + suffix + }) + .then((res: any) => { + callback({ + TmpSecretId: res.tmpSecretId, + TmpSecretKey: res.tmpSecretKey, + StartTime: res.startTime, // 时间戳,单位秒,如:1580000000 + ExpiredTime: res.expiredTime, // 时间戳,单位秒,如:1580000000 + ScopeLimit: true, // 细粒度控制权限需要设为 true,会限制密钥只在相同请求时重复使用 + SecurityToken: res.sessionToken, // 如果使用临时密钥,需要把 sessionToken 传给 SecurityToken + }) + }) + } +}) + +export const cosUploadFile = (file: any, md5: string, suffix: string) => { + cos.uploadFile({ + Bucket, + Region, + Key: `users/${md5}${suffix}`, + Body: file, + SliceSize: file.size, + onProgress: (progressData: any) => { + console.log(JSON.stringify(progressData)); + } + }, (err: any, data: any) => { + console.log(err || data); + }) +} \ No newline at end of file diff --git a/src/utils/request.ts b/src/utils/request.ts index 1bc7691..f633bd0 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -44,7 +44,7 @@ service.interceptors.response.use( const longToken = localStorage.getItem('LongToken') if (longToken) { - post('/auth/refresh', { longToken }) + post('/auth/refreshToken', { longToken }) .then((response: any) => { if (response.msg === 'token有误') { store.loginOut() diff --git a/src/views/personal/personal.vue b/src/views/personal/personal.vue index b4d62e6..490bd2e 100644 --- a/src/views/personal/personal.vue +++ b/src/views/personal/personal.vue @@ -68,15 +68,20 @@ class="contextmenu-popup" id="contextmenuPopup" v-show="isContexmenuPopup" + @update="updateFilesList" :style="{left: popupLeft + 'px', top: popupRight + 'px'}" >
-
+
-
复习资料
-
2024/01/26 13:14
+
{{ getFileName(file.name) }}
+
{{ getFileTime(file.updateAt) }}