ganze project
This commit is contained in:
23
node_modules/pdf-parse/dist/node/esm/getHeader.d.ts
generated
vendored
Normal file
23
node_modules/pdf-parse/dist/node/esm/getHeader.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Result information from getHeader.
|
||||
* @public
|
||||
*/
|
||||
export interface HeaderResult {
|
||||
ok: boolean;
|
||||
status?: number;
|
||||
size?: number;
|
||||
magic: boolean | null;
|
||||
headers?: Record<string, string>;
|
||||
error?: Error;
|
||||
}
|
||||
/**
|
||||
* 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>;
|
||||
//# sourceMappingURL=getHeader.d.ts.map
|
||||
1
node_modules/pdf-parse/dist/node/esm/getHeader.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-parse/dist/node/esm/getHeader.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getHeader.d.ts","sourceRoot":"","sources":["../../../src/node/getHeader.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC5B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,KAAK,CAAC;CACd;AA8BD;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,KAAK,GAAE,OAAe,GAAG,OAAO,CAAC,YAAY,CAAC,CAmChG"}
|
||||
66
node_modules/pdf-parse/dist/node/esm/getHeader.js
generated
vendored
Normal file
66
node_modules/pdf-parse/dist/node/esm/getHeader.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
import * as http from 'node:http';
|
||||
import * as https from 'node:https';
|
||||
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) : undefined;
|
||||
resolve({ status: res.statusCode ?? 0, headers: headersObj, buffer });
|
||||
});
|
||||
});
|
||||
req.on('error', (err) => reject(err));
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 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 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) : undefined;
|
||||
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: undefined,
|
||||
size: undefined,
|
||||
magic: false,
|
||||
headers: {},
|
||||
error: new Error(String(error)),
|
||||
};
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=getHeader.js.map
|
||||
1
node_modules/pdf-parse/dist/node/esm/getHeader.js.map
generated
vendored
Normal file
1
node_modules/pdf-parse/dist/node/esm/getHeader.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getHeader.js","sourceRoot":"","sources":["../../../src/node/getHeader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAqBpC,KAAK,UAAU,WAAW,CAAC,CAAM,EAAE,MAAc,EAAE,OAAgC;IAClF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,MAAM,KAAK,GAAG,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;QACrE,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;YACjD,MA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AAE,EAAE;YACX,KAAK,EAAE,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SAC/B,CAAC;IACH,CAAC;AACF,CAAC"}
|
||||
3
node_modules/pdf-parse/dist/node/esm/index.d.ts
generated
vendored
Normal file
3
node_modules/pdf-parse/dist/node/esm/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export type * from './getHeader.js';
|
||||
export * from './getHeader.js';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
1
node_modules/pdf-parse/dist/node/esm/index.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-parse/dist/node/esm/index.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,gBAAgB,CAAC;AACpC,cAAc,gBAAgB,CAAC"}
|
||||
2
node_modules/pdf-parse/dist/node/esm/index.js
generated
vendored
Normal file
2
node_modules/pdf-parse/dist/node/esm/index.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './getHeader.js';
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/pdf-parse/dist/node/esm/index.js.map
generated
vendored
Normal file
1
node_modules/pdf-parse/dist/node/esm/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAC"}
|
||||
Reference in New Issue
Block a user