@nka212bg/backend-utils 0.1.8 → 0.1.10
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/misc.js +11 -2
- package/package.json +1 -1
package/misc.js
CHANGED
|
@@ -415,7 +415,16 @@ exports.urlMetadata = async ({ url }) => {
|
|
|
415
415
|
const fxIndex = tempUrl.pathname.lastIndexOf(".");
|
|
416
416
|
fileExtension = fxIndex < 0 ? null : tempUrl.pathname.substring(fxIndex + 1)?.match(/\w+/)[0];
|
|
417
417
|
|
|
418
|
-
let fetchRes = await fetch(
|
|
418
|
+
let fetchRes = await fetch(tempUrl.href, {
|
|
419
|
+
headers: {
|
|
420
|
+
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0 google facebook linkedin",
|
|
421
|
+
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
|
422
|
+
"Accept-Language": "en-US,en;q=0.5",
|
|
423
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
424
|
+
Path: tempUrl.pathname,
|
|
425
|
+
Authority: tempUrl.hostname,
|
|
426
|
+
},
|
|
427
|
+
});
|
|
419
428
|
|
|
420
429
|
const sizeKb = parseInt(Number(fetchRes.headers?.get("content-length")) / 1000);
|
|
421
430
|
let contentType = fetchRes.headers?.get("content-type")?.split("/") || [];
|
|
@@ -424,7 +433,7 @@ exports.urlMetadata = async ({ url }) => {
|
|
|
424
433
|
|
|
425
434
|
contentType = `${contentGroup}/${fileType}`;
|
|
426
435
|
|
|
427
|
-
if (/html
|
|
436
|
+
if (/x?html/.test(fileType)) {
|
|
428
437
|
dataType = "html";
|
|
429
438
|
} else if (/image|audio|video|application/.test(contentGroup) && !/^xml|json|javascript/.test(fileType)) {
|
|
430
439
|
dataType = "dataSrc";
|