-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only request diffs for types we can diff
This got much more complex than anticipated! There are a few major bits here: - We now have a `MediaType` type for modeling and comparing different media types. It includes a concept of canonical types, so `parseMediaType('text/html').equals(parseMediaType('application/xhtml')) === true`. If we can reliably clean this up in the DB, we can get rid of that, but it's useful for now. Similarly, we can also get media types for file extensions (it only supports a minimal list of extensions we know we have in the DB). Once the DB has content types for all versions, we can get rid of that, too. - The `diffTypes` module now has a `diffTypesFor(mediaType)` method, allowing us to get the diffs that are appropriate to present for a given type of content. We've also added three "raw" diff types which indicate we should simply show the content in an `<iframe>` because we don't know how to diff it (or if the two versions in question have differing content types, which often happens when a PDF or image responded with an HTML error page [like a 404] for a given version). - The `SelectDiffType` form control now takes a list of diff types (from the above `diffTypesFor()`) to show. - There's a little extra complexity in retrieving an actual diff where we check to see if the diff type has an actual diff service associated with it ("raw" types don't, because they represent viewing the actual content, not a diff). We request the actual raw content there because we need to sniff it for HTML (when we present HTML, we need to set a `<base>` tag so associated images, styles, and scripts work). This part is definitely a little janky, but I don't see a clear improvement without a lot more other changes. It slightly exacerbates the existing race condition issue. The sniffing HTML situation should/could probably be fixed alongside edgi-govdata-archiving/web-monitoring#92, where we basically need some kind of proxy or pre-cleaned-up version to render. - Finally, this makes a slight tweak to the 'no changes' message; it shows a message indicating two versions are exactly the same if their hashes are identical, but shows the old message (with slightly more detail) if the hashes are different but `change_count` is 0. Fixes #179.
- Loading branch information
Showing
7 changed files
with
353 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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 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,34 @@ | ||
import React from 'react'; | ||
import SandboxedHtml from './sandboxed-html'; | ||
|
||
/** | ||
* @typedef {Object} RawVersionProps | ||
* @property {Page} page The page this diff pertains to | ||
* @property {Version} version | ||
* @property {string} content | ||
*/ | ||
|
||
/** | ||
* Display the raw content of a version. | ||
* | ||
* @class RawVersion | ||
* @extends {React.Component} | ||
* @param {RawVersionProps} props | ||
*/ | ||
export default class RawVersion extends React.Component { | ||
render () { | ||
if (this.props.content && /^[\s\n\r]*</.test(this.props.content)) { | ||
return ( | ||
<div className="inline-render"> | ||
<SandboxedHtml html={this.props.content} baseUrl={this.props.page.url} /> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="inline-render"> | ||
<iframe src={this.props.version.uri} /> | ||
</div> | ||
); | ||
} | ||
} |
This file contains 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 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,36 @@ | ||
import React from 'react'; | ||
import SandboxedHtml from './sandboxed-html'; | ||
|
||
/** | ||
* @typedef {Object} SideBySideRawVersionsProps | ||
* @property {DiffData} diffData Object containing diff to render and its metadata | ||
* @property {Page} page The page this diff pertains to | ||
* @property {Version} a | ||
* @property {Version} b | ||
*/ | ||
|
||
/** | ||
* Display two versions of a page, side-by-side. | ||
* | ||
* @class SideBySideRawVersions | ||
* @extends {React.Component} | ||
* @param {SideBySideRawVersionsProps} props | ||
*/ | ||
export default class SideBySideRawVersions extends React.Component { | ||
render () { | ||
return ( | ||
<div className="side-by-side-render"> | ||
{renderVersion(this.props.page, this.props.a, this.props.diffData.rawA)} | ||
{renderVersion(this.props.page, this.props.b, this.props.diffData.rawB)} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
function renderVersion (page, version, content) { | ||
if (content && /^[\s\n\r]*</.test(content)) { | ||
return <SandboxedHtml html={contentcontent} baseUrl={page.url} />; | ||
} | ||
|
||
return <iframe src={version.uri} />; | ||
} |
This file contains 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
Oops, something went wrong.