@qxs-bns/utils 0.0.1 → 0.0.3

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.
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}exports.commonjsRequire=o;
@@ -0,0 +1,6 @@
1
+ function r(o) {
2
+ throw new Error('Could not dynamically require "' + o + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
3
+ }
4
+ export {
5
+ r as commonjsRequire
6
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}exports.getDefaultExportFromCjs=e;
@@ -0,0 +1,6 @@
1
+ function e(t) {
2
+ return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
3
+ }
4
+ export {
5
+ e as getDefaultExportFromCjs
6
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={exports:{}};exports.__module=e;
@@ -0,0 +1,4 @@
1
+ var s = { exports: {} };
2
+ export {
3
+ s as __module
4
+ };
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./src/device.cjs"),t=require("./src/media.cjs"),i=require("./src/storage.cjs"),e=require("./src/types.cjs"),s=require("./src/watermark.cjs"),o=require("vue");exports.isMobile=r.isMobile;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:()=>o.isVNode});
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,19 +1,21 @@
1
1
  import { isMobile as r } from "./src/device.js";
2
- import { isImageByMimeType as m } from "./src/media.js";
3
- import { initStorage as s, useStorage as f } from "./src/storage.js";
4
- import { isBoolean as a, isElement as n, isNumber as x, isUndefined as d, isWindow as g } from "./src/types.js";
5
- import { watermark as b } from "./src/watermark.js";
6
- import { isVNode as w } from "vue";
2
+ import { VideoUploader as m } from "./src/file-operations.js";
3
+ import { isImageByMimeType as p } from "./src/media.js";
4
+ import { initStorage as f, useStorage as a } from "./src/storage.js";
5
+ import { isBoolean as d, isElement as n, isNumber as l, isUndefined as g, isWindow as b } from "./src/types.js";
6
+ import { watermark as w } from "./src/watermark.js";
7
+ import { isVNode as B } from "vue";
7
8
  export {
8
- s as initStorage,
9
- a as isBoolean,
9
+ m as VideoUploader,
10
+ f as initStorage,
11
+ d as isBoolean,
10
12
  n as isElement,
11
- m as isImageByMimeType,
13
+ p as isImageByMimeType,
12
14
  r as isMobile,
13
- x as isNumber,
14
- d as isUndefined,
15
- w as isVNode,
16
- g as isWindow,
17
- f as useStorage,
18
- b as watermark
15
+ l as isNumber,
16
+ g as isUndefined,
17
+ B as isVNode,
18
+ b as isWindow,
19
+ a as useStorage,
20
+ w as watermark
19
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qxs-bns/utils",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "main": "./index.cjs",
5
5
  "module": "./index.js",
6
6
  "types": "./types/index.d.ts",
@@ -11,6 +11,9 @@
11
11
  "require": "./index.cjs"
12
12
  }
13
13
  },
14
+ "dependencies": {
15
+ "axios": "^1.7.9"
16
+ },
14
17
  "publishConfig": {
15
18
  "access": "public",
16
19
  "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 i() {
2
- const t = navigator.userAgent, n = [
3
- "Android",
4
- "iPhone",
5
- "SymbianOS",
6
- "Windows Phone",
7
- "iPad",
8
- "iPod"
9
- ];
10
- let o = !1;
11
- for (let e = 0; e < n.length; e++)
12
- if (t.indexOf(n[e]) > 0) {
13
- o = !0;
14
- break;
15
- }
16
- return o;
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
- i as isMobile
22
+ o as isMobile
20
23
  };
@@ -0,0 +1 @@
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("../node_modules/.pnpm/ali-oss@6.22.0/node_modules/ali-oss/dist/aliyun-oss-sdk.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;
@@ -0,0 +1,80 @@
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
+ try {
7
+ n(o.next(e));
8
+ } catch (a) {
9
+ i(a);
10
+ }
11
+ }, s = (e) => {
12
+ try {
13
+ n(o.throw(e));
14
+ } catch (a) {
15
+ i(a);
16
+ }
17
+ }, n = (e) => e.done ? r(e.value) : Promise.resolve(e.value).then(t, s);
18
+ n((o = o.apply(l, d)).next());
19
+ });
20
+ import S from "../node_modules/.pnpm/ali-oss@6.22.0/node_modules/ali-oss/dist/aliyun-oss-sdk.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);
31
+ }
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
+ });
49
+ }
50
+ upload(d) {
51
+ return new Promise((o, r) => {
52
+ if (!this.uploader) {
53
+ r(new Error("请先调用 init 方法初始化上传器"));
54
+ return;
55
+ }
56
+ const i = JSON.stringify({
57
+ Vod: {
58
+ UserData: {
59
+ IsShowWaterMark: "false",
60
+ Priority: "7"
61
+ }
62
+ }
63
+ });
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);
74
+ };
75
+ });
76
+ }
77
+ }
78
+ export {
79
+ E as VideoUploader
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;
@@ -93,11 +98,48 @@ declare class Storage_2 {
93
98
  };
94
99
  }
95
100
 
101
+ export declare interface UploadInfo {
102
+ file: File;
103
+ videoId?: string;
104
+ }
105
+
96
106
  export declare const useStorage: typeof Storage_2.getInstance;
97
107
 
108
+ export declare class VideoUploader implements IVideoUploader {
109
+ uploader: any;
110
+ constructor(options: VideoUploadOptions);
111
+ private initialize;
112
+ upload(file: File): Promise<VideoUploadResult>;
113
+ }
114
+
115
+ declare interface VideoUploadOptions {
116
+ onUploadFailed?: (uploadInfo: any, code: string, message: string) => void;
117
+ onUploadSucceed?: (uploadInfo: any) => void;
118
+ onUploadProgress?: (uploadInfo: UploadInfo, totalSize: number, percent: number) => void;
119
+ onUploadTokenExpired?: (response: any) => void;
120
+ onUploadstarted?: (uploadInfo: UploadInfo) => Promise<{
121
+ uploadAuth: string;
122
+ uploadAddress: string;
123
+ videoId: string;
124
+ }>;
125
+ }
126
+
127
+ declare interface VideoUploadResult {
128
+ videoId: string;
129
+ }
130
+
98
131
  export declare function watermark(): {
99
132
  addMark: (settings: Partial<SettingsType>) => void;
100
133
  removeMark: () => void;
101
134
  };
102
135
 
103
136
  export { }
137
+
138
+
139
+ declare global {
140
+ interface Window {
141
+ AliyunUpload: any;
142
+ OSS: typeof OSS;
143
+ }
144
+ }
145
+