1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 * Obtains the entry set from the entries passed from onLaunched events.
9 * If an single entry is specified, the function returns all entries in the same
10 * directory. Otherwise the function returns the passed entries.
12 * The function also filters non-image items and hidden items.
14 * @param {!Array.<!FileEntry>} originalEntries Entries passed from onLaunched
16 * @return {!Promise} Promise to be fulfilled with entry array.
18 GalleryUtil.createEntrySet = function(originalEntries) {
20 if (originalEntries.length === 1) {
22 new Promise(originalEntries[0].getParent.bind(originalEntries[0]));
23 entriesPromise = parentPromise.then(function(parent) {
24 var reader = parent.createReader();
25 var readEntries = function() {
26 return new Promise(reader.readEntries.bind(reader)).then(
28 if (entries.length === 0)
30 return readEntries().then(function(nextEntries) {
31 return entries.concat(nextEntries);
36 }).then(function(entries) {
37 return entries.filter(function(entry) {
38 return originalEntries[0].toURL() === entry.toURL() ||
39 entry.name[0] !== '.';
43 entriesPromise = Promise.resolve(originalEntries);
46 return entriesPromise.then(function(entries) {
47 return entries.filter(function(entry) {
48 return FileType.isImage(entry) || FileType.isRaw(entry);
49 }).sort(function(a, b) {
50 return a.name.localeCompare(b.name);