Extend url typings (fix issue #25)

This commit is contained in:
yumauri
2021-01-26 19:44:28 +03:00
parent 51dcdc83a9
commit 3be519955b
5 changed files with 22 additions and 20 deletions
+1 -4
View File
@@ -110,11 +110,8 @@ export type OfficeRequestFields = {
// Attention: when converting a website to PDF, you should remove all margins
// If not, some of the content of the page might be hidden
// https://thecodingmachine.github.io/gotenberg/#url
export type UrlRequestFields = {
export type UrlRequestFields = HtmlRequestFields & {
remoteURL?: string
// https://thecodingmachine.github.io/gotenberg/#html.paper_size_margins_orientation_scaling
scale?: number
}
// merge conversion doesn't have any form fields
+5 -15
View File
@@ -1,24 +1,14 @@
import {
ConversionOptions,
HtmlRequest,
MarginOptions,
MarkdownRequest,
OfficeRequest,
PaperOptions,
RequestFields,
} from './_types'
import { ConversionOptions, MarginOptions, PaperOptions, Request, RequestFields } from './_types'
import { fields } from './internal/fields'
import { marginSizes, paperSize } from './to-helpers'
/**
* Adjust Request fields, for html, markdown or office requests
* @return new Request (Html|Markdown|Office), doesn't modify original Request
* Adjust Request fields, for any request
* @return new typed Request, doesn't modify original Request
*/
export const to: {
(...opts: ConversionOptions[]): (request: HtmlRequest) => HtmlRequest
(...opts: ConversionOptions[]): (request: OfficeRequest) => OfficeRequest
(...opts: ConversionOptions[]): (request: MarkdownRequest) => MarkdownRequest
} = (...opts: ConversionOptions[]): any => {
<RequestEx extends Request>(...opts: ConversionOptions[]): (request: RequestEx) => RequestEx
} = (...opts): any => {
const options: RequestFields = {}
// page size and margins options
+1 -1
View File
@@ -7,7 +7,7 @@ import { type } from './internal/type'
/**
* Adjust Request url, by adding `/url` to it; Set `remoteURL` from source
* @return new HtmlRequest, doesn't modify original Request
* @return new UrlRequest, doesn't modify original Request
*/
export const url: {
(request: Request): UrlRequest
Binary file not shown.
+15
View File
@@ -0,0 +1,15 @@
import { createWriteStream } from 'fs'
import { convert, gotenberg, landscape, pipe, please, to, url } from '../../src'
// need to run Gotenberg like this
// docker run --rm -p 3500:3000 thecodingmachine/gotenberg:6
pipe(
gotenberg('http://localhost:3500'),
convert,
url,
to(landscape),
please
)('https://google.com')
.then((pdf) => pdf.pipe(createWriteStream(`${__dirname}/google.pdf`)))
.catch(console.error)