@stemy/backend 2.9.2 → 2.9.5
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/bundles/stemy-backend.umd.js +28 -9
- package/bundles/stemy-backend.umd.js.map +1 -1
- package/bundles/stemy-backend.umd.min.js +1 -1
- package/bundles/stemy-backend.umd.min.js.map +1 -1
- package/common-types.d.ts +1 -0
- package/esm2015/common-types.js +1 -1
- package/esm2015/services/asset-processor.js +23 -4
- package/esm2015/services/assets.js +2 -3
- package/esm2015/services/progresses.js +2 -2
- package/fesm2015/stemy-backend.js +24 -6
- package/fesm2015/stemy-backend.js.map +1 -1
- package/package.json +2 -2
- package/services/asset-processor.d.ts +1 -1
- package/stemy-backend.metadata.json +1 -1
|
@@ -1212,7 +1212,7 @@
|
|
|
1212
1212
|
"application/font-woff", "application/font-woff2", "application/x-font-opentype", "application/x-font-truetype", "application/x-font-datafork",
|
|
1213
1213
|
"font/woff", "font/woff2", "font/otf", "font/ttf", "font/datafork"
|
|
1214
1214
|
];
|
|
1215
|
-
var imageTypes = ["image/jpeg", "image/jpg", "image/png"];
|
|
1215
|
+
var imageTypes = ["image/jpeg", "image/jpg", "image/png", "image/svg+xml"];
|
|
1216
1216
|
var fontProps = [
|
|
1217
1217
|
"postscriptName", "fullName", "familyName", "subfamilyName",
|
|
1218
1218
|
"copyright", "version", "unitsPerEm", "ascent", "descent", "lineGap",
|
|
@@ -1267,12 +1267,32 @@
|
|
|
1267
1267
|
AssetProcessor.isImage = function (contentType) {
|
|
1268
1268
|
return imageTypes.indexOf(contentType) >= 0;
|
|
1269
1269
|
};
|
|
1270
|
-
AssetProcessor.copyImageMeta = function (buffer, metadata) {
|
|
1270
|
+
AssetProcessor.copyImageMeta = function (buffer, metadata, fileType) {
|
|
1271
1271
|
return __awaiter$u(this, void 0, void 0, function () {
|
|
1272
|
-
var output;
|
|
1272
|
+
var match, attrs, parts, output;
|
|
1273
1273
|
return __generator(this, function (_b) {
|
|
1274
1274
|
switch (_b.label) {
|
|
1275
|
-
case 0:
|
|
1275
|
+
case 0:
|
|
1276
|
+
if (fileType.mime === "image/svg+xml") {
|
|
1277
|
+
match = /<svg(.+)>/gi.exec(buffer.toString("utf8"));
|
|
1278
|
+
if (match && match.length > 1) {
|
|
1279
|
+
attrs = match[1].match(/([a-z]+)="([^"]+)"/gi);
|
|
1280
|
+
attrs.forEach(function (attr) {
|
|
1281
|
+
if (attr.length < 5)
|
|
1282
|
+
return;
|
|
1283
|
+
var _b = __read(attr.split("="), 2), name = _b[0], value = _b[1];
|
|
1284
|
+
var val = value.replace(/"/gi, "");
|
|
1285
|
+
metadata[name] = isNaN(val) ? val : Number(val);
|
|
1286
|
+
});
|
|
1287
|
+
if (metadata.viewBox && (isNaN(metadata.width) || isNaN(metadata.height))) {
|
|
1288
|
+
parts = metadata.viewBox.split(" ");
|
|
1289
|
+
metadata.width = Number(parts[0]) + Number(parts[2]);
|
|
1290
|
+
metadata.height = Number(parts[1]) + Number(parts[3]);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
return [2 /*return*/, buffer];
|
|
1294
|
+
}
|
|
1295
|
+
return [4 /*yield*/, sharp$3(buffer).rotate().toBuffer({ resolveWithObject: true })];
|
|
1276
1296
|
case 1:
|
|
1277
1297
|
output = _b.sent();
|
|
1278
1298
|
Object.assign(metadata, output.info);
|
|
@@ -1297,7 +1317,7 @@
|
|
|
1297
1317
|
switch (_b.label) {
|
|
1298
1318
|
case 0:
|
|
1299
1319
|
if (!AssetProcessor_1.isImage(fileType.mime)) return [3 /*break*/, 2];
|
|
1300
|
-
return [4 /*yield*/, AssetProcessor_1.copyImageMeta(buffer, metadata)];
|
|
1320
|
+
return [4 /*yield*/, AssetProcessor_1.copyImageMeta(buffer, metadata, fileType)];
|
|
1301
1321
|
case 1:
|
|
1302
1322
|
buffer = _b.sent();
|
|
1303
1323
|
_b.label = 2;
|
|
@@ -1947,18 +1967,17 @@
|
|
|
1947
1967
|
};
|
|
1948
1968
|
Assets.prototype.upload = function (stream, fileType, metadata) {
|
|
1949
1969
|
return __awaiter$q(this, void 0, void 0, function () {
|
|
1950
|
-
var contentType
|
|
1970
|
+
var contentType;
|
|
1951
1971
|
var _this = this;
|
|
1952
1972
|
return __generator(this, function (_b) {
|
|
1953
1973
|
contentType = fileType.mime.trim();
|
|
1954
|
-
extension = (fileType.ext || "").trim();
|
|
1955
1974
|
metadata = Object.assign({
|
|
1956
|
-
extension: extension,
|
|
1957
1975
|
downloadCount: 0,
|
|
1958
1976
|
firstDownload: null,
|
|
1959
1977
|
lastDownload: null
|
|
1960
1978
|
}, metadata || {});
|
|
1961
1979
|
metadata.filename = metadata.filename || new bson.ObjectId().toHexString();
|
|
1980
|
+
metadata.extension = (fileType.ext || "").trim();
|
|
1962
1981
|
return [2 /*return*/, new Promise((function (resolve, reject) {
|
|
1963
1982
|
var uploaderStream = _this.bucket.openUploadStream(metadata.filename);
|
|
1964
1983
|
stream.pipe(uploaderStream)
|
|
@@ -2890,7 +2909,7 @@
|
|
|
2890
2909
|
}
|
|
2891
2910
|
isFinished = progress.percent == 100;
|
|
2892
2911
|
if (!!isFinished) return [3 /*break*/, 4];
|
|
2893
|
-
return [4 /*yield*/, promiseTimeout(
|
|
2912
|
+
return [4 /*yield*/, promiseTimeout(50)];
|
|
2894
2913
|
case 3:
|
|
2895
2914
|
_a.sent();
|
|
2896
2915
|
_a.label = 4;
|