mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-13 03:10:03 -05:00
Add resources field to find-photo's Photo object (#2778)
This commit is contained in:
@@ -87,13 +87,15 @@ async function main(): Promise<void> {
|
||||
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<void> {
|
||||
});
|
||||
}
|
||||
|
||||
function getSizes(input: Object): Map<Struct, string> {
|
||||
async function getSizes(resources: Map<Struct, Struct>): Promise<Map<Struct, string>> {
|
||||
const tuples = [];
|
||||
await resources.forEach((v: any, k: Struct) => {
|
||||
tuples.push([k, v.url]);
|
||||
});
|
||||
return new Map(tuples);
|
||||
}
|
||||
|
||||
function getResources(input: Object): Map<Struct, Struct> {
|
||||
const orig = input.media_info.metadata.dimensions;
|
||||
|
||||
const kv = sizes.map(([width, height]) => {
|
||||
@@ -136,10 +146,12 @@ function getSizes(input: Object): Map<Struct, string> {
|
||||
}
|
||||
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<Struct, string> {
|
||||
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.
|
||||
|
||||
@@ -93,6 +93,7 @@ async function main(): Promise<void> {
|
||||
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<Map<Struct, string>> {
|
||||
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<Map<Struct, Struct>> {
|
||||
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<Set<Struct>> {
|
||||
|
||||
@@ -100,6 +100,7 @@ async function main(): Promise<void> {
|
||||
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<Struct, string> {
|
||||
return new Map(a.filter(kv => kv));
|
||||
}
|
||||
|
||||
function getResources(input: Object): Map<Struct, Struct> {
|
||||
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});
|
||||
}
|
||||
|
||||
@@ -105,10 +105,12 @@ async function main(): Promise<void> {
|
||||
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<Struct, Struct>)
|
||||
: Promise<Map<Struct, string>> {
|
||||
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<Map<Struct, Struct>> {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user