@resolveio/server-lib 5.2.6 → 5.2.8
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/methods/aws.js +24 -13
- package/methods/pdf.js +58 -0
- package/package.json +1 -1
package/methods/aws.js
CHANGED
|
@@ -63,23 +63,34 @@ function loadAWSMethods(methodManager) {
|
|
|
63
63
|
}
|
|
64
64
|
}),
|
|
65
65
|
function: function (fileName, fileData, fileSize, fileOrder, fileType) {
|
|
66
|
+
var _this = this;
|
|
66
67
|
var that = this;
|
|
67
68
|
return new Promise(function (resolve, reject) {
|
|
68
69
|
if (fileName) {
|
|
69
70
|
var key_1 = 'uploads/' + Date.now() + '-' + (pdfCnt++) + '-' + fileName;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
if (fileData.split(',')[0].split(':')[1].split(';')[0] === 'application/pdf') {
|
|
72
|
+
_this.callMethodInternal.call(_this, 'compressAndUploadPDF', fileName, key_1, fileData.replace('data:' + fileData.split(',')[0].split(':')[1].split(';')[0] + ';base64,', ''));
|
|
73
|
+
file_collection_1.Files.create({
|
|
74
|
+
_id: mongoose_1.Types.ObjectId().toHexString(), __v: 0, name: fileName, size: fileSize, key: key_1, order: fileOrder, type: fileType
|
|
75
|
+
}).then(function (resFile) {
|
|
76
|
+
resolve(resFile);
|
|
77
|
+
}, function (errFile) { return reject(errFile); });
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
var newParams = { Bucket: that.serverConfig.AWSBUCKET, Key: key_1, Body: Buffer.from(fileData.replace('data:' + fileData.split(',')[0].split(':')[1].split(';')[0] + ';base64,', ''), 'base64'), ACL: 'private', ContentType: fileData.split(',')[0].split(':')[1].split(';')[0], ContentDisposition: 'inline' };
|
|
81
|
+
that.getAWS().upload(newParams, function (err, res) {
|
|
82
|
+
if (err) {
|
|
83
|
+
reject(err);
|
|
84
|
+
}
|
|
85
|
+
else if (res) {
|
|
86
|
+
file_collection_1.Files.create({
|
|
87
|
+
_id: mongoose_1.Types.ObjectId().toHexString(), __v: 0, name: fileName, size: fileSize, key: key_1, order: fileOrder, type: fileType
|
|
88
|
+
}).then(function (resFile) {
|
|
89
|
+
resolve(resFile);
|
|
90
|
+
}, function (errFile) { return reject(errFile); });
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
83
94
|
}
|
|
84
95
|
});
|
|
85
96
|
}
|
package/methods/pdf.js
CHANGED
|
@@ -119,6 +119,64 @@ function loadPDFMethods(methodManager) {
|
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
},
|
|
122
|
+
compressAndUploadPDF: {
|
|
123
|
+
skipQueue: true,
|
|
124
|
+
check: new simpl_schema_1.default({
|
|
125
|
+
fileName: {
|
|
126
|
+
type: String
|
|
127
|
+
},
|
|
128
|
+
filePath: {
|
|
129
|
+
type: String
|
|
130
|
+
},
|
|
131
|
+
fileContent: {
|
|
132
|
+
type: String
|
|
133
|
+
}
|
|
134
|
+
}),
|
|
135
|
+
function: function (fileName, filePath, fileContent) {
|
|
136
|
+
var _this = this;
|
|
137
|
+
return new Promise(function (resolve, reject) {
|
|
138
|
+
_this.callMethodInternal.call(_this, 'getCCProcessURL').then(function (resCC) {
|
|
139
|
+
//send request
|
|
140
|
+
request({
|
|
141
|
+
method: 'POST',
|
|
142
|
+
url: 'https:' + resCC.url,
|
|
143
|
+
headers: {
|
|
144
|
+
'Content-Type': 'application/json'
|
|
145
|
+
},
|
|
146
|
+
json: {
|
|
147
|
+
mode: 'compress',
|
|
148
|
+
input: 'base64',
|
|
149
|
+
file: fileContent,
|
|
150
|
+
filename: fileName,
|
|
151
|
+
outputformat: 'pdf',
|
|
152
|
+
wait: true,
|
|
153
|
+
output: {
|
|
154
|
+
's3': {
|
|
155
|
+
'accesskeyid': _this.serverConfig['AWSACCESSKEYID'],
|
|
156
|
+
'secretaccesskey': _this.serverConfig['AWSSECRETACCESSKEY'],
|
|
157
|
+
'region': _this.serverConfig['AWSREGION'],
|
|
158
|
+
'bucket': _this.serverConfig['AWSBUCKET'],
|
|
159
|
+
'path': filePath
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
}
|
|
163
|
+
}, function (error, response, body) {
|
|
164
|
+
if (!error) {
|
|
165
|
+
if (body.output.size) {
|
|
166
|
+
resolve();
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
reject('Compressed file has no size, compress failed');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
reject(error);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}, function (errCC) { return reject(errCC); });
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
},
|
|
122
180
|
mergePDF: {
|
|
123
181
|
skipQueue: true,
|
|
124
182
|
check: new simpl_schema_1.default({
|