ganze project
This commit is contained in:
96
node_modules/pdf-parse/dist/node/cjs/index.cjs
generated
vendored
Normal file
96
node_modules/pdf-parse/dist/node/cjs/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/node/index.ts
|
||||
var index_exports = {};
|
||||
__export(index_exports, {
|
||||
getHeader: () => getHeader
|
||||
});
|
||||
module.exports = __toCommonJS(index_exports);
|
||||
|
||||
// src/node/getHeader.ts
|
||||
var http = __toESM(require("node:http"), 1);
|
||||
var https = __toESM(require("node:https"), 1);
|
||||
async function nodeRequest(u, method, headers) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reqFn = u.protocol === "https:" ? https.request : http.request;
|
||||
const req = reqFn(u, { method, headers }, (res) => {
|
||||
const headersObj = {};
|
||||
for (const [k, v] of Object.entries(res.headers)) {
|
||||
headersObj[k] = Array.isArray(v) ? v.join(",") : v ?? "";
|
||||
}
|
||||
const chunks = [];
|
||||
res.on("data", (c) => chunks.push(Buffer.from(c)));
|
||||
res.on("end", () => {
|
||||
const buffer = chunks.length ? Buffer.concat(chunks) : void 0;
|
||||
resolve({ status: res.statusCode ?? 0, headers: headersObj, buffer });
|
||||
});
|
||||
});
|
||||
req.on("error", (err) => reject(err));
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
async function getHeader(url, check = false) {
|
||||
try {
|
||||
const u = typeof url === "string" ? new URL(url) : url;
|
||||
const headResp = await nodeRequest(u, "HEAD");
|
||||
const size = headResp.headers["content-length"] ? parseInt(headResp.headers["content-length"], 10) : void 0;
|
||||
let magic = null;
|
||||
if (check) {
|
||||
const rangeResp = await nodeRequest(u, "GET", { Range: "bytes=0-4" });
|
||||
if (rangeResp.status >= 200 && rangeResp.status < 300 && rangeResp.buffer) {
|
||||
const headerStr = rangeResp.buffer.slice(0, 4).toString("utf8");
|
||||
magic = headerStr.startsWith("%PDF");
|
||||
} else {
|
||||
magic = false;
|
||||
}
|
||||
}
|
||||
return {
|
||||
ok: headResp.status >= 200 && headResp.status < 300,
|
||||
status: headResp.status,
|
||||
size,
|
||||
magic,
|
||||
headers: headResp.headers
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
ok: false,
|
||||
status: void 0,
|
||||
size: void 0,
|
||||
magic: false,
|
||||
headers: {},
|
||||
error: new Error(String(error))
|
||||
};
|
||||
}
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
getHeader
|
||||
});
|
||||
//# sourceMappingURL=index.cjs.map
|
||||
7
node_modules/pdf-parse/dist/node/cjs/index.cjs.map
generated
vendored
Normal file
7
node_modules/pdf-parse/dist/node/cjs/index.cjs.map
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"version": 3,
|
||||
"sources": ["../../../src/node/index.ts", "../../../src/node/getHeader.ts"],
|
||||
"sourcesContent": ["export type * from './getHeader.js';\nexport * from './getHeader.js';\n", "import * as http from 'node:http';\nimport * as https from 'node:https';\n\n/**\n * Result information from getHeader.\n * @public\n */\nexport interface HeaderResult {\n\tok: boolean;\n\tstatus?: number;\n\tsize?: number;\n\tmagic: boolean | null;\n\theaders?: Record<string, string>;\n\terror?: Error;\n}\n\ninterface RequestResult {\n\tstatus: number;\n\theaders: Record<string, string>;\n\tbuffer?: Buffer;\n}\n\nasync function nodeRequest(u: URL, method: string, headers?: Record<string, string>): Promise<RequestResult> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst reqFn = u.protocol === 'https:' ? https.request : http.request;\n\t\tconst req = reqFn(u, { method, headers }, (res) => {\n\t\t\tconst headersObj: Record<string, string> = {};\n\t\t\tfor (const [k, v] of Object.entries(res.headers)) {\n\t\t\t\theadersObj[k] = Array.isArray(v) ? v.join(',') : (v ?? '');\n\t\t\t}\n\n\t\t\tconst chunks: Buffer[] = [];\n\t\t\tres.on('data', (c) => chunks.push(Buffer.from(c)));\n\t\t\tres.on('end', () => {\n\t\t\t\tconst buffer = chunks.length ? Buffer.concat(chunks) : undefined;\n\t\t\t\tresolve({ status: res.statusCode ?? 0, headers: headersObj, buffer });\n\t\t\t});\n\t\t});\n\n\t\treq.on('error', (err) => reject(err));\n\t\treq.end();\n\t});\n}\n\n/**\n * Perform an HTTP HEAD request to retrieve the file size and verify existence;\n * when `check` is true, fetch a small range and inspect the magic number to confirm the URL points to a valid PDF.\n * If the server does not support range requests, `isPdf` will be set to `false`.\n * @param url - The URL of the PDF file to check. Can be a string or URL object.\n * @param check - When `true`, download a small byte range (first 4 bytes) to validate the file signature by checking for '%PDF' magic bytes. Default: `false`.\n * @returns - A Promise that resolves to a HeaderResult object containing the response status, size, headers, and PDF validation result.\n * @public\n */\nexport async function getHeader(url: string | URL, check: boolean = false): Promise<HeaderResult> {\n\ttry {\n\t\tconst u = typeof url === 'string' ? new URL(url) : url;\n\n\t\tconst headResp = await nodeRequest(u, 'HEAD');\n\t\tconst size = headResp.headers['content-length'] ? parseInt(headResp.headers['content-length'], 10) : undefined;\n\n\t\tlet magic: boolean | null = null;\n\t\tif (check) {\n\t\t\tconst rangeResp = await nodeRequest(u, 'GET', { Range: 'bytes=0-4' });\n\t\t\tif (rangeResp.status >= 200 && rangeResp.status < 300 && rangeResp.buffer) {\n\t\t\t\tconst headerStr = rangeResp.buffer.slice(0, 4).toString('utf8');\n\t\t\t\tmagic = headerStr.startsWith('%PDF');\n\t\t\t} else {\n\t\t\t\tmagic = false;\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tok: headResp.status >= 200 && headResp.status < 300,\n\t\t\tstatus: headResp.status,\n\t\t\tsize,\n\t\t\tmagic,\n\t\t\theaders: headResp.headers,\n\t\t};\n\t} catch (error) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\tstatus: undefined,\n\t\t\tsize: undefined,\n\t\t\tmagic: false,\n\t\t\theaders: {},\n\t\t\terror: new Error(String(error)),\n\t\t};\n\t}\n}\n"],
|
||||
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,WAAsB;AACtB,YAAuB;AAqBvB,eAAe,YAAY,GAAQ,QAAgB,SAA0D;AAC5G,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACvC,UAAM,QAAQ,EAAE,aAAa,WAAiB,gBAAe;AAC7D,UAAM,MAAM,MAAM,GAAG,EAAE,QAAQ,QAAQ,GAAG,CAAC,QAAQ;AAClD,YAAM,aAAqC,CAAC;AAC5C,iBAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,IAAI,OAAO,GAAG;AACjD,mBAAW,CAAC,IAAI,MAAM,QAA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MACR,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SAAS,CAAC;AAAA,MACV,OAAO,IAAI,MAAM,OAAO,KAAK,CAAC;AAAA,IAC/B;AAAA,EACD;AACD;",
|
||||
"names": []
|
||||
}
|
||||
25
node_modules/pdf-parse/dist/node/cjs/index.d.cts
generated
vendored
Normal file
25
node_modules/pdf-parse/dist/node/cjs/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Perform an HTTP HEAD request to retrieve the file size and verify existence;
|
||||
* when `check` is true, fetch a small range and inspect the magic number to confirm the URL points to a valid PDF.
|
||||
* If the server does not support range requests, `isPdf` will be set to `false`.
|
||||
* @param url - The URL of the PDF file to check. Can be a string or URL object.
|
||||
* @param check - When `true`, download a small byte range (first 4 bytes) to validate the file signature by checking for '%PDF' magic bytes. Default: `false`.
|
||||
* @returns - A Promise that resolves to a HeaderResult object containing the response status, size, headers, and PDF validation result.
|
||||
* @public
|
||||
*/
|
||||
export declare function getHeader(url: string | URL, check?: boolean): Promise<HeaderResult>;
|
||||
|
||||
/**
|
||||
* Result information from getHeader.
|
||||
* @public
|
||||
*/
|
||||
export declare interface HeaderResult {
|
||||
ok: boolean;
|
||||
status?: number;
|
||||
size?: number;
|
||||
magic: boolean | null;
|
||||
headers?: Record<string, string>;
|
||||
error?: Error;
|
||||
}
|
||||
|
||||
export { }
|
||||
Reference in New Issue
Block a user