aboutsummaryrefslogtreecommitdiff
path: root/src/client/apis
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2019-12-03 01:46:36 -0500
committerSam Wilkins <samwilkins333@gmail.com>2019-12-03 01:46:36 -0500
commitef94ad7df2a087141ddb8d347d3e3c484ff7609b (patch)
treea7c16be04ff4050da1ff03e02f59df6da4f5f7e2 /src/client/apis
parent62c888ad25c5580441eaf947a1a0f1638939b868 (diff)
const linter rule and restored google docs push, fixed routing
Diffstat (limited to 'src/client/apis')
-rw-r--r--src/client/apis/GoogleAuthenticationManager.tsx2
-rw-r--r--src/client/apis/google_docs/GoogleApiClientUtils.ts20
-rw-r--r--src/client/apis/google_docs/GooglePhotosClientUtils.ts16
-rw-r--r--src/client/apis/youtube/YoutubeBox.tsx102
4 files changed, 70 insertions, 70 deletions
diff --git a/src/client/apis/GoogleAuthenticationManager.tsx b/src/client/apis/GoogleAuthenticationManager.tsx
index ae77c4b7b..ce1277667 100644
--- a/src/client/apis/GoogleAuthenticationManager.tsx
+++ b/src/client/apis/GoogleAuthenticationManager.tsx
@@ -30,7 +30,7 @@ export default class GoogleAuthenticationManager extends React.Component<{}> {
}
public fetchOrGenerateAccessToken = async () => {
- let response = await Networking.FetchFromServer("/readGoogleAccessToken");
+ const response = await Networking.FetchFromServer("/readGoogleAccessToken");
// if this is an authentication url, activate the UI to register the new access token
if (new RegExp(AuthenticationUrl).test(response)) {
this.isOpen = true;
diff --git a/src/client/apis/google_docs/GoogleApiClientUtils.ts b/src/client/apis/google_docs/GoogleApiClientUtils.ts
index 26c7f8d2e..d2a79f189 100644
--- a/src/client/apis/google_docs/GoogleApiClientUtils.ts
+++ b/src/client/apis/google_docs/GoogleApiClientUtils.ts
@@ -1,4 +1,4 @@
-import { docs_v1, slides_v1 } from "googleapis";
+import { docs_v1 } from "googleapis";
import { Opt } from "../../../new_fields/Doc";
import { isArray } from "util";
import { EditorState } from "prosemirror-state";
@@ -94,7 +94,7 @@ export namespace GoogleApiClientUtils {
export type ExtractResult = { text: string, paragraphs: DeconstructedParagraph[] };
export const extractText = (document: docs_v1.Schema$Document, removeNewlines = false): ExtractResult => {
- let paragraphs = extractParagraphs(document);
+ const paragraphs = extractParagraphs(document);
let text = paragraphs.map(paragraph => paragraph.contents.filter(content => !("inlineObjectId" in content)).map(run => run as docs_v1.Schema$TextRun).join("")).join("");
text = text.substring(0, text.length - 1);
removeNewlines && text.ReplaceAll("\n", "");
@@ -107,14 +107,14 @@ export namespace GoogleApiClientUtils {
const fragments: DeconstructedParagraph[] = [];
if (document.body && document.body.content) {
for (const element of document.body.content) {
- let runs: ContentArray = [];
+ const runs: ContentArray = [];
let bullet: Opt<number>;
if (element.paragraph) {
if (element.paragraph.elements) {
for (const inner of element.paragraph.elements) {
if (inner) {
if (inner.textRun) {
- let run = inner.textRun;
+ const run = inner.textRun;
(run.content || !filterEmpty) && runs.push(inner.textRun);
} else if (inner.inlineObjectElement) {
runs.push(inner.inlineObjectElement);
@@ -182,8 +182,8 @@ export namespace GoogleApiClientUtils {
export const read = async (options: ReadOptions): Promise<Opt<ReadResult>> => {
return retrieve({ documentId: options.documentId }).then(document => {
if (document) {
- let title = document.title!;
- let body = Utils.extractText(document, options.removeNewlines).text;
+ const title = document.title!;
+ const body = Utils.extractText(document, options.removeNewlines).text;
return { title, body };
}
});
@@ -192,7 +192,7 @@ export namespace GoogleApiClientUtils {
export const readLines = async (options: ReadOptions): Promise<Opt<ReadLinesResult>> => {
return retrieve({ documentId: options.documentId }).then(document => {
if (document) {
- let title = document.title;
+ const title = document.title;
let bodyLines = Utils.extractText(document).text.split("\n");
options.removeNewlines && (bodyLines = bodyLines.filter(line => line.length));
return { title, bodyLines };
@@ -201,7 +201,7 @@ export namespace GoogleApiClientUtils {
};
export const setStyle = async (options: UpdateOptions) => {
- let replies: any = await update({
+ const replies: any = await update({
documentId: options.documentId,
requests: options.requests
});
@@ -221,7 +221,7 @@ export namespace GoogleApiClientUtils {
let index = options.index;
const mode = options.mode;
if (!(index && mode === WriteMode.Insert)) {
- let schema = await retrieve({ documentId });
+ const schema = await retrieve({ documentId });
if (!schema || !(index = Utils.endOf(schema))) {
return undefined;
}
@@ -248,7 +248,7 @@ export namespace GoogleApiClientUtils {
return undefined;
}
requests.push(...options.content.requests);
- let replies: any = await update({ documentId: documentId, requests });
+ const replies: any = await update({ documentId: documentId, requests });
if ("errors" in replies) {
console.log("Write operation failed:");
console.log(replies.errors.map((error: any) => error.message));
diff --git a/src/client/apis/google_docs/GooglePhotosClientUtils.ts b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
index bf8897061..966d8053a 100644
--- a/src/client/apis/google_docs/GooglePhotosClientUtils.ts
+++ b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
@@ -128,10 +128,10 @@ export namespace GooglePhotos {
export const CollectionFromSearch = async (constructor: CollectionConstructor, requested: Opt<Partial<Query.SearchOptions>>): Promise<Doc> => {
await GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken();
- let response = await Query.ContentSearch(requested);
- let uploads = await Transactions.WriteMediaItemsToServer(response);
+ const response = await Query.ContentSearch(requested);
+ const uploads = await Transactions.WriteMediaItemsToServer(response);
const children = uploads.map((upload: Transactions.UploadInformation) => {
- let document = Docs.Create.ImageDocument(Utils.fileUrl(upload.fileNames.clean));
+ const document = Docs.Create.ImageDocument(Utils.fileUrl(upload.fileNames.clean));
document.fillColumn = true;
document.contentSize = upload.contentSize;
return document;
@@ -157,12 +157,12 @@ export namespace GooglePhotos {
const images = (await DocListCastAsync(collection.data))!.map(Doc.GetProto);
images && images.forEach(image => tagMapping.set(image[Id], ContentCategories.NONE));
const values = Object.values(ContentCategories);
- for (let value of values) {
+ for (const value of values) {
if (value !== ContentCategories.NONE) {
const results = await ContentSearch({ included: [value] });
if (results.mediaItems) {
const ids = results.mediaItems.map(item => item.id);
- for (let id of ids) {
+ for (const id of ids) {
const image = await Cast(idMapping[id], Doc);
if (image) {
const key = image[Id];
@@ -220,9 +220,9 @@ export namespace GooglePhotos {
export const AlbumSearch = async (albumId: string, pageSize = 100): Promise<MediaItem[]> => {
const photos = await endpoint();
- let mediaItems: MediaItem[] = [];
+ const mediaItems: MediaItem[] = [];
let nextPageTokenStored: Opt<string> = undefined;
- let found = 0;
+ const found = 0;
do {
const response: any = await photos.mediaItems.search(albumId, pageSize, nextPageTokenStored);
mediaItems.push(...response.mediaItems);
@@ -332,7 +332,7 @@ export namespace GooglePhotos {
album = await Create.Album(album.title);
}
const media: MediaInput[] = [];
- for (let source of sources) {
+ for (const source of sources) {
const data = Cast(Doc.GetProto(source).data, ImageField);
if (!data) {
return;
diff --git a/src/client/apis/youtube/YoutubeBox.tsx b/src/client/apis/youtube/YoutubeBox.tsx
index bed812852..fd3d9e2f1 100644
--- a/src/client/apis/youtube/YoutubeBox.tsx
+++ b/src/client/apis/youtube/YoutubeBox.tsx
@@ -48,44 +48,44 @@ export class YoutubeBox extends React.Component<FieldViewProps> {
*/
async componentWillMount() {
//DocServer.getYoutubeChannels();
- let castedSearchBackUp = Cast(this.props.Document.cachedSearchResults, Doc);
- let awaitedBackUp = await castedSearchBackUp;
- let castedDetailBackUp = Cast(this.props.Document.cachedDetails, Doc);
- let awaitedDetails = await castedDetailBackUp;
+ const castedSearchBackUp = Cast(this.props.Document.cachedSearchResults, Doc);
+ const awaitedBackUp = await castedSearchBackUp;
+ const castedDetailBackUp = Cast(this.props.Document.cachedDetails, Doc);
+ const awaitedDetails = await castedDetailBackUp;
if (awaitedBackUp) {
- let jsonList = await DocListCastAsync(awaitedBackUp.json);
- let jsonDetailList = await DocListCastAsync(awaitedDetails!.json);
+ const jsonList = await DocListCastAsync(awaitedBackUp.json);
+ const jsonDetailList = await DocListCastAsync(awaitedDetails!.json);
if (jsonList!.length !== 0) {
runInAction(() => this.searchResultsFound = true);
let index = 0;
//getting the necessary information from backUps and building templates that will be used to map in render
- for (let video of jsonList!) {
-
- let videoId = await Cast(video.id, Doc);
- let id = StrCast(videoId!.videoId);
- let snippet = await Cast(video.snippet, Doc);
- let videoTitle = this.filterYoutubeTitleResult(StrCast(snippet!.title));
- let thumbnail = await Cast(snippet!.thumbnails, Doc);
- let thumbnailMedium = await Cast(thumbnail!.medium, Doc);
- let thumbnailUrl = StrCast(thumbnailMedium!.url);
- let videoDescription = StrCast(snippet!.description);
- let pusblishDate = (this.roundPublishTime(StrCast(snippet!.publishedAt)))!;
- let channelTitle = StrCast(snippet!.channelTitle);
+ for (const video of jsonList!) {
+
+ const videoId = await Cast(video.id, Doc);
+ const id = StrCast(videoId!.videoId);
+ const snippet = await Cast(video.snippet, Doc);
+ const videoTitle = this.filterYoutubeTitleResult(StrCast(snippet!.title));
+ const thumbnail = await Cast(snippet!.thumbnails, Doc);
+ const thumbnailMedium = await Cast(thumbnail!.medium, Doc);
+ const thumbnailUrl = StrCast(thumbnailMedium!.url);
+ const videoDescription = StrCast(snippet!.description);
+ const pusblishDate = (this.roundPublishTime(StrCast(snippet!.publishedAt)))!;
+ const channelTitle = StrCast(snippet!.channelTitle);
let duration: string = "";
let viewCount: string = "";
if (jsonDetailList!.length !== 0) {
- let contentDetails = await Cast(jsonDetailList![index].contentDetails, Doc);
- let statistics = await Cast(jsonDetailList![index].statistics, Doc);
+ const contentDetails = await Cast(jsonDetailList![index].contentDetails, Doc);
+ const statistics = await Cast(jsonDetailList![index].statistics, Doc);
duration = this.convertIsoTimeToDuration(StrCast(contentDetails!.duration));
viewCount = this.abbreviateViewCount(parseInt(StrCast(statistics!.viewCount)))!;
}
index = index + 1;
- let newTemplate: VideoTemplate = { videoId: id, videoTitle: videoTitle, thumbnailUrl: thumbnailUrl, publishDate: pusblishDate, channelTitle: channelTitle, videoDescription: videoDescription, duration: duration, viewCount: viewCount };
+ const newTemplate: VideoTemplate = { videoId: id, videoTitle: videoTitle, thumbnailUrl: thumbnailUrl, publishDate: pusblishDate, channelTitle: channelTitle, videoDescription: videoDescription, duration: duration, viewCount: viewCount };
runInAction(() => this.curVideoTemplates.push(newTemplate));
}
}
@@ -115,7 +115,7 @@ export class YoutubeBox extends React.Component<FieldViewProps> {
*/
onEnterKeyDown = (e: React.KeyboardEvent) => {
if (e.keyCode === 13) {
- let submittedTitle = this.YoutubeSearchElement!.value;
+ const submittedTitle = this.YoutubeSearchElement!.value;
this.YoutubeSearchElement!.value = "";
this.YoutubeSearchElement!.blur();
DocServer.getYoutubeVideos(submittedTitle, this.processesVideoResults);
@@ -184,23 +184,23 @@ export class YoutubeBox extends React.Component<FieldViewProps> {
* difference between today's date and that date, in terms of "ago" to imitate youtube.
*/
roundPublishTime = (publishTime: string) => {
- let date = new Date(publishTime).getTime();
- let curDate = new Date().getTime();
- let timeDif = curDate - date;
- let totalSeconds = timeDif / 1000;
- let totalMin = totalSeconds / 60;
- let totalHours = totalMin / 60;
- let totalDays = totalHours / 24;
- let totalMonths = totalDays / 30.417;
- let totalYears = totalMonths / 12;
-
-
- let truncYears = Math.trunc(totalYears);
- let truncMonths = Math.trunc(totalMonths);
- let truncDays = Math.trunc(totalDays);
- let truncHours = Math.trunc(totalHours);
- let truncMin = Math.trunc(totalMin);
- let truncSec = Math.trunc(totalSeconds);
+ const date = new Date(publishTime).getTime();
+ const curDate = new Date().getTime();
+ const timeDif = curDate - date;
+ const totalSeconds = timeDif / 1000;
+ const totalMin = totalSeconds / 60;
+ const totalHours = totalMin / 60;
+ const totalDays = totalHours / 24;
+ const totalMonths = totalDays / 30.417;
+ const totalYears = totalMonths / 12;
+
+
+ const truncYears = Math.trunc(totalYears);
+ const truncMonths = Math.trunc(totalMonths);
+ const truncDays = Math.trunc(totalDays);
+ const truncHours = Math.trunc(totalHours);
+ const truncMin = Math.trunc(totalMin);
+ const truncSec = Math.trunc(totalSeconds);
let pluralCase = "";
@@ -230,7 +230,7 @@ export class YoutubeBox extends React.Component<FieldViewProps> {
*/
convertIsoTimeToDuration = (isoDur: string) => {
- let convertedTime = isoDur.replace(/D|H|M/g, ":").replace(/P|T|S/g, "").split(":");
+ const convertedTime = isoDur.replace(/D|H|M/g, ":").replace(/P|T|S/g, "").split(":");
if (1 === convertedTime.length) {
2 !== convertedTime[0].length && (convertedTime[0] = "0" + convertedTime[0]), convertedTime[0] = "0:" + convertedTime[0];
@@ -269,10 +269,10 @@ export class YoutubeBox extends React.Component<FieldViewProps> {
if (this.searchResults.length !== 0) {
return <ul>
{this.searchResults.map((video, index) => {
- let filteredTitle = this.filterYoutubeTitleResult(video.snippet.title);
- let channelTitle = video.snippet.channelTitle;
- let videoDescription = video.snippet.description;
- let pusblishDate = this.roundPublishTime(video.snippet.publishedAt);
+ const filteredTitle = this.filterYoutubeTitleResult(video.snippet.title);
+ const channelTitle = video.snippet.channelTitle;
+ const videoDescription = video.snippet.description;
+ const pusblishDate = this.roundPublishTime(video.snippet.publishedAt);
let duration;
let viewCount;
if (this.videoDetails.length !== 0) {
@@ -331,26 +331,26 @@ export class YoutubeBox extends React.Component<FieldViewProps> {
*/
@action
embedVideoOnClick = (videoId: string, filteredTitle: string) => {
- let embeddedUrl = "https://www.youtube.com/embed/" + videoId;
+ const embeddedUrl = "https://www.youtube.com/embed/" + videoId;
this.selectedVideoUrl = embeddedUrl;
- let addFunction = this.props.addDocument!;
- let newVideoX = NumCast(this.props.Document.x);
- let newVideoY = NumCast(this.props.Document.y) + NumCast(this.props.Document.height);
+ const addFunction = this.props.addDocument!;
+ const newVideoX = NumCast(this.props.Document.x);
+ const newVideoY = NumCast(this.props.Document.y) + NumCast(this.props.Document.height);
addFunction(Docs.Create.VideoDocument(embeddedUrl, { title: filteredTitle, width: 400, height: 315, x: newVideoX, y: newVideoY }));
this.videoClicked = true;
}
render() {
- let content =
+ const content =
<div className="youtubeBox-cont" style={{ width: "100%", height: "100%", position: "absolute" }} onWheel={this.onPostWheel} onPointerDown={this.onPostPointer} onPointerMove={this.onPostPointer} onPointerUp={this.onPostPointer}>
<input type="text" placeholder="Search for a video" onKeyDown={this.onEnterKeyDown} style={{ height: 40, width: "100%", border: "1px solid black", padding: 5, textAlign: "center" }} ref={(e) => this.YoutubeSearchElement = e!} />
{this.renderSearchResultsOrVideo()}
</div>;
- let frozen = !this.props.isSelected() || DocumentDecorations.Instance.Interacting;
+ const frozen = !this.props.isSelected() || DocumentDecorations.Instance.Interacting;
- let classname = "webBox-cont" + (this.props.isSelected() && !InkingControl.Instance.selectedTool && !DocumentDecorations.Instance.Interacting ? "-interactive" : "");
+ const classname = "webBox-cont" + (this.props.isSelected() && !InkingControl.Instance.selectedTool && !DocumentDecorations.Instance.Interacting ? "-interactive" : "");
return (
<>
<div className={classname} >