diff --git a/samples/js/dropbox/find-photos/src/main.js b/samples/js/dropbox/find-photos/src/main.js index dec1fcd452..fef9278b30 100644 --- a/samples/js/dropbox/find-photos/src/main.js +++ b/samples/js/dropbox/find-photos/src/main.js @@ -87,13 +87,15 @@ async function main(): Promise { let result = Promise.resolve(new Set()); // TODO: How to report progress? - await walk(input, db, (v: any) => { + await walk(input, db, async (v: any) => { if (isSubtype(sourceType, getTypeOfValue(v))) { + const resources = getResources(v); const photo: Object = { id: `https://github.com/attic-labs/noms/samples/js/dropbox/find-photos#${v.id}`, title: v.name, tags: new Set(), - sizes: getSizes(v), + sizes: await getSizes(resources), + resources: resources, dateTaken: newDate(v.media_info.metadata.time_taken), dateUpdated: newDate(v.server_modified), }; @@ -126,7 +128,15 @@ async function main(): Promise { }); } -function getSizes(input: Object): Map { +async function getSizes(resources: Map): Promise> { + const tuples = []; + await resources.forEach((v: any, k: Struct) => { + tuples.push([k, v.url]); + }); + return new Map(tuples); +} + +function getResources(input: Object): Map { const orig = input.media_info.metadata.dimensions; const kv = sizes.map(([width, height]) => { @@ -136,10 +146,12 @@ function getSizes(input: Object): Map { } return [ newStruct('', {width: resized.width, height: resized.height}), - getURL('files/get_thumbnail', { - path: input.id, - format: 'jpeg', - size: `w${width}h${height}`, + newStruct('RemoteResource', { + url: getURL('files/get_thumbnail', { + path: input.id, + format: 'jpeg', + size: `w${width}h${height}`, + }), }), ]; }); @@ -149,7 +161,9 @@ function getSizes(input: Object): Map { width: orig.width, height: orig.height, }), - getURL('files/download', {path: input.id}), + newStruct('RemoteResource', { + url: getURL('files/download', {path: input.id}), + }), ]); // $FlowIssue: Does not understand that filter removes all null values. diff --git a/samples/js/fb/find-photos/src/main.js b/samples/js/fb/find-photos/src/main.js index 65664d0cb5..3a57035111 100644 --- a/samples/js/fb/find-photos/src/main.js +++ b/samples/js/fb/find-photos/src/main.js @@ -93,6 +93,7 @@ async function main(): Promise { id: `https://github.com/attic-labs/noms/samples/js/fb/find-photos#${v.id}`, title: v.name || '', sizes: await getSizes(v), + resources: await getResources(v), tags: new Set(), // fb has 'tags', but they are actually people not textual tags datePublished: new NomsDate({nsSinceEpoch: v.created_time * 1e9}), dateUpdated: new NomsDate({nsSinceEpoch: v.updated_time * 1e9}), @@ -134,13 +135,25 @@ function getGeo(input): Struct { } async function getSizes(input): Promise> { - let result = Promise.resolve(new Map()); + const tuples = []; await input.images.forEach(v => { - result = result.then(m => m.set( + tuples.push([ newStruct('', {width: v.width, height: v.height}), - v.source)); + v.source, + ]); }); - return result; + return new Map(tuples); +} + +async function getResources(input): Promise> { + const tuples = []; + await input.images.forEach(v => { + tuples.push([ + newStruct('', {width: v.width, height: v.height}), + newStruct('RemoteResource', {url: v.source}), + ]); + }); + return new Map(tuples); } async function getFaces(photo): Promise> { diff --git a/samples/js/flickr/find-photos/src/main.js b/samples/js/flickr/find-photos/src/main.js index 52ccfe1608..8475baaa87 100644 --- a/samples/js/flickr/find-photos/src/main.js +++ b/samples/js/flickr/find-photos/src/main.js @@ -100,6 +100,7 @@ async function main(): Promise { title: v.title, tags: new Set(v.tags ? v.tags.split(' ') : []), sizes: getSizes(v), + resources: getResources(v), datePublished: newDate(Number(v.dateupload) * nsInSecond), dateUpdated: newDate(Number(v.lastupdate) * nsInSecond), }; @@ -159,6 +160,20 @@ function getSizes(input: Object): Map { return new Map(a.filter(kv => kv)); } +function getResources(input: Object): Map { + const a = sizes.map((s, i) => { + if (!isSubtype(sizeTypes[i], input.type)) { + return null; + } + const url = input['url_' + s]; + const width = Number(input['width_' + s]); + const height = Number(input['height_' + s]); + return [newStruct('', {width, height}), url]; + }); + // $FlowIssue: Does not understand that filter removes all null values. + return new Map(a.filter(kv => kv)); +} + function newDate(nsSinceEpoch: number): Struct { return newStruct('Date', {nsSinceEpoch}); } diff --git a/samples/js/picasa/find-photos/src/main.js b/samples/js/picasa/find-photos/src/main.js index fdbd8026e8..fdbaf7239d 100644 --- a/samples/js/picasa/find-photos/src/main.js +++ b/samples/js/picasa/find-photos/src/main.js @@ -105,10 +105,12 @@ async function main(): Promise { const w = parseInt(v.gphotoQ24width.Q24t, 10); const h = parseInt(v.gphotoQ24height.Q24t, 10); + const resources = await getResources(v, w, h); const photo: Object = { id: 'https://github.com/attic-labs/noms/samples/js/picasa/find-photos' + `#${v.gphotoQ24id.Q24t}`, - sizes: await getSizes(v, w, h), + sizes: await getSizes(resources), + resources: resources, datePublished: getDate(Date.parse(v.published.Q24t)), dateUpdated: getDate(Date.parse(v.updated.Q24t)), }; @@ -172,10 +174,19 @@ function getGeo(input): ?Struct { }); } -async function getSizes(input: Object, origWidth: number, origHeight: number) +async function getSizes(resources: Map) : Promise> { + const tuples = []; + await resources.forEach((v: any, k: Struct) => { + tuples.push([k, v.url]); + }); + return new Map(tuples); +} + +async function getResources(input: Object, origWidth: number, origHeight: number) + : Promise> { const thumbURL = (await input.mediaQ24group.mediaQ24thumbnail - .get(0)).url.split('/'); + .get(0)).url.split('/'); const sizePart = thumbURL.length - 2; const makeURL = s => { @@ -191,14 +202,14 @@ async function getSizes(input: Object, origWidth: number, origHeight: number) } return [ newStruct('', {width: r.width, height: r.height}), - makeURL(s), + newStruct('RemoteResource', {url: makeURL(s)}), ]; }).filter(t => t); // The original file. tuples.push([ newStruct('', {width: origWidth, height: origHeight}), - makeURL('d'), + newStruct('RemoteResource', {url: makeURL('d')}), ]); return new Map(tuples);