Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF: Switch to using Proton #1090

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions config.example.wikimedia.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ default_project: &default_project
pdf:
# Cache PDF for 5 minutes since it's not purged
cache_control: s-maxage=600, max-age=600
uri: https://pdfrender-beta.wmflabs.org
new_uri: https://proton-beta.wmflabs.org
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe let's rename new_uri to uri?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about it, but to keep it backwards compatible, I opted with leaving it as-is. Perhaps we could go with this now and revisit in the future?

new_probability: 1
secret: secret
scheme: https
transform:
cx_host: https://cxserver-beta.wmflabs.org
skip_updates: false
Expand Down
2 changes: 0 additions & 2 deletions config.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ default_project: &default_project
pdf:
# Cache PDF for 5 minutes since it's not purged
cache_control: s-maxage=600, max-age=600
uri: https://pdfrender-beta.wmflabs.org
new_uri: https://proton-beta.wmflabs.org
secret: secret
transform:
cx_host: https://cxserver-beta.wmflabs.org
skip_updates: false
Expand Down
19 changes: 5 additions & 14 deletions v1/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,14 @@ module.exports = options => ({
operations: {
generatePDF: (hyper, req) => {
const rp = req.params;
const newProbability = options.new_probability || 0;
return hyper.get(new URI([rp.domain, 'sys', 'page_revisions', 'page', rp.title]))
.then((latestRevision) => {
if (options.new_uri && (Math.random() < newProbability || req.query.new_pdf)) {
const newResult = hyper.get(new URI(
if (options.new_uri) {
return hyper.get(new URI(
`${options.new_uri}/${rp.domain}/v1/`
+ `pdf/${encodeURIComponent(rp.title)}/a4/desktop`
))
.catch((e) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still keep logging

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't throwing the error here make RB log it automatically? We don't want to end up with duplicate log entries.

hyper.logger.log('error/proton', e);
if (req.query.new_pdf) {
throw e;
}
});
if (req.query.new_pdf) {
return newResult;
}
+ `pdf/${encodeURIComponent(rp.title)}`
+ `/${rp.format || 'a4'}/${rp.type || `desktop`}`
));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to do more - change the public API to allow for changing the hardcoded /a4/desktop. Optional parameters with defaults should not break backwards compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, damn, forgot that part. Very good point. Will change.

}
return hyper.get({
uri: new URI(`${options.uri}/pdf`),
Expand Down
19 changes: 18 additions & 1 deletion v1/pdf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ info:
name: Apache licence, v2
url: https://www.apache.org/licenses/LICENSE-2.0
paths:
/pdf/{title}:
/pdf/{title}{/format}{/type}:
x-route-filters:
- path: ./lib/access_check_filter.js
options:
Expand All @@ -34,6 +34,23 @@ paths:
description: "Page title. Use underscores instead of spaces. Example: `Main_Page`."
type: string
required: true
- in: path
name: format
type: string
enum: ['a4', 'letter', 'legal']
required: false
default: a4
description: "PDF page format. Default: a4"
- in: path
name: type
schema:
type: string
enum: ['mobile', 'desktop']
required: false
default: desktop
description: |
PDF type: mobile (optimized for reading on mobile devices) or desktop
(regular PDF). Default: desktop
responses:
'200':
description: The PDF render of an article
Expand Down