@blocklet/uploader-server 0.1.73 → 0.1.74
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/es/utils.d.ts +15 -2
- package/es/utils.js +10 -5
- package/lib/utils.d.ts +15 -2
- package/lib/utils.js +10 -5
- package/package.json +1 -1
package/es/utils.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import type { Method } from 'axios';
|
|
2
|
+
type CallComponentOptions<D = any, P = any> = {
|
|
3
|
+
name?: string;
|
|
4
|
+
method?: Method;
|
|
5
|
+
path: string;
|
|
6
|
+
data?: D;
|
|
7
|
+
params?: P;
|
|
8
|
+
headers?: {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
1
12
|
export declare function getTrustedDomainsCache({ forceUpdate, ttl, }?: {
|
|
2
13
|
forceUpdate?: boolean;
|
|
3
14
|
ttl?: number;
|
|
@@ -6,9 +17,11 @@ export declare function checkTrustedReferer(req: any, res: any, next?: Function)
|
|
|
6
17
|
export declare function proxyImageDownload(req: any, res: any, next?: Function): Promise<void>;
|
|
7
18
|
export declare function setPDFDownloadHeader(req: any, res: any): void;
|
|
8
19
|
export declare const getFileHash: (filePath: string, maxBytes?: number) => Promise<any>;
|
|
9
|
-
export declare function uploadToMediaKit({ filePath, fileName, base64, }: {
|
|
20
|
+
export declare function uploadToMediaKit({ filePath, fileName, base64, extraComponentCallOptions, }: {
|
|
10
21
|
filePath?: string;
|
|
11
22
|
fileName?: string;
|
|
12
23
|
base64?: string;
|
|
13
|
-
|
|
24
|
+
extraComponentCallOptions?: CallComponentOptions;
|
|
25
|
+
}): Promise<import("axios").AxiosResponse<import("http").IncomingMessage, any> | undefined>;
|
|
14
26
|
export declare function getMediaKitFileStream(filePath: string): Promise<import("axios").AxiosResponse<import("http").IncomingMessage, any>>;
|
|
27
|
+
export {};
|
package/es/utils.js
CHANGED
|
@@ -8,6 +8,7 @@ import { createReadStream } from "fs";
|
|
|
8
8
|
import crypto from "crypto";
|
|
9
9
|
import { getSignData } from "@blocklet/sdk/lib/util/verify-sign";
|
|
10
10
|
import FormData from "form-data";
|
|
11
|
+
import omit from "lodash/omit";
|
|
11
12
|
const DEFAULT_TTL = 5 * 60 * 1e3;
|
|
12
13
|
const appUrl = process.env.BLOCKLET_APP_URL || "";
|
|
13
14
|
const trustedDomainsCache = {
|
|
@@ -100,7 +101,8 @@ export const getFileHash = async (filePath, maxBytes = 5 * 1024 * 1024) => {
|
|
|
100
101
|
export async function uploadToMediaKit({
|
|
101
102
|
filePath,
|
|
102
103
|
fileName,
|
|
103
|
-
base64
|
|
104
|
+
base64,
|
|
105
|
+
extraComponentCallOptions
|
|
104
106
|
}) {
|
|
105
107
|
if (!filePath && !base64) {
|
|
106
108
|
throw new Error("filePath or base64 is required");
|
|
@@ -115,7 +117,8 @@ export async function uploadToMediaKit({
|
|
|
115
117
|
data: {
|
|
116
118
|
base64,
|
|
117
119
|
filename: fileName
|
|
118
|
-
}
|
|
120
|
+
},
|
|
121
|
+
...omit(extraComponentCallOptions, ["name", "path", "data"])
|
|
119
122
|
});
|
|
120
123
|
return res;
|
|
121
124
|
}
|
|
@@ -140,9 +143,11 @@ export async function uploadToMediaKit({
|
|
|
140
143
|
},
|
|
141
144
|
method: "POST",
|
|
142
145
|
url: "/api/sdk/uploads",
|
|
143
|
-
params: {}
|
|
144
|
-
}).sig
|
|
145
|
-
|
|
146
|
+
params: extraComponentCallOptions?.params || {}
|
|
147
|
+
}).sig,
|
|
148
|
+
...extraComponentCallOptions?.headers
|
|
149
|
+
},
|
|
150
|
+
...omit(extraComponentCallOptions, ["name", "path", "data", "headers"])
|
|
146
151
|
},
|
|
147
152
|
{
|
|
148
153
|
retries: 0
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import type { Method } from 'axios';
|
|
2
|
+
type CallComponentOptions<D = any, P = any> = {
|
|
3
|
+
name?: string;
|
|
4
|
+
method?: Method;
|
|
5
|
+
path: string;
|
|
6
|
+
data?: D;
|
|
7
|
+
params?: P;
|
|
8
|
+
headers?: {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
1
12
|
export declare function getTrustedDomainsCache({ forceUpdate, ttl, }?: {
|
|
2
13
|
forceUpdate?: boolean;
|
|
3
14
|
ttl?: number;
|
|
@@ -6,9 +17,11 @@ export declare function checkTrustedReferer(req: any, res: any, next?: Function)
|
|
|
6
17
|
export declare function proxyImageDownload(req: any, res: any, next?: Function): Promise<void>;
|
|
7
18
|
export declare function setPDFDownloadHeader(req: any, res: any): void;
|
|
8
19
|
export declare const getFileHash: (filePath: string, maxBytes?: number) => Promise<any>;
|
|
9
|
-
export declare function uploadToMediaKit({ filePath, fileName, base64, }: {
|
|
20
|
+
export declare function uploadToMediaKit({ filePath, fileName, base64, extraComponentCallOptions, }: {
|
|
10
21
|
filePath?: string;
|
|
11
22
|
fileName?: string;
|
|
12
23
|
base64?: string;
|
|
13
|
-
|
|
24
|
+
extraComponentCallOptions?: CallComponentOptions;
|
|
25
|
+
}): Promise<import("axios").AxiosResponse<import("http").IncomingMessage, any> | undefined>;
|
|
14
26
|
export declare function getMediaKitFileStream(filePath: string): Promise<import("axios").AxiosResponse<import("http").IncomingMessage, any>>;
|
|
27
|
+
export {};
|
package/lib/utils.js
CHANGED
|
@@ -20,6 +20,7 @@ var _fs = require("fs");
|
|
|
20
20
|
var _crypto = _interopRequireDefault(require("crypto"));
|
|
21
21
|
var _verifySign = require("@blocklet/sdk/lib/util/verify-sign");
|
|
22
22
|
var _formData = _interopRequireDefault(require("form-data"));
|
|
23
|
+
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
23
24
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
24
25
|
const DEFAULT_TTL = 5 * 60 * 1e3;
|
|
25
26
|
const appUrl = process.env.BLOCKLET_APP_URL || "";
|
|
@@ -120,7 +121,8 @@ exports.getFileHash = getFileHash;
|
|
|
120
121
|
async function uploadToMediaKit({
|
|
121
122
|
filePath,
|
|
122
123
|
fileName,
|
|
123
|
-
base64
|
|
124
|
+
base64,
|
|
125
|
+
extraComponentCallOptions
|
|
124
126
|
}) {
|
|
125
127
|
if (!filePath && !base64) {
|
|
126
128
|
throw new Error("filePath or base64 is required");
|
|
@@ -135,7 +137,8 @@ async function uploadToMediaKit({
|
|
|
135
137
|
data: {
|
|
136
138
|
base64,
|
|
137
139
|
filename: fileName
|
|
138
|
-
}
|
|
140
|
+
},
|
|
141
|
+
...(0, _omit.default)(extraComponentCallOptions, ["name", "path", "data"])
|
|
139
142
|
});
|
|
140
143
|
return res;
|
|
141
144
|
}
|
|
@@ -159,9 +162,11 @@ async function uploadToMediaKit({
|
|
|
159
162
|
},
|
|
160
163
|
method: "POST",
|
|
161
164
|
url: "/api/sdk/uploads",
|
|
162
|
-
params: {}
|
|
163
|
-
}).sig
|
|
164
|
-
|
|
165
|
+
params: extraComponentCallOptions?.params || {}
|
|
166
|
+
}).sig,
|
|
167
|
+
...extraComponentCallOptions?.headers
|
|
168
|
+
},
|
|
169
|
+
...(0, _omit.default)(extraComponentCallOptions, ["name", "path", "data", "headers"])
|
|
165
170
|
}, {
|
|
166
171
|
retries: 0
|
|
167
172
|
});
|