|
|
@@ -4,6 +4,50 @@ import { useMainStore } from '@/store'
|
|
|
import { getImageDataURL } from '@/utils/image'
|
|
|
import usePasteTextClipboardData from './usePasteTextClipboardData'
|
|
|
import useCreateElement from './useCreateElement'
|
|
|
+/**
|
|
|
+ * 上传 File 到 S3,返回公开访问的 URL
|
|
|
+ */
|
|
|
+const uploadFileToS3 = (file: File): Promise<string> => {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ if (typeof window === 'undefined' || !window.AWS) {
|
|
|
+ reject(new Error('AWS SDK not available'))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const credentials = {
|
|
|
+ accessKeyId: 'AKIATLPEDU37QV5CHLMH',
|
|
|
+ secretAccessKey: 'Q2SQw37HfolS7yeaR1Ndpy9Jl4E2YZKUuuy2muZR',
|
|
|
+ }
|
|
|
+ window.AWS.config.update(credentials)
|
|
|
+ window.AWS.config.region = 'cn-northwest-1'
|
|
|
+
|
|
|
+ const bucket = new window.AWS.S3({
|
|
|
+ params: { Bucket: 'ccrb' }, httpOptions: {
|
|
|
+ timeout: 600000 // 10分钟超时
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const ext = file.name.split('.').pop() || 'bin'
|
|
|
+ const key = `${file.name.split('.')[0]}_${Date.now()}.${ext}`
|
|
|
+
|
|
|
+ const params = {
|
|
|
+ Key: 'pptto/' + key,
|
|
|
+ ContentType: file.type,
|
|
|
+ Body: file,
|
|
|
+ ACL: 'public-read',
|
|
|
+ }
|
|
|
+ const options = {
|
|
|
+ partSize: 5 * 1024 * 1024, // 2GB 分片,可酌情调小
|
|
|
+ queueSize: 2,
|
|
|
+ leavePartsOnError: true,
|
|
|
+ }
|
|
|
+
|
|
|
+ bucket
|
|
|
+ .upload(params, options)
|
|
|
+ .promise()
|
|
|
+ .then(data => resolve(data.Location))
|
|
|
+ .catch(err => reject(err))
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
export default () => {
|
|
|
const { editorAreaFocus, thumbnailsFocus, disableHotkeys } = storeToRefs(useMainStore())
|
|
|
@@ -13,7 +57,8 @@ export default () => {
|
|
|
|
|
|
// 粘贴图片到幻灯片元素
|
|
|
const pasteImageFile = (imageFile: File) => {
|
|
|
- getImageDataURL(imageFile).then(dataURL => createImageElement(dataURL))
|
|
|
+ // getImageDataURL(imageFile).then(dataURL => createImageElement(dataURL))
|
|
|
+ uploadFileToS3(imageFile).then(url => createImageElement(url))
|
|
|
}
|
|
|
|
|
|
/**
|