studiokit-scaffolding-js 5.2.0 → 5.2.1
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/lib/utils/quill.js +38 -33
- package/package.json +1 -1
package/lib/utils/quill.js
CHANGED
|
@@ -32,40 +32,45 @@ var checkForNonPublicImages = function (quill, checkedImages) {
|
|
|
32
32
|
var _a, _b;
|
|
33
33
|
(_b = (_a = quill
|
|
34
34
|
.getContents()) === null || _a === void 0 ? void 0 : _a.ops // Is the op an image and have we not seen it before?
|
|
35
|
-
) === null || _b === void 0 ? void 0 : _b.filter(function (op) {
|
|
35
|
+
) === null || _b === void 0 ? void 0 : _b.filter(function (op) {
|
|
36
|
+
return op.insert.image &&
|
|
37
|
+
!checkedImages.find(function (image) { return image.src === op.insert.image.src; }) &&
|
|
38
|
+
op.insert.image.src.startsWith('http');
|
|
39
|
+
}).forEach(function (op) {
|
|
36
40
|
// Check if the image is public. Do not check data:image urls
|
|
37
|
-
if
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
noStoreSaga_1.noStoreHooks.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
41
|
+
// Use the backend to check if the image is public
|
|
42
|
+
// Due to CSP and other security measures, we can't check this in the frontend
|
|
43
|
+
// uuidv5 is a deterministic uuid generator based on a namespace and a name
|
|
44
|
+
// uuidv5.URL is the namespace for urls
|
|
45
|
+
var hookId = uuid_1.v5(op.insert.image.src, uuid_1.v5.URL);
|
|
46
|
+
noStoreSaga_1.noStoreHooks.registerNoStoreActionHook(hookId, function (data) {
|
|
47
|
+
noStoreSaga_1.noStoreHooks.unregisterNoStoreActionHook(hookId);
|
|
48
|
+
// Backend fetches the URL. If there is no data returned or if the data returned has headers
|
|
49
|
+
// but those headers are not of image type (i.e. it was a 302 that, when followed returned HTML
|
|
50
|
+
// (I'm looking at you, Brightspace), then we update the image insert op to be nonPublic
|
|
51
|
+
var contentTypeKey;
|
|
52
|
+
if (!data ||
|
|
53
|
+
((contentTypeKey = Object.keys(data).find(function (k) { return k.toLowerCase() === 'content-type'; })) &&
|
|
54
|
+
!data[contentTypeKey][0].startsWith('image'))) {
|
|
55
|
+
var contents = quill.getContents();
|
|
56
|
+
var ops = contents.map(function (o) {
|
|
57
|
+
var _a;
|
|
58
|
+
return ((_a = o.insert.image) === null || _a === void 0 ? void 0 : _a.src) && op.insert.image.src && o.insert.image.src === op.insert.image.src
|
|
59
|
+
? __assign(__assign({}, o), { insert: __assign(__assign({}, o.insert), { image: __assign(__assign({}, o.insert.image), { nonPublic: true }) }) }) : o;
|
|
60
|
+
});
|
|
61
|
+
var updatedContents = contents.diff(new Delta(ops));
|
|
62
|
+
quill.updateContents(updatedContents);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
// This endpoint returns headers for a url. If the url is nonexistent, it will return null
|
|
66
|
+
actionCreator_1.dispatchAction(actions_1.NET_ACTION.DATA_REQUESTED, {
|
|
67
|
+
modelName: 'urlChecker',
|
|
68
|
+
guid: hookId,
|
|
69
|
+
noStore: true,
|
|
70
|
+
queryParams: {
|
|
71
|
+
url: op.insert.image.src
|
|
72
|
+
}
|
|
73
|
+
});
|
|
69
74
|
});
|
|
70
75
|
};
|
|
71
76
|
exports.checkForNonPublicImages = checkForNonPublicImages;
|
package/package.json
CHANGED