@qxs-bns/utils 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/file-operations.cjs +1 -1
- package/src/file-operations.js +49 -47
- package/types/index.d.ts +2 -7
package/package.json
CHANGED
package/src/file-operations.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var s=(
|
|
1
|
+
"use strict";var s=(r,l,a)=>new Promise((o,c)=>{var e=n=>{try{d(a.next(n))}catch(i){c(i)}},t=n=>{try{d(a.throw(n))}catch(i){c(i)}},d=n=>n.done?o(n.value):Promise.resolve(n.value).then(e,t);d((a=a.apply(r,l)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function u(r){return s(this,null,function*(){return new Promise((l,a)=>{try{const o=document.createElement("script");o.src=r,o.onload=()=>{l()},o.onerror=()=>{a(new Error(`Failed to load script from ${r}`))},document.head.appendChild(o)}catch(o){a(o)}})})}function p(){return s(this,null,function*(){try{if(yield u("https://gosspublic.alicdn.com/aliyun-oss-sdk.min.js"),yield u("https://cdnfile.yaomaitong.cn/cdn/js/aliyun-upload-sdk1.3.1.min.js"),!window.AliyunUpload)throw new Error("SDK 加载成功但未找到 AliyunUpload 对象")}catch(r){throw r}})}function w(r){return s(this,null,function*(){if(typeof window=="undefined")throw new TypeError("VideoUploader 只能在浏览器环境中使用");window.AliyunUpload||(yield p());let l=null,a=null;const o=new window.AliyunUpload.Vod({onUploadProgress:r.onUploadProgress,onUploadTokenExpired:r.onUploadTokenExpired||(()=>{}),onUploadstarted:e=>s(this,null,function*(){var t;try{const{uploadAuth:d,uploadAddress:n,videoId:i}=(yield(t=r.onUploadstarted)==null?void 0:t.call(r,e))||{};d&&n&&i&&o.setUploadAuthAndAddress(e,d,n,i)}catch(d){throw d}}),onUploadSucceed:e=>{l==null||l(e)},onUploadFailed:(e,t,d)=>{a==null||a(new Error(`${d} ${t}`))}});return{uploader:o,upload:e=>s(this,null,function*(){return new Promise((t,d)=>{l=t,a=d;const n=JSON.stringify({Vod:{UserData:{IsShowWaterMark:"false",Priority:"7"}}});o.addFile(e,null,null,null,n),o.startUpload()})})}})}exports.createVideoUploader=w;
|
package/src/file-operations.js
CHANGED
|
@@ -1,65 +1,77 @@
|
|
|
1
|
-
var s = (
|
|
2
|
-
var
|
|
1
|
+
var s = (r, l, a) => new Promise((o, c) => {
|
|
2
|
+
var e = (d) => {
|
|
3
3
|
try {
|
|
4
|
-
|
|
5
|
-
} catch (
|
|
6
|
-
|
|
4
|
+
n(a.next(d));
|
|
5
|
+
} catch (i) {
|
|
6
|
+
c(i);
|
|
7
7
|
}
|
|
8
|
-
},
|
|
8
|
+
}, t = (d) => {
|
|
9
9
|
try {
|
|
10
|
-
|
|
11
|
-
} catch (
|
|
12
|
-
|
|
10
|
+
n(a.throw(d));
|
|
11
|
+
} catch (i) {
|
|
12
|
+
c(i);
|
|
13
13
|
}
|
|
14
|
-
},
|
|
15
|
-
|
|
14
|
+
}, n = (d) => d.done ? o(d.value) : Promise.resolve(d.value).then(e, t);
|
|
15
|
+
n((a = a.apply(r, l)).next());
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
import h from "../public/aliyun-upload-sdk-1.5.6/lib/aliyun-oss-sdk-6.17.1.min.js";
|
|
19
|
-
function y(d) {
|
|
17
|
+
function p(r) {
|
|
20
18
|
return s(this, null, function* () {
|
|
21
|
-
return new Promise((
|
|
19
|
+
return new Promise((l, a) => {
|
|
22
20
|
try {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
const o = document.createElement("script");
|
|
22
|
+
o.src = r, o.onload = () => {
|
|
23
|
+
l();
|
|
24
|
+
}, o.onerror = () => {
|
|
25
|
+
a(new Error(`Failed to load script from ${r}`));
|
|
26
|
+
}, document.head.appendChild(o);
|
|
27
|
+
} catch (o) {
|
|
28
|
+
a(o);
|
|
27
29
|
}
|
|
28
30
|
});
|
|
29
31
|
});
|
|
30
32
|
}
|
|
31
|
-
function
|
|
33
|
+
function u() {
|
|
32
34
|
return s(this, null, function* () {
|
|
33
35
|
try {
|
|
34
|
-
if (yield
|
|
36
|
+
if (yield p("https://gosspublic.alicdn.com/aliyun-oss-sdk.min.js"), yield p("https://cdnfile.yaomaitong.cn/cdn/js/aliyun-upload-sdk1.3.1.min.js"), !window.AliyunUpload)
|
|
35
37
|
throw new Error("SDK 加载成功但未找到 AliyunUpload 对象");
|
|
36
|
-
} catch (
|
|
37
|
-
throw
|
|
38
|
+
} catch (r) {
|
|
39
|
+
throw r;
|
|
38
40
|
}
|
|
39
41
|
});
|
|
40
42
|
}
|
|
41
|
-
function
|
|
43
|
+
function y(r) {
|
|
42
44
|
return s(this, null, function* () {
|
|
43
45
|
if (typeof window == "undefined")
|
|
44
46
|
throw new TypeError("VideoUploader 只能在浏览器环境中使用");
|
|
45
|
-
window.AliyunUpload || (yield
|
|
47
|
+
window.AliyunUpload || (yield u());
|
|
48
|
+
let l = null, a = null;
|
|
46
49
|
const o = new window.AliyunUpload.Vod({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
onUploadProgress: d.onUploadProgress,
|
|
50
|
-
onUploadTokenExpired: d.onUploadTokenExpired || (() => {
|
|
50
|
+
onUploadProgress: r.onUploadProgress,
|
|
51
|
+
onUploadTokenExpired: r.onUploadTokenExpired || (() => {
|
|
51
52
|
}),
|
|
52
53
|
onUploadstarted: (e) => s(this, null, function* () {
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
var t;
|
|
55
|
+
try {
|
|
56
|
+
const { uploadAuth: n, uploadAddress: d, videoId: i } = (yield (t = r.onUploadstarted) == null ? void 0 : t.call(r, e)) || {};
|
|
57
|
+
n && d && i && o.setUploadAuthAndAddress(e, n, d, i);
|
|
58
|
+
} catch (n) {
|
|
59
|
+
throw n;
|
|
60
|
+
}
|
|
61
|
+
}),
|
|
62
|
+
onUploadSucceed: (e) => {
|
|
63
|
+
l == null || l(e);
|
|
64
|
+
},
|
|
65
|
+
onUploadFailed: (e, t, n) => {
|
|
66
|
+
a == null || a(new Error(`${n} ${t}`));
|
|
67
|
+
}
|
|
57
68
|
});
|
|
58
69
|
return {
|
|
59
70
|
uploader: o,
|
|
60
71
|
upload: (e) => s(this, null, function* () {
|
|
61
|
-
return new Promise((t,
|
|
62
|
-
|
|
72
|
+
return new Promise((t, n) => {
|
|
73
|
+
l = t, a = n;
|
|
74
|
+
const d = JSON.stringify({
|
|
63
75
|
Vod: {
|
|
64
76
|
UserData: {
|
|
65
77
|
IsShowWaterMark: "false",
|
|
@@ -67,22 +79,12 @@ function P(d) {
|
|
|
67
79
|
}
|
|
68
80
|
}
|
|
69
81
|
});
|
|
70
|
-
o.addFile(e, null, null, null,
|
|
71
|
-
const r = (n) => {
|
|
72
|
-
t({ videoId: n.videoId });
|
|
73
|
-
}, a = (n, w, u) => {
|
|
74
|
-
i(new Error(u || "上传失败"));
|
|
75
|
-
}, c = o.onUploadSucceed, U = o.onUploadFailed;
|
|
76
|
-
o.onUploadSucceed = (n) => {
|
|
77
|
-
r(n), c == null || c(n);
|
|
78
|
-
}, o.onUploadFailed = (n, w, u) => {
|
|
79
|
-
a(n, w, u), U == null || U(n, w, u);
|
|
80
|
-
};
|
|
82
|
+
o.addFile(e, null, null, null, d), o.startUpload();
|
|
81
83
|
});
|
|
82
84
|
})
|
|
83
85
|
};
|
|
84
86
|
});
|
|
85
87
|
}
|
|
86
88
|
export {
|
|
87
|
-
|
|
89
|
+
y as createVideoUploader
|
|
88
90
|
};
|
package/types/index.d.ts
CHANGED
|
@@ -121,6 +121,7 @@ declare interface VideoUploadOptions {
|
|
|
121
121
|
|
|
122
122
|
declare interface VideoUploadResult {
|
|
123
123
|
videoId: string;
|
|
124
|
+
uploadInfo: any;
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
export declare function watermark(): {
|
|
@@ -130,16 +131,10 @@ export declare function watermark(): {
|
|
|
130
131
|
|
|
131
132
|
export { }
|
|
132
133
|
|
|
133
|
-
|
|
134
|
-
declare module '*.js?raw' {
|
|
135
|
-
const content: string;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
134
|
declare global {
|
|
140
135
|
interface Window {
|
|
141
136
|
AliyunUpload: any;
|
|
142
|
-
OSS:
|
|
137
|
+
OSS: any;
|
|
143
138
|
}
|
|
144
139
|
}
|
|
145
140
|
|