doomistorage 1.0.1 → 1.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.
- package/dist/cosfile.d.ts +1 -1
- package/dist/file.js +1 -1
- package/dist/filehelper.d.ts +11 -1
- package/dist/filehelper.js +18 -0
- package/package.json +1 -1
- package/src/cosfile.ts +1 -3
- package/src/file.ts +1 -1
- package/src/filehelper.ts +55 -37
package/dist/cosfile.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare class CosFile extends FileBase {
|
|
|
22
22
|
* @param userInfo
|
|
23
23
|
* @returns
|
|
24
24
|
*/
|
|
25
|
-
saveFileStream(file: any, fileName: any, saveOption:
|
|
25
|
+
saveFileStream(file: any, fileName: any, saveOption: FileConfig, userInfo: any): Promise<FileResult>;
|
|
26
26
|
/**
|
|
27
27
|
* 删除指定位置的文件
|
|
28
28
|
* @param filepath
|
package/dist/file.js
CHANGED
|
@@ -17,7 +17,7 @@ class FileBase {
|
|
|
17
17
|
*/
|
|
18
18
|
getSaveFileName(saveOption, fileName, userInfo = {}) {
|
|
19
19
|
let saveFolder = this.getSaveFolder(saveOption, userInfo);
|
|
20
|
-
console.log('getSaveFileName', fileName)
|
|
20
|
+
// console.log('getSaveFileName', fileName)
|
|
21
21
|
let _fileName = this.getSaveOnlyFileName(saveOption, fileName, userInfo);
|
|
22
22
|
return path_1.default.join(saveFolder, _fileName);
|
|
23
23
|
}
|
package/dist/filehelper.d.ts
CHANGED
|
@@ -44,6 +44,16 @@ declare class FileUtility {
|
|
|
44
44
|
* @param filePath
|
|
45
45
|
*/
|
|
46
46
|
DeleteFile(filePath: string | string[]): void;
|
|
47
|
+
/**
|
|
48
|
+
* 批量下载指定的文件并上传到存储中
|
|
49
|
+
* 替代原来file中的对应方法save2localForRemoteImage
|
|
50
|
+
* 用于百度UEditor的保存文件
|
|
51
|
+
* @param urlArray
|
|
52
|
+
* @param saveOption
|
|
53
|
+
* @param userInfo
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
BatchDownloadImage(urlArray: string[], saveOption: FileConfig, userInfo?: any): Promise<FileResult[]>;
|
|
47
57
|
/**
|
|
48
58
|
* 下载文件并且保存
|
|
49
59
|
* @param saveDestination
|
|
@@ -53,7 +63,7 @@ declare class FileUtility {
|
|
|
53
63
|
* @param allowWebPFormat
|
|
54
64
|
* @returns
|
|
55
65
|
*/
|
|
56
|
-
DownloadFile(fileUrl: string, savefileName: string, savesetting: FileConfig, userInfo?: any, allowWebPFormat?: boolean): Promise<FileResult>;
|
|
66
|
+
DownloadFile(fileUrl: string, savefileName: string | null, savesetting: FileConfig, userInfo?: any, allowWebPFormat?: boolean): Promise<FileResult>;
|
|
57
67
|
/**
|
|
58
68
|
* 预测生成文件保存后的文件路径
|
|
59
69
|
* @param saveOption
|
package/dist/filehelper.js
CHANGED
|
@@ -84,6 +84,24 @@ class FileUtility {
|
|
|
84
84
|
DeleteFile(filePath) {
|
|
85
85
|
this.fileHandler.deleteFile(filePath);
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* 批量下载指定的文件并上传到存储中
|
|
89
|
+
* 替代原来file中的对应方法save2localForRemoteImage
|
|
90
|
+
* 用于百度UEditor的保存文件
|
|
91
|
+
* @param urlArray
|
|
92
|
+
* @param saveOption
|
|
93
|
+
* @param userInfo
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
BatchDownloadImage(urlArray, saveOption, userInfo = {}) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
let promiseArr = [];
|
|
99
|
+
for (const url of urlArray) {
|
|
100
|
+
promiseArr.push(this.DownloadFile(url, null, saveOption, userInfo));
|
|
101
|
+
}
|
|
102
|
+
return yield Promise.all(promiseArr);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
87
105
|
/**
|
|
88
106
|
* 下载文件并且保存
|
|
89
107
|
* @param saveDestination
|
package/package.json
CHANGED
package/src/cosfile.ts
CHANGED
|
@@ -3,8 +3,6 @@ import { FileBase } from "./file";
|
|
|
3
3
|
import COS from 'cos-nodejs-sdk-v5';
|
|
4
4
|
|
|
5
5
|
export class CosFile extends FileBase {
|
|
6
|
-
|
|
7
|
-
|
|
8
6
|
private bucket: string; ///存储桶名称
|
|
9
7
|
private cos: COS; ///腾讯云COS对象
|
|
10
8
|
private region: string; ///存储桶所在的地区
|
|
@@ -49,7 +47,7 @@ export class CosFile extends FileBase {
|
|
|
49
47
|
* @param userInfo
|
|
50
48
|
* @returns
|
|
51
49
|
*/
|
|
52
|
-
async saveFileStream(file: any, fileName: any, saveOption:
|
|
50
|
+
async saveFileStream(file: any, fileName: any, saveOption: FileConfig, userInfo: any): Promise<FileResult> {
|
|
53
51
|
const destinationFileName = this.getSaveFileName(saveOption, fileName, userInfo);
|
|
54
52
|
return new Promise((resolve) => {
|
|
55
53
|
if (saveOption.reRead) {
|
package/src/file.ts
CHANGED
|
@@ -12,7 +12,7 @@ export abstract class FileBase {
|
|
|
12
12
|
*/
|
|
13
13
|
getSaveFileName(saveOption: FileConfig, fileName:string, userInfo:any = {}):string {
|
|
14
14
|
let saveFolder = this.getSaveFolder(saveOption,userInfo)
|
|
15
|
-
console.log('getSaveFileName', fileName)
|
|
15
|
+
// console.log('getSaveFileName', fileName)
|
|
16
16
|
let _fileName = this.getSaveOnlyFileName(saveOption, fileName, userInfo);
|
|
17
17
|
return path.join(saveFolder, _fileName);
|
|
18
18
|
}
|
package/src/filehelper.ts
CHANGED
|
@@ -18,12 +18,12 @@ export type FileProviderEnum = typeof FileProviderEnum[keyof typeof FileProvider
|
|
|
18
18
|
* @param destination
|
|
19
19
|
* @returns
|
|
20
20
|
*/
|
|
21
|
-
export function FileHelper(provider: FileProviderEnum, apiOption?:any): FileUtility {
|
|
22
|
-
let filehandler:FileBase
|
|
21
|
+
export function FileHelper(provider: FileProviderEnum, apiOption?: any): FileUtility {
|
|
22
|
+
let filehandler: FileBase
|
|
23
23
|
switch (provider) {
|
|
24
|
-
case FileProviderEnum.LOCAL: filehandler =
|
|
25
|
-
case FileProviderEnum.TENCENTCOS: filehandler =
|
|
26
|
-
default: filehandler =
|
|
24
|
+
case FileProviderEnum.LOCAL: filehandler = new LocalFile(); break;
|
|
25
|
+
case FileProviderEnum.TENCENTCOS: filehandler = new CosFile(apiOption); break;
|
|
26
|
+
default: filehandler = new LocalFile();
|
|
27
27
|
}
|
|
28
28
|
return new FileUtility(filehandler)
|
|
29
29
|
}
|
|
@@ -32,7 +32,7 @@ export function FileHelper(provider: FileProviderEnum, apiOption?:any): FileUtil
|
|
|
32
32
|
/**
|
|
33
33
|
* 文件帮助工具
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
class FileUtility {
|
|
36
36
|
private fileHandler: FileBase;
|
|
37
37
|
constructor(handler: FileBase) {
|
|
38
38
|
this.fileHandler = handler;
|
|
@@ -53,7 +53,7 @@ export function FileHelper(provider: FileProviderEnum, apiOption?:any): FileUtil
|
|
|
53
53
|
userInfo: any = {}): Promise<FileResult> {
|
|
54
54
|
return await this.fileHandler.saveFileStream(file, fileName, saveOption, userInfo);
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
|
|
57
57
|
/**
|
|
58
58
|
* 保存字符流到对应的存储设备
|
|
59
59
|
* @param bufferData
|
|
@@ -67,15 +67,31 @@ export function FileHelper(provider: FileProviderEnum, apiOption?:any): FileUtil
|
|
|
67
67
|
fileName: string,
|
|
68
68
|
saveOption: FileConfig,
|
|
69
69
|
userInfo: any = {}): Promise<FileResult> {
|
|
70
|
-
return await this.fileHandler.saveString2File(bufferData,fileName,
|
|
70
|
+
return await this.fileHandler.saveString2File(bufferData, fileName, saveOption, userInfo);
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* 删除指定位置的文件
|
|
74
74
|
* @param filePath
|
|
75
75
|
*/
|
|
76
|
-
DeleteFile(filePath:string|string[]):void{
|
|
76
|
+
DeleteFile(filePath: string | string[]): void {
|
|
77
77
|
this.fileHandler.deleteFile(filePath);
|
|
78
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* 批量下载指定的文件并上传到存储中
|
|
81
|
+
* 替代原来file中的对应方法save2localForRemoteImage
|
|
82
|
+
* 用于百度UEditor的保存文件
|
|
83
|
+
* @param urlArray
|
|
84
|
+
* @param saveOption
|
|
85
|
+
* @param userInfo
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
async BatchDownloadImage(urlArray: string[], saveOption: FileConfig, userInfo: any = {}): Promise<FileResult[]> {
|
|
89
|
+
let promiseArr = [];
|
|
90
|
+
for (const url of urlArray) {
|
|
91
|
+
promiseArr.push(this.DownloadFile(url, null, saveOption, userInfo))
|
|
92
|
+
}
|
|
93
|
+
return await Promise.all(promiseArr);
|
|
94
|
+
}
|
|
79
95
|
/**
|
|
80
96
|
* 下载文件并且保存
|
|
81
97
|
* @param saveDestination
|
|
@@ -85,17 +101,17 @@ export function FileHelper(provider: FileProviderEnum, apiOption?:any): FileUtil
|
|
|
85
101
|
* @param allowWebPFormat
|
|
86
102
|
* @returns
|
|
87
103
|
*/
|
|
88
|
-
async DownloadFile(fileUrl: string, savefileName:string, savesetting: FileConfig, userInfo: any = {}, allowWebPFormat = false): Promise<FileResult> {
|
|
104
|
+
async DownloadFile(fileUrl: string, savefileName: string | null, savesetting: FileConfig, userInfo: any = {}, allowWebPFormat = false): Promise<FileResult> {
|
|
89
105
|
if (!allowWebPFormat && fileUrl.indexOf('&tp=webp') >= 0) fileUrl = fileUrl.replace('&tp=webp', '');
|
|
90
|
-
let fileName = savefileName ?savefileName:path.basename(fileUrl);
|
|
91
|
-
try{
|
|
106
|
+
let fileName = savefileName ? savefileName : path.basename(fileUrl);
|
|
107
|
+
try {
|
|
92
108
|
const downloadResult = await axios.get(fileUrl, { responseType: 'arraybuffer' });
|
|
93
|
-
if (downloadResult.data){
|
|
94
|
-
return this.SaveString2File(downloadResult.data, fileName, savesetting,userInfo);
|
|
109
|
+
if (downloadResult.data) {
|
|
110
|
+
return this.SaveString2File(downloadResult.data, fileName, savesetting, userInfo);
|
|
95
111
|
}
|
|
96
112
|
return { successed: false, error: '下载文件中没有任何内容' }
|
|
97
|
-
}catch(error:any){
|
|
98
|
-
return { successed: false, error: error}
|
|
113
|
+
} catch (error: any) {
|
|
114
|
+
return { successed: false, error: error }
|
|
99
115
|
}
|
|
100
116
|
}
|
|
101
117
|
/**
|
|
@@ -104,26 +120,28 @@ export function FileHelper(provider: FileProviderEnum, apiOption?:any): FileUtil
|
|
|
104
120
|
* @param fileName
|
|
105
121
|
* @param userInfo
|
|
106
122
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
123
|
+
getSaveFileName(saveOption: FileConfig, fileName: string, userInfo: any = {}): string {
|
|
124
|
+
return this.fileHandler.getSaveFileName(saveOption, fileName, userInfo);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 预测生成文件保存后的文件路径
|
|
129
|
+
* @param saveOption
|
|
130
|
+
* @param fileName
|
|
131
|
+
* @param userInfo
|
|
132
|
+
*/
|
|
133
|
+
getSaveFolder(saveOption: FileConfig, userInfo: any = {}): string {
|
|
134
|
+
return this.fileHandler.getSaveFolder(saveOption, userInfo);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 预测生成文件保存后的文件名称
|
|
138
|
+
* @param saveOption
|
|
139
|
+
* @param fileName
|
|
140
|
+
* @param userInfo
|
|
141
|
+
*/
|
|
142
|
+
getSaveOnlyFileName(saveOption: FileConfig, fileName: string, userInfo: any = {}): string {
|
|
143
|
+
return this.fileHandler.getSaveOnlyFileName(saveOption, fileName, userInfo);
|
|
144
|
+
}
|
|
145
|
+
|
|
110
146
|
|
|
111
|
-
/**
|
|
112
|
-
* 预测生成文件保存后的文件路径
|
|
113
|
-
* @param saveOption
|
|
114
|
-
* @param fileName
|
|
115
|
-
* @param userInfo
|
|
116
|
-
*/
|
|
117
|
-
getSaveFolder(saveOption: FileConfig, userInfo: any = {}): string {
|
|
118
|
-
return this.fileHandler.getSaveFolder(saveOption, userInfo);
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* 预测生成文件保存后的文件名称
|
|
122
|
-
* @param saveOption
|
|
123
|
-
* @param fileName
|
|
124
|
-
* @param userInfo
|
|
125
|
-
*/
|
|
126
|
-
getSaveOnlyFileName(saveOption: FileConfig, fileName: string, userInfo: any = {}): string {
|
|
127
|
-
return this.fileHandler.getSaveOnlyFileName(saveOption,fileName,userInfo);
|
|
128
|
-
}
|
|
129
147
|
}
|