Commit 5ff69a70 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Files app: ES6 class forthumbnail_model.js metadata_item.js

Bug: 778674
Change-Id: I9ce3b37f51821c92326d6d028585ebb55ae97aab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1750502
Commit-Queue: Noel Gordon <noel@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686306}
parent 47fa14ee
......@@ -12,271 +12,273 @@
let ImageTransformation;
/**
* Metadata of a file. Doesn't have @struct to allow for '[]' computed property
* access.
* @constructor
* Metadata of a file.
* @unrestricted to allow access for properties via '.' or '[]', useful for
* computed properties.
*/
function MetadataItem() {
/**
* Size of the file. -1 for directory.
* @public {number|undefined}
*/
this.size;
/**
* @public {!Date|undefined}
*/
this.modificationTime;
/**
* @public {Error|undefined}
*/
this.modificationTimeError;
/**
* @public {!Date|undefined}
*/
this.modificationByMeTime;
/**
* Thumbnail URL obtained from external provider.
* @public {string|undefined}
*/
this.thumbnailUrl;
/**
* Cropped thumbnail URL obtained from external provider.
* @public {string|undefined}
*/
this.croppedThumbnailUrl;
/**
* @public {Error|undefined}
*/
this.croppedThumbnailUrlError;
/**
* @public {Error|undefined}
*/
this.thumbnailUrlError;
/**
* @public {number|undefined}
*/
this.imageWidth;
/**
* @public {number|undefined}
*/
this.imageHeight;
/**
* @public {number|undefined}
*/
this.imageRotation;
/**
* Thumbnail obtained from content provider.
* @public {string|undefined}
*/
this.contentThumbnailUrl;
/**
* @public {Error|undefined}
*/
this.contentThumbnailUrlError;
/**
* Thumbnail transformation obtained from content provider.
* @public {!ImageTransformation|undefined}
*/
this.contentThumbnailTransform;
/**
* @public {Error|undefined}
*/
this.contentThumbnailTransformError;
/**
* Image transformation obtained from content provider.
* @public {!ImageTransformation|undefined}
*/
this.contentImageTransform;
/**
* @public {Error|undefined}
*/
this.contentImageTransformError;
/**
* Whether the entry is pinned for ensuring it is available offline.
* @public {boolean|undefined}
*/
this.pinned;
/**
* Whether the entry is cached locally.
* @public {boolean|undefined}
*/
this.present;
/**
* @public {Error|undefined}
*/
this.presentError;
/**
* Whether the entry is hosted document of google drive.
* @public {boolean|undefined}
*/
this.hosted;
/**
* Whether the entry is modified locally and not synched yet.
* @public {boolean|undefined}
*/
this.dirty;
/**
* Whether the entry is present or hosted;
* @public {boolean|undefined}
*/
this.availableOffline;
/**
* @public {boolean|undefined}
*/
this.availableWhenMetered;
/**
* @public {string|undefined}
*/
this.customIconUrl;
/**
* @public {Error|undefined}
*/
this.customIconUrlError;
/**
* @public {string|undefined}
*/
this.contentMimeType;
/**
* Whether the entry is shared explicitly with me.
* @public {boolean|undefined}
*/
this.sharedWithMe;
/**
* Whether the entry is shared publicly.
* @public {boolean|undefined}
*/
this.shared;
/**
* URL for open a file in browser tab.
* @public {string|undefined}
*/
this.externalFileUrl;
/**
* @public {string|undefined}
*/
this.mediaAlbum;
/**
* @public {string|undefined}
*/
this.mediaArtist;
/**
* Audio or video duration in seconds.
* @public {number|undefined}
*/
this.mediaDuration;
/**
* @public {string|undefined}
*/
this.mediaGenre;
/**
* @public {string|undefined}
*/
this.mediaTitle;
/**
* @public {string|undefined}
*/
this.mediaTrack;
/**
* @public {string|undefined}
*/
this.mediaYearRecorded;
/**
* Mime type obtained by content provider based on URL.
* TODO(hirono): Remove the mediaMimeType.
* @public {string|undefined}
*/
this.mediaMimeType;
/**
* "Image File Directory" obtained from EXIF header.
* @public {!Object|undefined}
*/
this.ifd;
/**
* @public {boolean|undefined}
*/
this.exifLittleEndian;
/**
* @public {boolean|undefined}
*/
this.canCopy;
/**
* @public {boolean|undefined}
*/
this.canDelete;
/**
* @public {boolean|undefined}
*/
this.canRename;
/**
* @public {boolean|undefined}
*/
this.canAddChildren;
/**
* @public {boolean|undefined}
*/
this.canShare;
/**
* @public {string|undefined}
*/
this.alternateUrl;
/**
* @public {boolean|undefined}
*/
this.isMachineRoot;
/**
* @public {boolean|undefined}
*/
this.isArbitrarySyncFolder;
/**
* @public {boolean|undefined}
*/
this.isExternalMedia;
class MetadataItem {
constructor() {
/**
* Size of the file. -1 for directory.
* @public {number|undefined}
*/
this.size;
/**
* @public {!Date|undefined}
*/
this.modificationTime;
/**
* @public {Error|undefined}
*/
this.modificationTimeError;
/**
* @public {!Date|undefined}
*/
this.modificationByMeTime;
/**
* Thumbnail URL obtained from external provider.
* @public {string|undefined}
*/
this.thumbnailUrl;
/**
* Cropped thumbnail URL obtained from external provider.
* @public {string|undefined}
*/
this.croppedThumbnailUrl;
/**
* @public {Error|undefined}
*/
this.croppedThumbnailUrlError;
/**
* @public {Error|undefined}
*/
this.thumbnailUrlError;
/**
* @public {number|undefined}
*/
this.imageWidth;
/**
* @public {number|undefined}
*/
this.imageHeight;
/**
* @public {number|undefined}
*/
this.imageRotation;
/**
* Thumbnail obtained from content provider.
* @public {string|undefined}
*/
this.contentThumbnailUrl;
/**
* @public {Error|undefined}
*/
this.contentThumbnailUrlError;
/**
* Thumbnail transformation obtained from content provider.
* @public {!ImageTransformation|undefined}
*/
this.contentThumbnailTransform;
/**
* @public {Error|undefined}
*/
this.contentThumbnailTransformError;
/**
* Image transformation obtained from content provider.
* @public {!ImageTransformation|undefined}
*/
this.contentImageTransform;
/**
* @public {Error|undefined}
*/
this.contentImageTransformError;
/**
* Whether the entry is pinned for ensuring it is available offline.
* @public {boolean|undefined}
*/
this.pinned;
/**
* Whether the entry is cached locally.
* @public {boolean|undefined}
*/
this.present;
/**
* @public {Error|undefined}
*/
this.presentError;
/**
* Whether the entry is hosted document of google drive.
* @public {boolean|undefined}
*/
this.hosted;
/**
* Whether the entry is modified locally and not synched yet.
* @public {boolean|undefined}
*/
this.dirty;
/**
* Whether the entry is present or hosted;
* @public {boolean|undefined}
*/
this.availableOffline;
/**
* @public {boolean|undefined}
*/
this.availableWhenMetered;
/**
* @public {string|undefined}
*/
this.customIconUrl;
/**
* @public {Error|undefined}
*/
this.customIconUrlError;
/**
* @public {string|undefined}
*/
this.contentMimeType;
/**
* Whether the entry is shared explicitly with me.
* @public {boolean|undefined}
*/
this.sharedWithMe;
/**
* Whether the entry is shared publicly.
* @public {boolean|undefined}
*/
this.shared;
/**
* URL for open a file in browser tab.
* @public {string|undefined}
*/
this.externalFileUrl;
/**
* @public {string|undefined}
*/
this.mediaAlbum;
/**
* @public {string|undefined}
*/
this.mediaArtist;
/**
* Audio or video duration in seconds.
* @public {number|undefined}
*/
this.mediaDuration;
/**
* @public {string|undefined}
*/
this.mediaGenre;
/**
* @public {string|undefined}
*/
this.mediaTitle;
/**
* @public {string|undefined}
*/
this.mediaTrack;
/**
* @public {string|undefined}
*/
this.mediaYearRecorded;
/**
* Mime type obtained by content provider based on URL.
* TODO(hirono): Remove the mediaMimeType.
* @public {string|undefined}
*/
this.mediaMimeType;
/**
* "Image File Directory" obtained from EXIF header.
* @public {!Object|undefined}
*/
this.ifd;
/**
* @public {boolean|undefined}
*/
this.exifLittleEndian;
/**
* @public {boolean|undefined}
*/
this.canCopy;
/**
* @public {boolean|undefined}
*/
this.canDelete;
/**
* @public {boolean|undefined}
*/
this.canRename;
/**
* @public {boolean|undefined}
*/
this.canAddChildren;
/**
* @public {boolean|undefined}
*/
this.canShare;
/**
* @public {string|undefined}
*/
this.alternateUrl;
/**
* @public {boolean|undefined}
*/
this.isMachineRoot;
/**
* @public {boolean|undefined}
*/
this.isArbitrarySyncFolder;
/**
* @public {boolean|undefined}
*/
this.isExternalMedia;
}
}
......@@ -8,96 +8,97 @@
*/
let ThumbnailMetadataItem;
/**
* @param {!MetadataModel} metadataModel
* @struct
* @constructor
*/
function ThumbnailModel(metadataModel) {
class ThumbnailModel {
/**
* @private {!MetadataModel}
* @const
* @param {!MetadataModel} metadataModel
*/
this.metadataModel_ = metadataModel;
}
constructor(metadataModel) {
/**
* @private {!MetadataModel}
* @const
*/
this.metadataModel_ = metadataModel;
}
/**
* @param {!Array<!Entry>} entries
* @return {Promise<ThumbnailMetadataItem>} Promise fulfilled with old format
* metadata list.
*/
ThumbnailModel.prototype.get = function(entries) {
const results = {};
return this.metadataModel_
.get(
entries,
[
'modificationTime', 'customIconUrl', 'contentMimeType',
'thumbnailUrl', 'croppedThumbnailUrl', 'present'
])
.then(metadataList => {
const contentRequestEntries = [];
for (let i = 0; i < entries.length; i++) {
const url = entries[i].toURL();
// TODO(hirono): Use the provider results directly after removing code
// using old metadata format.
results[url] = {
filesystem: {
modificationTime: metadataList[i].modificationTime,
modificationTimeError: metadataList[i].modificationTimeError
},
external: {
thumbnailUrl: metadataList[i].thumbnailUrl,
thumbnailUrlError: metadataList[i].thumbnailUrlError,
croppedThumbnailUrl: metadataList[i].croppedThumbnailUrl,
croppedThumbnailUrlError:
metadataList[i].croppedThumbnailUrlError,
customIconUrl: metadataList[i].customIconUrl,
customIconUrlError: metadataList[i].customIconUrlError,
present: metadataList[i].present,
presentError: metadataList[i].presentError
},
thumbnail: {},
media: {}
};
const canUseContentThumbnail = metadataList[i].present &&
(FileType.isImage(entries[i], metadataList[i].contentMimeType) ||
FileType.isAudio(entries[i], metadataList[i].contentMimeType));
if (canUseContentThumbnail) {
contentRequestEntries.push(entries[i]);
/**
* @param {!Array<!Entry>} entries
* @return {Promise<ThumbnailMetadataItem>} Promise fulfilled with old format
* metadata list.
*/
get(entries) {
const results = {};
return this.metadataModel_
.get(
entries,
[
'modificationTime', 'customIconUrl', 'contentMimeType',
'thumbnailUrl', 'croppedThumbnailUrl', 'present'
])
.then(metadataList => {
const contentRequestEntries = [];
for (let i = 0; i < entries.length; i++) {
const url = entries[i].toURL();
// TODO(hirono): Use the provider results directly after removing
// code using old metadata format.
results[url] = {
filesystem: {
modificationTime: metadataList[i].modificationTime,
modificationTimeError: metadataList[i].modificationTimeError
},
external: {
thumbnailUrl: metadataList[i].thumbnailUrl,
thumbnailUrlError: metadataList[i].thumbnailUrlError,
croppedThumbnailUrl: metadataList[i].croppedThumbnailUrl,
croppedThumbnailUrlError:
metadataList[i].croppedThumbnailUrlError,
customIconUrl: metadataList[i].customIconUrl,
customIconUrlError: metadataList[i].customIconUrlError,
present: metadataList[i].present,
presentError: metadataList[i].presentError
},
thumbnail: {},
media: {}
};
const canUseContentThumbnail = metadataList[i].present &&
(FileType.isImage(
entries[i], metadataList[i].contentMimeType) ||
FileType.isAudio(entries[i], metadataList[i].contentMimeType));
if (canUseContentThumbnail) {
contentRequestEntries.push(entries[i]);
}
}
}
if (contentRequestEntries.length) {
return this.metadataModel_
.get(
contentRequestEntries,
[
'contentThumbnailUrl',
'contentThumbnailTransform',
'contentImageTransform',
])
.then(contentMetadataList => {
for (let i = 0; i < contentRequestEntries.length; i++) {
const url = contentRequestEntries[i].toURL();
results[url].thumbnail.url =
contentMetadataList[i].contentThumbnailUrl;
results[url].thumbnail.urlError =
contentMetadataList[i].contentThumbnailUrlError;
results[url].thumbnail.transform =
contentMetadataList[i].contentThumbnailTransform;
results[url].thumbnail.transformError =
contentMetadataList[i].contentThumbnailTransformError;
results[url].media.imageTransform =
contentMetadataList[i].contentImageTransform;
results[url].media.imageTransformError =
contentMetadataList[i].contentImageTransformError;
}
});
}
})
.then(() => {
return entries.map(entry => {
return results[entry.toURL()];
if (contentRequestEntries.length) {
return this.metadataModel_
.get(
contentRequestEntries,
[
'contentThumbnailUrl',
'contentThumbnailTransform',
'contentImageTransform',
])
.then(contentMetadataList => {
for (let i = 0; i < contentRequestEntries.length; i++) {
const url = contentRequestEntries[i].toURL();
results[url].thumbnail.url =
contentMetadataList[i].contentThumbnailUrl;
results[url].thumbnail.urlError =
contentMetadataList[i].contentThumbnailUrlError;
results[url].thumbnail.transform =
contentMetadataList[i].contentThumbnailTransform;
results[url].thumbnail.transformError =
contentMetadataList[i].contentThumbnailTransformError;
results[url].media.imageTransform =
contentMetadataList[i].contentImageTransform;
results[url].media.imageTransformError =
contentMetadataList[i].contentImageTransformError;
}
});
}
})
.then(() => {
return entries.map(entry => {
return results[entry.toURL()];
});
});
});
};
}
}
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