-
Notifications
You must be signed in to change notification settings - Fork 81
Parsoid: Add the variant proxy #1207
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a8fb336
Parsoid: Move the Parsoid class to lib/parsoid.js
56cbde4
Parsoid: Create the modules for both variants
eec926e
Parsoid: Add the variant proxy
3a7cfeb
Parsoid: Use Parsoid/PHP for tests using Beta wikipedia
cce372e
Parsoid: Add fallback for transforms to the proxy
a5d5f5d
Parsoid: Throw errors for unimplemented methods
8cfead2
Parsoid: Stash: Honour our own ETag when retrieving the stash
3d63e77
Minor: Parsoid: No return JSDoc for abstract methods
1665ed0
Parsoid: Tests: Add Parsoid/PHP to the list of allowed URLs
ccdf409
Parsoid: Set content-language and vary if they are missing
cd991c8
Travis: Start Cassandra only for the `cassandra` test target
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Parsoid: Create the modules for both variants
Using the Parsoid class, we create two new modules for the JS and PHP variant, respectively. Each module declares a new class that inherits from Parsoid, but sets up their methods for making requests to Parsoid as well as methods for obtaining the bucket URIs to use. Bug: T230791
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| 'use strict'; | ||
|
|
||
| const HyperSwitch = require('hyperswitch'); | ||
|
|
||
| const Parsoid = require('../lib/parsoid.js'); | ||
| const spec = HyperSwitch.utils.loadSpec(`${__dirname}/parsoid.yaml`); | ||
|
|
||
| const URI = HyperSwitch.URI; | ||
|
|
||
| class ParsoidJS extends Parsoid { | ||
|
|
||
| /** | ||
| * Assembles the request that is to be used to call the Parsoid service | ||
| * | ||
| * @param {Object} req the original request received by the module | ||
| * @param {string} path the path portion of the URI, without the domain or API version | ||
| * @param {Object} [headers] the headers to send, defaults to req.headers | ||
| * @param {Object} [body] the body of the request, defaults to undefined | ||
| * @return {Object} the request object to send | ||
| */ | ||
| _getParsoidReq(req, path, headers, body) { | ||
| return { | ||
| uri: new URI(`${this.parsoidUri}/${req.params.domain}/v3/${path}`), | ||
| headers: headers || req.headers, | ||
| body | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the URI of a bucket for the latest Parsoid content | ||
| * | ||
| * @param {string} domain the domain name | ||
| * @param {string} title the article title | ||
| * @return {HyperSwitch.URI} | ||
| */ | ||
| _getLatestBucketURI(domain, title) { | ||
| return new URI([ | ||
| domain, 'sys', 'key_value', 'parsoid', title | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the URI of a bucket for stashing Parsoid content. Used both for stashing | ||
| * original HTML/Data-Parsoid for normal edits as well as for stashing transforms | ||
| * | ||
| * @param {string} domain the domain name | ||
| * @param {string} title the article title | ||
| * @param {number} revision the revision of the article | ||
| * @param {string} tid the TID of the content | ||
| * @return {HyperSwitch.URI} | ||
| */ | ||
| _getStashBucketURI(domain, title, revision, tid) { | ||
| return new URI([ | ||
| domain, 'sys', 'key_value', 'parsoid-stash', `${title}:${revision}:${tid}` | ||
| ]); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| module.exports = (options = {}) => { | ||
| const ps = new ParsoidJS(options); | ||
| return { | ||
| spec, | ||
| operations: { | ||
| // Revision retrieval per format | ||
| getHtml: ps.getFormat.bind(ps, 'html'), | ||
| getDataParsoid: ps.getFormat.bind(ps, 'data-parsoid'), | ||
| getLintErrors: ps.getLintErrors.bind(ps), | ||
| // Transforms | ||
| transformHtmlToHtml: ps.makeTransform('html', 'html'), | ||
| transformHtmlToWikitext: ps.makeTransform('html', 'wikitext'), | ||
| transformWikitextToHtml: ps.makeTransform('wikitext', 'html'), | ||
| transformWikitextToLint: ps.makeTransform('wikitext', 'lint'), | ||
| transformChangesToWikitext: ps.makeTransform('changes', 'wikitext') | ||
| }, | ||
| // Dynamic resource dependencies, specific to implementation | ||
| resources: [ | ||
| { | ||
| uri: '/{domain}/sys/key_value/parsoid', | ||
| headers: { | ||
| 'content-type': 'application/json' | ||
| }, | ||
| body: { | ||
| valueType: 'blob' | ||
| } | ||
| }, | ||
| { | ||
| uri: '/{domain}/sys/key_value/parsoid-stash', | ||
| headers: { | ||
| 'content-type': 'application/json' | ||
| }, | ||
| body: { | ||
| valueType: 'blob', | ||
| default_time_to_live: options.grace_ttl || 86400 | ||
| } | ||
| } | ||
| ] | ||
| }; | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.