aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/apis/google_docs/GooglePhotosClientUtils.ts17
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx13
-rw-r--r--src/server/apis/google/GooglePhotosUploadUtils.ts8
-rw-r--r--src/server/credentials/google_docs_token.json2
-rw-r--r--src/server/index.ts2
5 files changed, 27 insertions, 15 deletions
diff --git a/src/client/apis/google_docs/GooglePhotosClientUtils.ts b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
index 49eb5b354..700c0401a 100644
--- a/src/client/apis/google_docs/GooglePhotosClientUtils.ts
+++ b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
@@ -135,13 +135,15 @@ export namespace GooglePhotos {
export namespace Query {
+ const delimiter = ", ";
export const TagChildImages = async (collection: Doc) => {
const idMapping = await Cast(collection.googlePhotosIdMapping, Doc);
if (!idMapping) {
throw new Error("Appending image metadata requires that the targeted collection have already been mapped to an album!");
}
+ const tagMapping = new Map<string, string>();
const images = await DocListCastAsync(collection.data);
- images && images.forEach(image => image.googlePhotosTags = new List([ContentCategories.NONE]));
+ images && images.forEach(image => tagMapping.set(image[Id], ContentCategories.NONE));
const values = Object.values(ContentCategories);
for (let value of values) {
if (value !== ContentCategories.NONE) {
@@ -151,9 +153,10 @@ export namespace GooglePhotos {
for (let id of ids) {
const image = await Cast(idMapping[id], Doc);
if (image) {
- const tags = Cast(image.googlePhotosTags, listSpec("string"))!;
+ const key = image[Id];
+ const tags = tagMapping.get(key)!;
if (!tags.includes(value)) {
- tags.push(value);
+ tagMapping.set(key, tags + delimiter + value);
}
}
}
@@ -161,9 +164,11 @@ export namespace GooglePhotos {
}
}
images && images.forEach(image => {
- const tags = Cast(image.googlePhotosTags, listSpec("string"))!;
- if (tags.includes(ContentCategories.NONE) && tags.length > 1) {
- image.googlePhotosTags = new List(tags.splice(tags.indexOf(ContentCategories.NONE), 1));
+ const concatenated = tagMapping.get(image[Id])!;
+ const tags = concatenated.split(delimiter);
+ if (tags.length > 1) {
+ const cleaned = concatenated.replace(ContentCategories.NONE + delimiter, "");
+ image.googlePhotosTags = cleaned.split(delimiter).sort((a, b) => (a < b) ? -1 : (a > b ? 1 : 0)).join(delimiter);
}
});
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index a7acd9e91..1af534ecd 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -98,7 +98,7 @@ export namespace PivotView {
groups.forEach((val, key) => minSize = Math.min(minSize, val.length));
const numCols = NumCast(collection.pivotNumColumns) || Math.ceil(Math.sqrt(minSize));
- const fontSize = NumCast(collection.pivotFontSize);
+ const fontSize = NumCast(collection.pivotFontSize, 30);
const docMap = new Map<Doc, ViewDefBounds>();
const groupNames: PivotData[] = [];
@@ -113,7 +113,8 @@ export namespace PivotView {
x,
y: width + 50,
width: width * 1.25 * numCols,
- height: 100, fontSize: fontSize
+ height: 100,
+ fontSize
});
for (const doc of val) {
docMap.set(doc, {
@@ -701,7 +702,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) {
return result.result === undefined ? { x: Cast(doc.x, "number"), y: Cast(doc.y, "number"), z: Cast(doc.z, "number"), width: Cast(doc.width, "number"), height: Cast(doc.height, "number") } : result.result;
}
- viewDefsToJSX = (views: any[]) => {
+ viewDefsToJSX = (views: PivotView.PivotData[]) => {
let elements: ViewDefResult[] = [];
if (Array.isArray(views)) {
elements = views.reduce<typeof elements>((prev, ele) => {
@@ -713,12 +714,12 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) {
return elements;
}
- private viewDefToJSX(viewDef: any): Opt<ViewDefResult> {
+ private viewDefToJSX(viewDef: PivotView.PivotData): Opt<ViewDefResult> {
if (viewDef.type === "text") {
const text = Cast(viewDef.text, "string");
const x = Cast(viewDef.x, "number");
const y = Cast(viewDef.y, "number");
- const z = Cast(viewDef.z, "number");
+ // const z = Cast(viewDef.z, "number");
const width = Cast(viewDef.width, "number");
const height = Cast(viewDef.height, "number");
const fontSize = Cast(viewDef.fontSize, "number");
@@ -730,7 +731,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) {
ele: <div className="collectionFreeform-customText" style={{
transform: `translate(${x}px, ${y}px)`,
width, height, fontSize
- }}>{text}</div>, bounds: { x: x!, y: y!, z: z, width: width!, height: height! }
+ }}>{text}</div>, bounds: { x: x!, y: y!, width: width!, height: height! }
};
}
}
diff --git a/src/server/apis/google/GooglePhotosUploadUtils.ts b/src/server/apis/google/GooglePhotosUploadUtils.ts
index 7f47259db..51642e345 100644
--- a/src/server/apis/google/GooglePhotosUploadUtils.ts
+++ b/src/server/apis/google/GooglePhotosUploadUtils.ts
@@ -6,6 +6,7 @@ import * as path from 'path';
import { Opt } from '../../../new_fields/Doc';
import * as sharp from 'sharp';
import { MediaItemCreationResult, NewMediaItemResult } from './SharedTypes';
+import { reject } from 'bluebird';
const uploadDirectory = path.join(__dirname, "../../public/files/");
@@ -50,7 +51,12 @@ export namespace GooglePhotosUploadUtils {
uri: prepend('uploads'),
body
};
- return new Promise<any>(resolve => request(parameters, (error, _response, body) => resolve(error ? undefined : body)));
+ return new Promise<any>(resolve => request(parameters, (error, _response, body) => {
+ if (error) {
+ return reject(error);
+ }
+ resolve(body);
+ }));
};
diff --git a/src/server/credentials/google_docs_token.json b/src/server/credentials/google_docs_token.json
index c58287bee..7442c643a 100644
--- a/src/server/credentials/google_docs_token.json
+++ b/src/server/credentials/google_docs_token.json
@@ -1 +1 @@
-{"access_token":"ya29.ImCBBwOPA7RqPIoh9RrZn90HLJnYAazRjts5R17yNQi9QLENQiChUUIUjcsTqbL-4cs_TK7UbEID6pR0w71gyTjVnA5uBcPJFcAaZ-GRPtheXx0PDU4oqSWHYoqlNQQKjn4","refresh_token":"1/HTv_xFHszu2Nf3iiFrUTaeKzC_Vp2-6bpIB06xW_WHI","scope":"https://www.googleapis.com/auth/presentations.readonly https://www.googleapis.com/auth/documents.readonly https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/documents https://www.googleapis.com/auth/photoslibrary https://www.googleapis.com/auth/photoslibrary.appendonly https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/presentations https://www.googleapis.com/auth/photoslibrary.sharing","token_type":"Bearer","expiry_date":1568239483409} \ No newline at end of file
+{"access_token":"ya29.GlyBB9xlRimL3pw4tgNg7g7wcr73JWyQd4-XZbgOvngFM_sYUgsWP0YV7XCez5u6nytEfrOm228Sadj52wluJ46cJGhj2IwtSbW9GYzHHiiD-ts0i1phIV3n28wo5A","refresh_token":"1/HTv_xFHszu2Nf3iiFrUTaeKzC_Vp2-6bpIB06xW_WHI","scope":"https://www.googleapis.com/auth/presentations.readonly https://www.googleapis.com/auth/documents.readonly https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/documents https://www.googleapis.com/auth/photoslibrary https://www.googleapis.com/auth/photoslibrary.appendonly https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/presentations https://www.googleapis.com/auth/photoslibrary.sharing","token_type":"Bearer","expiry_date":1568254634977} \ No newline at end of file
diff --git a/src/server/index.ts b/src/server/index.ts
index 388c8cd4d..9a2bd9a3a 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -821,7 +821,7 @@ app.post(RouteStore.googlePhotosMediaUpload, async (req, res) => {
const media: GooglePhotosUploadUtils.MediaInput[] = req.body.media;
await GooglePhotosUploadUtils.initialize({ uploadDirectory, credentialsPath, tokenPath });
const newMediaItems = await Promise.all(media.map(async element => {
- const uploadToken = await GooglePhotosUploadUtils.DispatchGooglePhotosUpload(element.url);
+ const uploadToken = await GooglePhotosUploadUtils.DispatchGooglePhotosUpload(element.url).catch(error => _error(res, tokenError, error));
return !uploadToken ? undefined : {
description: element.description,
simpleMediaItem: { uploadToken }