@qxs-bns/utils 0.0.2 → 0.0.4
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/index.cjs +1 -1
- package/index.js +2 -2
- package/package.json +1 -4
- package/src/device.cjs +1 -1
- package/src/device.js +20 -17
- package/src/file-operations.cjs +1 -1
- package/src/file-operations.js +56 -51
- package/types/index.d.ts +10 -7
- package/vendor/ali-oss/dist/aliyun-oss-sdk.js.cjs +83 -0
- package/vendor/ali-oss/dist/aliyun-oss-sdk.js.js +20175 -0
- package/lib/aliyun-upload-sdk-1.5.6.min.cjs +0 -6
- package/lib/aliyun-upload-sdk-1.5.6.min.js +0 -1986
- /package/{_virtual/aliyun-oss-sdk.cjs → vendor/ali-oss/dist/aliyun-oss-sdk.js?commonjs-module.cjs} +0 -0
- /package/{_virtual/aliyun-oss-sdk.js → vendor/ali-oss/dist/aliyun-oss-sdk.js?commonjs-module.js} +0 -0
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./src/device.cjs"),o=require("./src/file-operations.cjs"),t=require("./src/media.cjs"),i=require("./src/storage.cjs"),e=require("./src/types.cjs"),s=require("./src/watermark.cjs"),n=require("vue");exports.isMobile=r.isMobile;exports.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./src/device.cjs"),o=require("./src/file-operations.cjs"),t=require("./src/media.cjs"),i=require("./src/storage.cjs"),e=require("./src/types.cjs"),s=require("./src/watermark.cjs"),n=require("vue");exports.isMobile=r.isMobile;exports.VideoUploader=o.VideoUploader;exports.isImageByMimeType=t.isImageByMimeType;exports.initStorage=i.initStorage;exports.useStorage=i.useStorage;exports.isBoolean=e.isBoolean;exports.isElement=e.isElement;exports.isNumber=e.isNumber;exports.isUndefined=e.isUndefined;exports.isWindow=e.isWindow;exports.watermark=s.watermark;Object.defineProperty(exports,"isVNode",{enumerable:!0,get:()=>n.isVNode});
|
package/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { isMobile as r } from "./src/device.js";
|
|
2
|
-
import {
|
|
2
|
+
import { VideoUploader as m } from "./src/file-operations.js";
|
|
3
3
|
import { isImageByMimeType as p } from "./src/media.js";
|
|
4
4
|
import { initStorage as f, useStorage as a } from "./src/storage.js";
|
|
5
5
|
import { isBoolean as d, isElement as n, isNumber as l, isUndefined as g, isWindow as b } from "./src/types.js";
|
|
6
6
|
import { watermark as w } from "./src/watermark.js";
|
|
7
7
|
import { isVNode as B } from "vue";
|
|
8
8
|
export {
|
|
9
|
+
m as VideoUploader,
|
|
9
10
|
f as initStorage,
|
|
10
11
|
d as isBoolean,
|
|
11
12
|
n as isElement,
|
|
@@ -16,6 +17,5 @@ export {
|
|
|
16
17
|
B as isVNode,
|
|
17
18
|
b as isWindow,
|
|
18
19
|
a as useStorage,
|
|
19
|
-
m as videoUploader,
|
|
20
20
|
w as watermark
|
|
21
21
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qxs-bns/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"main": "./index.cjs",
|
|
5
5
|
"module": "./index.js",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -11,9 +11,6 @@
|
|
|
11
11
|
"require": "./index.cjs"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"axios": "^1.7.9"
|
|
16
|
-
},
|
|
17
14
|
"publishConfig": {
|
|
18
15
|
"access": "public",
|
|
19
16
|
"registry": "https://registry.npmjs.org/"
|
package/src/device.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(){const i=navigator.userAgent,n=["Android","iPhone","SymbianOS","Windows Phone","iPad","iPod"];let t=!1;for(let e=0;e<n.length;e++)if(i.indexOf(n[e])>0){t=!0;break}return t}exports.isMobile=o;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(){if(typeof navigator!="undefined"){const i=navigator.userAgent,n=["Android","iPhone","SymbianOS","Windows Phone","iPad","iPod"];let t=!1;for(let e=0;e<n.length;e++)if(i.indexOf(n[e])>0){t=!0;break}return t}return"确保在浏览器环境中"}exports.isMobile=o;
|
package/src/device.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
function o() {
|
|
2
|
+
if (typeof navigator != "undefined") {
|
|
3
|
+
const i = navigator.userAgent, n = [
|
|
4
|
+
"Android",
|
|
5
|
+
"iPhone",
|
|
6
|
+
"SymbianOS",
|
|
7
|
+
"Windows Phone",
|
|
8
|
+
"iPad",
|
|
9
|
+
"iPod"
|
|
10
|
+
];
|
|
11
|
+
let t = !1;
|
|
12
|
+
for (let e = 0; e < n.length; e++)
|
|
13
|
+
if (i.indexOf(n[e]) > 0) {
|
|
14
|
+
t = !0;
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
return t;
|
|
18
|
+
}
|
|
19
|
+
return "确保在浏览器环境中";
|
|
17
20
|
}
|
|
18
21
|
export {
|
|
19
|
-
|
|
22
|
+
o as isMobile
|
|
20
23
|
};
|
package/src/file-operations.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var h=Object.defineProperty;var y=(l,d,o)=>d in l?h(l,d,{enumerable:!0,configurable:!0,writable:!0,value:o}):l[d]=o;var w=(l,d,o)=>y(l,typeof d!="symbol"?d+"":d,o);var p=(l,d,o)=>new Promise((r,i)=>{var t=a=>{try{n(o.next(a))}catch(e){i(e)}},s=a=>{try{n(o.throw(a))}catch(e){i(e)}},n=a=>a.done?r(a.value):Promise.resolve(a.value).then(t,s);n((o=o.apply(l,d)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../vendor/ali-oss/dist/aliyun-oss-sdk.js.cjs");let U;function f(){return p(this,null,function*(){window.OSS=S,yield import("../lib/aliyun-upload-sdk-1.5.6.min.js"),U=window.AliyunUpload})}class A{constructor(d){w(this,"uploader");this.initialize(d)}initialize(d){return p(this,null,function*(){if(typeof window=="undefined")throw new TypeError("VideoUploader 只能在浏览器环境中使用");U||(yield f()),this.uploader=new U.Vod({onUploadFailed:d.onUploadFailed,onUploadSucceed:d.onUploadSucceed,onUploadProgress:d.onUploadProgress,onUploadTokenExpired:d.onUploadTokenExpired||(()=>{}),onUploadstarted:o=>p(this,null,function*(){var s;const{uploadAuth:r,uploadAddress:i,videoId:t}=(yield(s=d.onUploadstarted)==null?void 0:s.call(d,o))||{};r&&i&&t&&this.uploader.setUploadAuthAndAddress(o,r,i,t)})})})}upload(d){return new Promise((o,r)=>{if(!this.uploader){r(new Error("请先调用 init 方法初始化上传器"));return}const i=JSON.stringify({Vod:{UserData:{IsShowWaterMark:"false",Priority:"7"}}});this.uploader.addFile(d,null,null,null,i),this.uploader.startUpload();const t=e=>{o({videoId:e.videoId})},s=(e,c,u)=>{r(new Error(u||"上传失败"))},n=this.uploader.onUploadSucceed,a=this.uploader.onUploadFailed;this.uploader.onUploadSucceed=e=>{t(e),n==null||n(e)},this.uploader.onUploadFailed=(e,c,u)=>{s(e,c,u),a==null||a(e,c,u)}})}}exports.VideoUploader=A;
|
package/src/file-operations.js
CHANGED
|
@@ -1,53 +1,59 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
1
|
+
var h = Object.defineProperty;
|
|
2
|
+
var y = (l, d, o) => d in l ? h(l, d, { enumerable: !0, configurable: !0, writable: !0, value: o }) : l[d] = o;
|
|
3
|
+
var w = (l, d, o) => y(l, typeof d != "symbol" ? d + "" : d, o);
|
|
4
|
+
var u = (l, d, o) => new Promise((r, i) => {
|
|
5
|
+
var t = (e) => {
|
|
6
6
|
try {
|
|
7
|
-
|
|
8
|
-
} catch (
|
|
9
|
-
|
|
7
|
+
n(o.next(e));
|
|
8
|
+
} catch (a) {
|
|
9
|
+
i(a);
|
|
10
10
|
}
|
|
11
|
-
},
|
|
11
|
+
}, s = (e) => {
|
|
12
12
|
try {
|
|
13
|
-
|
|
14
|
-
} catch (
|
|
15
|
-
|
|
13
|
+
n(o.throw(e));
|
|
14
|
+
} catch (a) {
|
|
15
|
+
i(a);
|
|
16
16
|
}
|
|
17
|
-
},
|
|
18
|
-
|
|
17
|
+
}, n = (e) => e.done ? r(e.value) : Promise.resolve(e.value).then(t, s);
|
|
18
|
+
n((o = o.apply(l, d)).next());
|
|
19
19
|
});
|
|
20
|
-
import
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
import S from "../vendor/ali-oss/dist/aliyun-oss-sdk.js.js";
|
|
21
|
+
let c;
|
|
22
|
+
function f() {
|
|
23
|
+
return u(this, null, function* () {
|
|
24
|
+
window.OSS = S, yield import("../lib/aliyun-upload-sdk-1.5.6.min.js"), c = window.AliyunUpload;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
class E {
|
|
28
|
+
constructor(d) {
|
|
29
|
+
w(this, "uploader");
|
|
30
|
+
this.initialize(d);
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
return this
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
initialize(d) {
|
|
33
|
+
return u(this, null, function* () {
|
|
34
|
+
if (typeof window == "undefined")
|
|
35
|
+
throw new TypeError("VideoUploader 只能在浏览器环境中使用");
|
|
36
|
+
c || (yield f()), this.uploader = new c.Vod({
|
|
37
|
+
onUploadFailed: d.onUploadFailed,
|
|
38
|
+
onUploadSucceed: d.onUploadSucceed,
|
|
39
|
+
onUploadProgress: d.onUploadProgress,
|
|
40
|
+
onUploadTokenExpired: d.onUploadTokenExpired || (() => {
|
|
41
|
+
}),
|
|
42
|
+
onUploadstarted: (o) => u(this, null, function* () {
|
|
43
|
+
var s;
|
|
44
|
+
const { uploadAuth: r, uploadAddress: i, videoId: t } = (yield (s = d.onUploadstarted) == null ? void 0 : s.call(d, o)) || {};
|
|
45
|
+
r && i && t && this.uploader.setUploadAuthAndAddress(o, r, i, t);
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
});
|
|
43
49
|
}
|
|
44
50
|
upload(d) {
|
|
45
|
-
return new Promise((o,
|
|
51
|
+
return new Promise((o, r) => {
|
|
46
52
|
if (!this.uploader) {
|
|
47
|
-
|
|
53
|
+
r(new Error("请先调用 init 方法初始化上传器"));
|
|
48
54
|
return;
|
|
49
55
|
}
|
|
50
|
-
const
|
|
56
|
+
const i = JSON.stringify({
|
|
51
57
|
Vod: {
|
|
52
58
|
UserData: {
|
|
53
59
|
IsShowWaterMark: "false",
|
|
@@ -55,21 +61,20 @@ class f {
|
|
|
55
61
|
}
|
|
56
62
|
}
|
|
57
63
|
});
|
|
58
|
-
this.uploader.addFile(d, null, null, null,
|
|
59
|
-
const
|
|
60
|
-
o({ videoId:
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
},
|
|
64
|
-
this.uploader.onUploadSucceed = (
|
|
65
|
-
|
|
66
|
-
}, this.uploader.onUploadFailed = (
|
|
67
|
-
|
|
64
|
+
this.uploader.addFile(d, null, null, null, i), this.uploader.startUpload();
|
|
65
|
+
const t = (a) => {
|
|
66
|
+
o({ videoId: a.videoId });
|
|
67
|
+
}, s = (a, U, p) => {
|
|
68
|
+
r(new Error(p || "上传失败"));
|
|
69
|
+
}, n = this.uploader.onUploadSucceed, e = this.uploader.onUploadFailed;
|
|
70
|
+
this.uploader.onUploadSucceed = (a) => {
|
|
71
|
+
t(a), n == null || n(a);
|
|
72
|
+
}, this.uploader.onUploadFailed = (a, U, p) => {
|
|
73
|
+
s(a, U, p), e == null || e(a, U, p);
|
|
68
74
|
};
|
|
69
75
|
});
|
|
70
76
|
}
|
|
71
77
|
}
|
|
72
|
-
const F = new f();
|
|
73
78
|
export {
|
|
74
|
-
|
|
79
|
+
E as VideoUploader
|
|
75
80
|
};
|
package/types/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare function isImageByMimeType(file: File): boolean;
|
|
|
11
11
|
/**
|
|
12
12
|
* 判断是移动端还是pc端
|
|
13
13
|
*/
|
|
14
|
-
export declare function isMobile(): boolean;
|
|
14
|
+
export declare function isMobile(): boolean | "确保在浏览器环境中";
|
|
15
15
|
|
|
16
16
|
export declare const isNumber: (val: any) => val is number;
|
|
17
17
|
|
|
@@ -21,6 +21,11 @@ export { isVNode }
|
|
|
21
21
|
|
|
22
22
|
export declare function isWindow(val: unknown): val is Window;
|
|
23
23
|
|
|
24
|
+
export declare interface IVideoUploader {
|
|
25
|
+
uploader: any;
|
|
26
|
+
upload: (file: File) => Promise<VideoUploadResult>;
|
|
27
|
+
}
|
|
28
|
+
|
|
24
29
|
declare interface SettingsType {
|
|
25
30
|
/** 水印总体的id */
|
|
26
31
|
id?: string;
|
|
@@ -100,15 +105,13 @@ export declare interface UploadInfo {
|
|
|
100
105
|
|
|
101
106
|
export declare const useStorage: typeof Storage_2.getInstance;
|
|
102
107
|
|
|
103
|
-
declare class VideoUploader {
|
|
104
|
-
|
|
105
|
-
constructor();
|
|
106
|
-
|
|
108
|
+
export declare class VideoUploader implements IVideoUploader {
|
|
109
|
+
uploader: any;
|
|
110
|
+
constructor(options: VideoUploadOptions);
|
|
111
|
+
private initialize;
|
|
107
112
|
upload(file: File): Promise<VideoUploadResult>;
|
|
108
113
|
}
|
|
109
114
|
|
|
110
|
-
export declare const videoUploader: VideoUploader;
|
|
111
|
-
|
|
112
115
|
declare interface VideoUploadOptions {
|
|
113
116
|
onUploadFailed?: (uploadInfo: any, code: string, message: string) => void;
|
|
114
117
|
onUploadSucceed?: (uploadInfo: any) => void;
|