single-file-core 1.3.1 → 1.3.2

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/core/index.js CHANGED
@@ -336,9 +336,9 @@ class BatchRequest {
336
336
  this.duplicates = new Map();
337
337
  }
338
338
 
339
- addURL(resourceURL, { asBinary, expectedType, groupDuplicates, baseURI, blockMixedContent } = {}) {
339
+ addURL(resourceURL, { asBinary, expectedType, groupDuplicates, baseURI, blockMixedContent, contentType } = {}) {
340
340
  return new Promise((resolve, reject) => {
341
- const requestKey = JSON.stringify([resourceURL, asBinary, expectedType, baseURI, blockMixedContent]);
341
+ const requestKey = JSON.stringify([resourceURL, asBinary, expectedType, baseURI, blockMixedContent, contentType]);
342
342
  let resourceRequests = this.requests.get(requestKey);
343
343
  if (!resourceRequests) {
344
344
  resourceRequests = [];
@@ -365,7 +365,7 @@ class BatchRequest {
365
365
  const resourceURLs = [...this.requests.keys()];
366
366
  let indexResource = 0;
367
367
  return Promise.all(resourceURLs.map(async requestKey => {
368
- const [resourceURL, asBinary, expectedType, baseURI, blockMixedContent] = JSON.parse(requestKey);
368
+ const [resourceURL, asBinary, expectedType, baseURI, blockMixedContent, contentType] = JSON.parse(requestKey);
369
369
  const resourceRequests = this.requests.get(requestKey);
370
370
  try {
371
371
  const currentIndexResource = indexResource;
@@ -374,6 +374,7 @@ class BatchRequest {
374
374
  asBinary,
375
375
  inline: !options.compressContent,
376
376
  expectedType,
377
+ contentType,
377
378
  maxResourceSize: options.maxResourceSize,
378
379
  maxResourceSizeEnabled: options.maxResourceSizeEnabled,
379
380
  frameId: options.windowId,
@@ -305,9 +305,11 @@ function getProcessorHelperClass(utilInstance) {
305
305
  // ignored
306
306
  }
307
307
  if (testValidURL(resourceURL)) {
308
+ const declaredContentType = ["OBJECT", "EMBED"].includes(resourceElement.tagName.toUpperCase()) ? resourceElement.getAttribute("type") : "";
309
+ const groupDuplicates = options.groupDuplicateImages && resourceElement.tagName.toUpperCase() == "IMG" && attributeName == "src";
308
310
  let { content, indexResource, duplicate } = await batchRequest.addURL(
309
311
  resourceURL,
310
- { asBinary: true, expectedType, groupDuplicates: options.groupDuplicateImages && resourceElement.tagName.toUpperCase() == "IMG" && attributeName == "src" });
312
+ { asBinary: true, expectedType, contentType: declaredContentType, groupDuplicates });
311
313
  if (originURL) {
312
314
  if (this.testEmptyResource(content)) {
313
315
  try {
@@ -321,6 +323,7 @@ function getProcessorHelperClass(utilInstance) {
321
323
  asBinary: true,
322
324
  inline: true,
323
325
  expectedType,
326
+ contentType: declaredContentType,
324
327
  maxResourceSize: options.maxResourceSize,
325
328
  maxResourceSizeEnabled: options.maxResourceSizeEnabled,
326
329
  frameId: options.windowId,
@@ -280,8 +280,9 @@ function getProcessorHelperClass(utilInstance) {
280
280
  // ignored
281
281
  }
282
282
  if (testValidURL(resourceURL)) {
283
+ const declaredContentType = ["OBJECT", "EMBED"].includes(resourceElement.tagName.toUpperCase()) ? resourceElement.getAttribute("type") : "";
283
284
  let { content, indexResource, extension, contentType } = await batchRequest.addURL(resourceURL,
284
- { asBinary: true, expectedType });
285
+ { asBinary: true, expectedType, contentType: declaredContentType });
285
286
  if (originURL) {
286
287
  if (this.testEmptyResource(content)) {
287
288
  try {
@@ -294,6 +295,7 @@ function getProcessorHelperClass(utilInstance) {
294
295
  content = (await util.getContent(resourceURL, {
295
296
  asBinary: true,
296
297
  expectedType,
298
+ contentType: declaredContentType,
297
299
  maxResourceSize: options.maxResourceSize,
298
300
  maxResourceSizeEnabled: options.maxResourceSizeEnabled,
299
301
  frameId: options.windowId,
package/core/util.js CHANGED
@@ -286,7 +286,10 @@ function getInstance(utilOptions) {
286
286
  // ignored
287
287
  }
288
288
  if (!contentType || (contentType == CONTENT_TYPE_OCTET_STREAM && options.asBinary)) {
289
- contentType = guessMIMEType(options.expectedType, buffer, options.asBinary);
289
+ contentType = guessMIMEType(options.expectedType, buffer);
290
+ if (!contentType) {
291
+ contentType = options.contentType ? options.contentType : options.asBinary ? CONTENT_TYPE_OCTET_STREAM : "";
292
+ }
290
293
  }
291
294
  if (!charset && options.charset) {
292
295
  charset = options.charset;
@@ -366,7 +369,7 @@ async function getFetchResponse(resourceURL, options, data, charset, contentType
366
369
  return { data, resourceURL, charset, contentType };
367
370
  }
368
371
 
369
- function guessMIMEType(expectedType, buffer, asBinary) {
372
+ function guessMIMEType(expectedType, buffer) {
370
373
  if (expectedType == "image") {
371
374
  if (compareBytes([255, 255, 255, 255], [0, 0, 1, 0])) {
372
375
  return "image/x-icon";
@@ -463,7 +466,6 @@ function guessMIMEType(expectedType, buffer, asBinary) {
463
466
  return "audio/3gpp";
464
467
  }
465
468
  }
466
- return asBinary ? CONTENT_TYPE_OCTET_STREAM : "";
467
469
 
468
470
  function compareBytes(mask, pattern) {
469
471
  let patternMatch = true, index = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -62,7 +62,8 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
62
62
  "ttf": "font/ttf",
63
63
  "woff": "font/woff",
64
64
  "woff2": "font/woff2",
65
- "eot": "application/vnd.ms-fontobject"
65
+ "eot": "application/vnd.ms-fontobject",
66
+ "pdf": "application/pdf"
66
67
  };
67
68
  const REGEXP_MATCH_STYLESHEET = /stylesheet_[0-9]+\.css/;
68
69
  const REGEXP_MATCH_SCRIPT = /scripts\/[0-9]+\.js/;