@qxs-bns/utils 0.0.1 → 0.0.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qxs-bns/utils",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
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/"
@@ -0,0 +1 @@
1
+ "use strict";var w=Object.defineProperty;var S=(a,d,e)=>d in a?w(a,d,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[d]=e;var c=(a,d,e)=>S(a,typeof d!="symbol"?d+"":d,e);var U=(a,d,e)=>new Promise((l,n)=>{var s=r=>{try{t(e.next(r))}catch(o){n(o)}},u=r=>{try{t(e.throw(r))}catch(o){n(o)}},t=r=>r.done?l(r.value):Promise.resolve(r.value).then(s,u);t((e=e.apply(a,d)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("../node_modules/.pnpm/ali-oss@6.22.0/node_modules/ali-oss/dist/aliyun-oss-sdk.cjs");require("../lib/aliyun-upload-sdk-1.5.6.min.cjs");window.OSS=y;const h=window.AliyunUpload;class A{constructor(){c(this,"uploader");if(!h)throw new Error("请先引入阿里云上传SDK")}init(d){return this.uploader=new h.Vod({onUploadFailed:d.onUploadFailed,onUploadSucceed:d.onUploadSucceed,onUploadProgress:d.onUploadProgress,onUploadTokenExpired:d.onUploadTokenExpired||(()=>{}),onUploadstarted:e=>U(this,null,function*(){var u;const{uploadAuth:l,uploadAddress:n,videoId:s}=(yield(u=d.onUploadstarted)==null?void 0:u.call(d,e))||{};l&&n&&s&&this.uploader.setUploadAuthAndAddress(e,l,n,s)})}),this.uploader}upload(d){return new Promise((e,l)=>{if(!this.uploader){l(new Error("请先调用 init 方法初始化上传器"));return}const n=JSON.stringify({Vod:{UserData:{IsShowWaterMark:"false",Priority:"7"}}});this.uploader.addFile(d,null,null,null,n),this.uploader.startUpload();const s=o=>{e({videoId:o.videoId})},u=(o,p,i)=>{l(new Error(i||"上传失败"))},t=this.uploader.onUploadSucceed,r=this.uploader.onUploadFailed;this.uploader.onUploadSucceed=o=>{s(o),t==null||t(o)},this.uploader.onUploadFailed=(o,p,i)=>{u(o,p,i),r==null||r(o,p,i)}})}}const v=new A;exports.videoUploader=v;
@@ -0,0 +1,75 @@
1
+ var w = Object.defineProperty;
2
+ var S = (a, d, o) => d in a ? w(a, d, { enumerable: !0, configurable: !0, writable: !0, value: o }) : a[d] = o;
3
+ var U = (a, d, o) => S(a, typeof d != "symbol" ? d + "" : d, o);
4
+ var c = (a, d, o) => new Promise((l, n) => {
5
+ var s = (r) => {
6
+ try {
7
+ t(o.next(r));
8
+ } catch (e) {
9
+ n(e);
10
+ }
11
+ }, p = (r) => {
12
+ try {
13
+ t(o.throw(r));
14
+ } catch (e) {
15
+ n(e);
16
+ }
17
+ }, t = (r) => r.done ? l(r.value) : Promise.resolve(r.value).then(s, p);
18
+ t((o = o.apply(a, d)).next());
19
+ });
20
+ import A from "../node_modules/.pnpm/ali-oss@6.22.0/node_modules/ali-oss/dist/aliyun-oss-sdk.js";
21
+ import "../lib/aliyun-upload-sdk-1.5.6.min.js";
22
+ window.OSS = A;
23
+ const h = window.AliyunUpload;
24
+ class f {
25
+ constructor() {
26
+ U(this, "uploader");
27
+ if (!h)
28
+ throw new Error("请先引入阿里云上传SDK");
29
+ }
30
+ init(d) {
31
+ return this.uploader = new h.Vod({
32
+ onUploadFailed: d.onUploadFailed,
33
+ onUploadSucceed: d.onUploadSucceed,
34
+ onUploadProgress: d.onUploadProgress,
35
+ onUploadTokenExpired: d.onUploadTokenExpired || (() => {
36
+ }),
37
+ onUploadstarted: (o) => c(this, null, function* () {
38
+ var p;
39
+ const { uploadAuth: l, uploadAddress: n, videoId: s } = (yield (p = d.onUploadstarted) == null ? void 0 : p.call(d, o)) || {};
40
+ l && n && s && this.uploader.setUploadAuthAndAddress(o, l, n, s);
41
+ })
42
+ }), this.uploader;
43
+ }
44
+ upload(d) {
45
+ return new Promise((o, l) => {
46
+ if (!this.uploader) {
47
+ l(new Error("请先调用 init 方法初始化上传器"));
48
+ return;
49
+ }
50
+ const n = JSON.stringify({
51
+ Vod: {
52
+ UserData: {
53
+ IsShowWaterMark: "false",
54
+ Priority: "7"
55
+ }
56
+ }
57
+ });
58
+ this.uploader.addFile(d, null, null, null, n), this.uploader.startUpload();
59
+ const s = (e) => {
60
+ o({ videoId: e.videoId });
61
+ }, p = (e, i, u) => {
62
+ l(new Error(u || "上传失败"));
63
+ }, t = this.uploader.onUploadSucceed, r = this.uploader.onUploadFailed;
64
+ this.uploader.onUploadSucceed = (e) => {
65
+ s(e), t == null || t(e);
66
+ }, this.uploader.onUploadFailed = (e, i, u) => {
67
+ p(e, i, u), r == null || r(e, i, u);
68
+ };
69
+ });
70
+ }
71
+ }
72
+ const F = new f();
73
+ export {
74
+ F as videoUploader
75
+ };
package/types/index.d.ts CHANGED
@@ -93,11 +93,50 @@ declare class Storage_2 {
93
93
  };
94
94
  }
95
95
 
96
+ export declare interface UploadInfo {
97
+ file: File;
98
+ videoId?: string;
99
+ }
100
+
96
101
  export declare const useStorage: typeof Storage_2.getInstance;
97
102
 
103
+ declare class VideoUploader {
104
+ private uploader;
105
+ constructor();
106
+ init(options: VideoUploadOptions): any;
107
+ upload(file: File): Promise<VideoUploadResult>;
108
+ }
109
+
110
+ export declare const videoUploader: VideoUploader;
111
+
112
+ declare interface VideoUploadOptions {
113
+ onUploadFailed?: (uploadInfo: any, code: string, message: string) => void;
114
+ onUploadSucceed?: (uploadInfo: any) => void;
115
+ onUploadProgress?: (uploadInfo: UploadInfo, totalSize: number, percent: number) => void;
116
+ onUploadTokenExpired?: (response: any) => void;
117
+ onUploadstarted?: (uploadInfo: UploadInfo) => Promise<{
118
+ uploadAuth: string;
119
+ uploadAddress: string;
120
+ videoId: string;
121
+ }>;
122
+ }
123
+
124
+ declare interface VideoUploadResult {
125
+ videoId: string;
126
+ }
127
+
98
128
  export declare function watermark(): {
99
129
  addMark: (settings: Partial<SettingsType>) => void;
100
130
  removeMark: () => void;
101
131
  };
102
132
 
103
133
  export { }
134
+
135
+
136
+ declare global {
137
+ interface Window {
138
+ AliyunUpload: any;
139
+ OSS: typeof OSS;
140
+ }
141
+ }
142
+