Merge pull request #12645 from Snuffleupagus/async-PDFDocumentProperties-open

Convert the `PDFDocumentProperties.open` method to be async
This commit is contained in:
Tim van der Meij 2020-11-21 14:42:48 +01:00 committed by GitHub
commit d88d47d621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -97,7 +97,7 @@ class PDFDocumentProperties {
/**
* Open the document properties overlay.
*/
open() {
async open() {
const freezeFieldData = data => {
Object.defineProperty(this, "fieldData", {
value: Object.freeze(data),
@ -107,10 +107,10 @@ class PDFDocumentProperties {
});
};
Promise.all([
await Promise.all([
this.overlayManager.open(this.overlayName),
this._dataAvailableCapability.promise,
]).then(() => {
]);
const currentPageNumber = this._currentPageNumber;
const pagesRotation = this._pagesRotation;
@ -126,38 +126,31 @@ class PDFDocumentProperties {
}
// Get the document properties.
this.pdfDocument
.getMetadata()
.then(
({ info, metadata, contentDispositionFilename, contentLength }) => {
return Promise.all([
const {
info,
metadata,
/* metadata, */
contentDispositionFilename,
contentLength,
} = await this.pdfDocument.getMetadata();
const [
fileName,
fileSize,
creationDate,
modificationDate,
pageSize,
isLinearized,
] = await Promise.all([
contentDispositionFilename || getPDFFileNameFromURL(this.url),
this._parseFileSize(contentLength),
this._parseDate(info.CreationDate),
this._parseDate(info.ModDate),
this.pdfDocument.getPage(currentPageNumber).then(pdfPage => {
return this._parsePageSize(
getPageSizeInches(pdfPage),
pagesRotation
);
return this._parsePageSize(getPageSizeInches(pdfPage), pagesRotation);
}),
this._parseLinearization(info.IsLinearized),
]);
}
)
.then(
([
info,
metadata,
fileName,
fileSize,
creationDate,
modDate,
pageSize,
isLinearized,
]) => {
freezeFieldData({
fileName,
fileSize,
@ -166,7 +159,7 @@ class PDFDocumentProperties {
subject: info.Subject,
keywords: info.Keywords,
creationDate,
modificationDate: modDate,
modificationDate,
creator: info.Creator,
producer: info.Producer,
version: info.PDFFormatVersion,
@ -180,22 +173,15 @@ class PDFDocumentProperties {
// Get the correct fileSize, since it may not have been available
// or could potentially be wrong.
return this.pdfDocument.getDownloadInfo().then(downloadInfo => {
return this._parseFileSize(downloadInfo.length);
});
}
)
.then(fileSize => {
if (fileSize === this.fieldData.fileSize) {
const { length } = await this.pdfDocument.getDownloadInfo();
if (contentLength === length) {
return; // The fileSize has already been correctly set.
}
const data = Object.assign(Object.create(null), this.fieldData);
data.fileSize = fileSize;
data.fileSize = await this._parseFileSize(length);
freezeFieldData(data);
this._updateUI();
});
});
}
/**