From d212529fad5565b9f884f83c68d717902a438c44 Mon Sep 17 00:00:00 2001 From: Philippe Vaucher Date: Wed, 28 Feb 2018 15:13:33 +0100 Subject: [PATCH 1/2] Use pdf.yaml instead of sed --- 0.16.9/Dockerfile | 2 ++ 0.16.9/pdf.yaml | 77 ++++++++++++++++++++++++++++++++++++++++++ 0.16.9/run-restbase.sh | 3 -- 3 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 0.16.9/pdf.yaml diff --git a/0.16.9/Dockerfile b/0.16.9/Dockerfile index 7a3c582..7397879 100644 --- a/0.16.9/Dockerfile +++ b/0.16.9/Dockerfile @@ -27,6 +27,8 @@ RUN set -x; \ COPY run-restbase.sh /run-restbase.sh RUN chmod -v +x /run-restbase.sh +COPY pdf.yaml $RB_HOME/v1/ + COPY projects_docker.yaml $RB_HOME/projects/docker.yaml EXPOSE 7231 diff --git a/0.16.9/pdf.yaml b/0.16.9/pdf.yaml new file mode 100644 index 0000000..3fc69ab --- /dev/null +++ b/0.16.9/pdf.yaml @@ -0,0 +1,77 @@ +swagger: '2.0' +info: + version: '1.0.0-beta' + title: MediaWiki PDF API + description: Page PDF Render API + termsOfService: https://github.com/wikimedia/restbase#restbase + contact: + name: Services + email: services@lists.wikimedia.org + url: https://www.mediawiki.org/wiki/Services + license: + name: Apache licence, v2 + url: https://www.apache.org/licenses/LICENSE-2.0 +paths: + /pdf/{title}: + x-route-filters: + - path: ./lib/revision_table_access_check_filter.js + options: + redirect_cache_control: '{{options.cache_control}}' + get: + tags: + - Page content + summary: Get a page as PDF + description: | + Renders the page content as PDF. + + Stability: [experimental](https://www.mediawiki.org/wiki/API_versioning#Experimental) + produces: + - application/pdf + parameters: + - name: title + in: path + description: "Page title. Use underscores instead of spaces. Example: `Main_Page`." + type: string + required: true + responses: + '200': + description: The PDF render of an article + schema: + type: file + headers: + ETag: + description: > + Syntax: "{revision}/{tid}". + Example: "701384379/154d7bca-c264-11e5-8c2f-1b51b33b59fc" + '404': + description: Unknown page title + schema: + $ref: '#/definitions/problem' + default: + description: Error + schema: + $ref: '#/definitions/problem' + + x-request-handler: + - get_latest_revision: + request: + method: get + uri: /{domain}/sys/page_revisions/page/{title} + - get_pdf_from_backend: + request: + method: get + # Note: The title needs to be encoded twice. + uri: '{{options.uri}}/pdf?accessKey={options.secret}&url=http://{{domain}}/wiki/{_encodeURIComponent(title)}%3Fprintable=yes' + return: + status: 200 + headers: + # Firefox supports filename*= syntax while Chrome respect + # filename=. Safari is stupid and understands neither. + # TODO: Quote raw `"` chars in filename. + content-disposition: 'attachment; {{filenameParameters(request.params.title)}}' + content-type: '{{get_pdf_from_backend.headers.content-type}}' + content-length: '{{get_pdf_from_backend.headers.content-length}}' + cache-control: '{{default(options.cache_control, "s-maxage=600, max-age=600")}}' + etag: '{{get_latest_revision.headers.etag}}' + body: '{{get_pdf_from_backend.body}}' + x-monitor: false # PDF generation is expensive and it's not stored, so don't run checker script diff --git a/0.16.9/run-restbase.sh b/0.16.9/run-restbase.sh index dad9bfa..e27ef9a 100644 --- a/0.16.9/run-restbase.sh +++ b/0.16.9/run-restbase.sh @@ -189,7 +189,4 @@ logging: num_workers: ${RB_CONF_NUM_WORKERS:-'0'} EOT -# Use HTTP instead of HTTPS in pdf.yaml -sed -i -e 's#https://{{domain}}#http://{{domain}}#' v1/pdf.yaml - su -c 'npm start' $RB_USER From 12b42cdd765644d6eb956e764af3ed4b7327d7ca Mon Sep 17 00:00:00 2001 From: Philippe Vaucher Date: Wed, 28 Feb 2018 18:31:52 +0100 Subject: [PATCH 2/2] TMP --- 0.16.9/pdf.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/0.16.9/pdf.yaml b/0.16.9/pdf.yaml index 3fc69ab..1a93174 100644 --- a/0.16.9/pdf.yaml +++ b/0.16.9/pdf.yaml @@ -60,8 +60,10 @@ paths: - get_pdf_from_backend: request: method: get - # Note: The title needs to be encoded twice. - uri: '{{options.uri}}/pdf?accessKey={options.secret}&url=http://{{domain}}/wiki/{_encodeURIComponent(title)}%3Fprintable=yes' + #uri: '{{options.uri}}/pdf?accessKey={options.secret}&url=http://{{domain}}/wiki/{_encodeURIComponent(title)}%3Fprintable=yes' + #uri: '{{options.uri}}/pdf?accessKey={options.secret}&url={_encodeURIComponent("http://google.com")}' + #uri: '{{options.uri}}/pdf?accessKey={options.secret}&url=http%3A%2F%2F{{domain}}%2Fwiki%2F{encodeURI(title)}%3Fprintable=yes' + uri: '{{options.uri}}/pdf?accessKey={options.secret}&url=http://{{domain}}/wiki/{title}%3Fprintable=yes' return: status: 200 headers: