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.
Files changed (2) hide show
  1. package/lib/utils/quill.js +38 -33
  2. package/package.json +1 -1
@@ -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) { var _a; return ((_a = op.insert) === null || _a === void 0 ? void 0 : _a.image) && !checkedImages.find(function (image) { return image.src === op.insert.image.src; }); }).forEach(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 (op.insert.image.src && op.insert.image.src.startsWith('http')) {
38
- // Use the backend to check if the image is public
39
- // Due to CSP and other security measures, we can't check this in the frontend
40
- // uuidv5 is a deterministic uuid generator based on a namespace and a name
41
- // uuidv5.URL is the namespace for urls
42
- var hookId_1 = uuid_1.v5(op.insert.image.src, uuid_1.v5.URL);
43
- noStoreSaga_1.noStoreHooks.registerNoStoreActionHook(hookId_1, function (data) {
44
- noStoreSaga_1.noStoreHooks.unregisterNoStoreActionHook(hookId_1);
45
- // Backend fetches the URL. If there is no data returned or if the data returned has headers
46
- // but those headers are not of image type (i.e. it was a 302 that, when followed returned HTML
47
- // (I'm looking at you, Brightspace), then we update the image insert op to be nonPublic
48
- if (!data || (data['Content-Type'] && !data['Content-Type'][0].startsWith('image'))) {
49
- var contents = quill.getContents();
50
- var ops = contents.map(function (o) {
51
- var _a, _b;
52
- return ((_a = o.insert.image) === null || _a === void 0 ? void 0 : _a.src) && ((_b = op.insert.image) === null || _b === void 0 ? void 0 : _b.src) && o.insert.image.src === op.insert.image.src
53
- ? __assign(__assign({}, o), { insert: __assign(__assign({}, o.insert), { image: __assign(__assign({}, o.insert.image), { nonPublic: true }) }) }) : o;
54
- });
55
- var updatedContents = contents.diff(new Delta(ops));
56
- quill.updateContents(updatedContents);
57
- }
58
- });
59
- // This endpoint returns headers for a url. If the url is nonexistent, it will return null
60
- actionCreator_1.dispatchAction(actions_1.NET_ACTION.DATA_REQUESTED, {
61
- modelName: 'urlChecker',
62
- guid: hookId_1,
63
- noStore: true,
64
- queryParams: {
65
- url: op.insert.image.src
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "studiokit-scaffolding-js",
3
- "version": "5.2.0",
3
+ "version": "5.2.1",
4
4
  "description": "Common scaffolding for Studio apps at Purdue",
5
5
  "repository": "https://gitlab.com/purdue-informatics/studiokit/studiokit-scaffolding-js",
6
6
  "license": "MIT",