Skip to content

Commit

Permalink
perf: upload sdk换成aws-s3
Browse files Browse the repository at this point in the history
  • Loading branch information
greper committed Mar 10, 2023
1 parent e924d61 commit 6814083
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"docgen:extends": "vue-docgen -c docgen/extends.config.js",
"docgen:all": "npm run docgen:crud && npm run docgen:extends",
"prepublishOnly": "lerna run build --scope */ui-* --scope @fast-crud/fast-crud --scope @fast-crud/fast-extends",
"publish": "npm run prepublishOnly && lerna publish --conventional-commits && npm run copylogs",
"publish": "npm run prepublishOnly && lerna publish --conventional-commits --create-release github && npm run copylogs",
"publish:canary": "lerna publish --canary --conventional-commits && npm run copylogs",
"afterpublish": "npm run copylogs",
"copylogs": "copyfiles \"packages/**/CHANGELOG.md\" ./docs/zh/guide/other/changelogs/ -e **/node_modules/** && copyfiles \"CHANGELOG.md\" ./docs/zh/guide/other/changelogs/",
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-crud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"typedoc-github-wiki-theme": "^1.0.1",
"typedoc-plugin-markdown": "^3.13.6",
"typescript": "4.8.4",
"unplugin-vue-define-options": "^1.2.3",
"unplugin-vue-define-options": "^1.2.4",
"vite": "^3.1.4",
"vite-plugin-compression": "^0.5.1",
"vue": ">=3.2.40",
Expand Down
2 changes: 2 additions & 0 deletions packages/fast-extends/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"author": "Greper",
"license": "MIT",
"dependencies": {
"@aws-sdk/client-s3": "^3.288.0",
"@aws-sdk/s3-request-presigner": "^3.288.0",
"@soerenmartius/vue3-clipboard": "^0.1.2",
"@wangeditor/editor": "^5.1.23",
"@wangeditor/editor-for-vue": "^5.1.12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ export default {
const array: any = [];
for (let item of fList) {
if (ui.upload.isSuccess(item)) {
debugger;
array.push(await buildOneToValue(item));
}
}
Expand Down Expand Up @@ -317,6 +316,7 @@ export default {
option.options = props.uploader;
let uploaderRef = uploaderImplRef.value.getUploaderRef();
if (uploaderRef == null) {
ui.message.warn("Sorry,The uploader component is not ready yet");
throw new Error("Sorry,The component is not ready yet");
}
return await uploaderRef?.upload(option);
Expand Down
30 changes: 14 additions & 16 deletions packages/fast-extends/src/uploader/components/fs-uploader-s3.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,35 @@
import _ from "lodash-es";
import { useUploader, buildKey } from "./utils/index.js";
import { getCurrentInstance } from "vue";
import Minio from "minio";
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
async function doUpload({ file, fileName, onProgress, options }) {
const minioClient = new Minio.Client({
const client = new S3Client({
...(options.sdkOpts || {})
});
return new Promise(async (resolve, reject) => {
const key = await buildKey(file, fileName, options);
const metaData = {
"Content-Type": "application/octet-stream",
// "X-Amz-Meta-Testing": 1234,
// example: 5678
...options.metaData
};
async function complete() {
let ret = { url: options.domain + "/" + key, key: key };
let ret = { url: options.sdkOpts.endpoint + "/" + options.bucket + "/" + key, key: key };
if (options.successHandle) {
ret = await options.successHandle(ret);
resolve(ret);
return;
}
resolve(ret);
}
return minioClient.fPutObject(options.bucket, key, file, metaData, function (err, etag) {
if (err) {
reject(err);
}
//onProgress(res.total);
complete();
});
const params = {
Bucket: options.bucket, // The name of the bucket. For example, 'sample_bucket_101'.
Key: key // The name of the object. For example, 'sample_upload.txt'.
};
try {
await client.send(new PutObjectCommand({ Body: file, ...params }));
return complete();
} catch (err) {
reject(err);
}
});
}
export default {
Expand Down

0 comments on commit 6814083

Please sign in to comment.