aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/apis/google_docs/GooglePhotosClientUtils.ts22
-rw-r--r--src/client/views/MainView.tsx6
2 files changed, 25 insertions, 3 deletions
diff --git a/src/client/apis/google_docs/GooglePhotosClientUtils.ts b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
index 67a282f48..0864ebdb1 100644
--- a/src/client/apis/google_docs/GooglePhotosClientUtils.ts
+++ b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
@@ -1,6 +1,7 @@
import { Album } from "../../../server/apis/google/typings/albums";
import { PostToServer } from "../../../Utils";
import { RouteStore } from "../../../server/RouteStore";
+import { ImageField } from "../../../new_fields/URLField";
export namespace GooglePhotosClientUtils {
@@ -9,7 +10,7 @@ export namespace GooglePhotosClientUtils {
action: Album.Action.Create,
body: { album: { title } }
} as Album.Create;
- return PostToServer(RouteStore.googlePhotos, parameters);
+ return PostToServer(RouteStore.googlePhotosQuery, parameters);
};
export const List = async (options?: Partial<Album.ListOptions>) => {
@@ -21,7 +22,7 @@ export namespace GooglePhotosClientUtils {
excludeNonAppCreatedData: (options ? options.excludeNonAppCreatedData : false) || false,
} as Album.ListOptions
} as Album.List;
- return PostToServer(RouteStore.googlePhotos, parameters);
+ return PostToServer(RouteStore.googlePhotosQuery, parameters);
};
export const Get = async (albumId: string) => {
@@ -29,7 +30,22 @@ export namespace GooglePhotosClientUtils {
action: Album.Action.Get,
albumId
} as Album.Get;
- return PostToServer(RouteStore.googlePhotos, parameters);
+ return PostToServer(RouteStore.googlePhotosQuery, parameters);
+ };
+
+ export const toDataURL = (field: ImageField | undefined) => {
+ if (!field) {
+ return undefined;
+ }
+ const image = document.createElement("img");
+ image.src = field.url.href;
+ const canvas = document.createElement("canvas");
+ canvas.width = image.width;
+ canvas.height = image.height;
+ const ctx = canvas.getContext("2d")!;
+ ctx.drawImage(image, 0, 0);
+ const dataUrl = canvas.toDataURL("image/png");
+ return dataUrl.replace(/^data:image\/(png|jpg);base64,/, "");
};
} \ No newline at end of file
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index 3ee62ae86..590addaa3 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -44,6 +44,7 @@ import { GoogleApiClientUtils } from '../apis/google_docs/GoogleApiClientUtils';
import { docs_v1 } from 'googleapis';
import { Album } from '../../server/apis/google/typings/albums';
import { GooglePhotosClientUtils } from '../apis/google_docs/GooglePhotosClientUtils';
+import { ImageField } from '../../new_fields/URLField';
@observer
export class MainView extends React.Component {
@@ -130,6 +131,11 @@ export class MainView extends React.Component {
window.removeEventListener("keydown", KeyManager.Instance.handle);
window.addEventListener("keydown", KeyManager.Instance.handle);
+ let imgurl = "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg";
+ let image = Docs.Create.ImageDocument(imgurl, { width: 200, title: "an image of a cat" });
+ let parameters = { title: StrCast(image.title), MEDIA_BINARY_DATA: GooglePhotosClientUtils.toDataURL(Cast(image.data, ImageField)) };
+ PostToServer(RouteStore.googlePhotosMediaUpload, parameters).then(console.log);
+
reaction(() => {
let workspaces = CurrentUserUtils.UserDocument.workspaces;
let recent = CurrentUserUtils.UserDocument.recentlyClosed;