Commit c4ad6cdc authored by Nick Stenning's avatar Nick Stenning

Use document fingerprint, not URL, as primary URI for PDFs

Consider the following situation:

- A PDF with fingerprint (F) exists at multiple URLs (U1, U2, ...)
- A user visits the PDF at U1 and annotates it
- A second user visits the PDF at U2

Prior to this commit, due to the way document equivalence for PDFs
functions, the annotations made at U1 will not be loaded, because the
initial search is made for U2 only.

(If the second user subsequently makes annotations at U2, and then
reloads the page, the annotations made at U1 will then show up, as the
association between U2 and F will have been made).

This commit improves the situation here by treating the PDF fingerprint
as the "primary URI" for the document, much as we treat <link
rel="canonical"> URLs as "primary" if we find them in an HTML page.

This means that the initial search will be made for the fingerprint F,
which will match the annotations made at U1.

For more, see:

  https://trello.com/c/DVUemKwi/329-use-pdf-fingerprint-as-primary-search-uri-for-pdfs
parent 533b5f4b
......@@ -27,7 +27,7 @@ function PDFMetadata(app) {
*/
PDFMetadata.prototype.getUri = function () {
return this._loaded.then(function (app) {
return app.url;
return fingerprintToURN(app.documentFingerprint);
});
};
......
......@@ -10,11 +10,11 @@ describe('pdf-metadata', function () {
var event = document.createEvent('Event');
event.initEvent('documentload', false, false);
fakeApp.url = 'http://example.com/foo.pdf';
fakeApp.documentFingerprint = 'fakeFingerprint';
window.dispatchEvent(event);
return pdfMetadata.getUri().then(function (uri) {
assert.equal('http://example.com/foo.pdf', uri);
assert.equal('urn:x-pdf:fakeFingerprint', uri);
});
});
});
......@@ -39,9 +39,9 @@ describe('pdf-metadata', function () {
});
describe('#getUri', function () {
it('returns the PDF URL as its URI', function () {
it('returns the URN-ified document fingerprint as its URI', function () {
return pdfMetadata.getUri().then(function (uri) {
assert.equal('fakeUrl', uri);
assert.equal('urn:x-pdf:fakeFingerprint', uri);
});
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment