aboutsummaryrefslogtreecommitdiff
path: root/src/client/apis
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/apis')
-rw-r--r--src/client/apis/GoogleAuthenticationManager.tsx27
-rw-r--r--src/client/apis/google_docs/GoogleApiClientUtils.ts19
-rw-r--r--src/client/apis/google_docs/GooglePhotosClientUtils.ts18
3 files changed, 31 insertions, 33 deletions
diff --git a/src/client/apis/GoogleAuthenticationManager.tsx b/src/client/apis/GoogleAuthenticationManager.tsx
index 5269f763b..94ce42d8d 100644
--- a/src/client/apis/GoogleAuthenticationManager.tsx
+++ b/src/client/apis/GoogleAuthenticationManager.tsx
@@ -11,7 +11,8 @@ const AuthenticationUrl = 'https://accounts.google.com/o/oauth2/v2/auth';
const prompt = 'Paste authorization code here...';
@observer
-export class GoogleAuthenticationManager extends React.Component<{}> {
+export class GoogleAuthenticationManager extends React.Component<object> {
+ // eslint-disable-next-line no-use-before-define
public static Instance: GoogleAuthenticationManager;
private authenticationLink: Opt<string> = undefined;
@observable private openState = false;
@@ -19,7 +20,7 @@ export class GoogleAuthenticationManager extends React.Component<{}> {
@observable private showPasteTargetState = false;
@observable private success: Opt<boolean> = undefined;
@observable private displayLauncher = true;
- @observable private credentials: any;
+ @observable private credentials: { user_info: { name: string; picture: string }; access_token: string } | undefined = undefined;
private disposer: Opt<IReactionDisposer>;
private set isOpen(value: boolean) {
@@ -35,25 +36,25 @@ export class GoogleAuthenticationManager extends React.Component<{}> {
}
public fetchOrGenerateAccessToken = async (displayIfFound = false) => {
- let response: any = 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;
this.authenticationLink = response;
- return new Promise<string>(async resolve => {
+ return new Promise<string>(resolve => {
this.disposer?.();
this.disposer = reaction(
() => this.authenticationCode,
async authenticationCode => {
if (authenticationCode && /\d{1}\/[\w-]{55}/.test(authenticationCode)) {
this.disposer?.();
- const response = await Networking.PostToServer('/writeGoogleAccessToken', { authenticationCode });
+ const response2 = await Networking.PostToServer('/writeGoogleAccessToken', { authenticationCode });
runInAction(() => {
this.success = true;
- this.credentials = response;
+ this.credentials = response2 as { user_info: { name: string; picture: string }; access_token: string };
});
this.resetState();
- resolve(response.access_token);
+ resolve((response2 as { access_token: string }).access_token);
}
}
);
@@ -61,16 +62,16 @@ export class GoogleAuthenticationManager extends React.Component<{}> {
}
// otherwise, we already have a valid, stored access token and user info
- response = JSON.parse(response);
+ const response2 = JSON.parse(response) as { user_info: { name: string; picture: string }; access_token: string };
if (displayIfFound) {
runInAction(() => {
this.success = true;
- this.credentials = response;
+ this.credentials = response2;
});
this.resetState(-1, -1);
this.isOpen = true;
}
- return response.access_token;
+ return (response2 as { access_token: string }).access_token;
};
resetState = action((visibleForMS: number = 3000, fadesOutInMS: number = 500) => {
@@ -106,7 +107,7 @@ export class GoogleAuthenticationManager extends React.Component<{}> {
}
});
- constructor(props: {}) {
+ constructor(props: object) {
super(props);
GoogleAuthenticationManager.Instance = this;
}
@@ -128,8 +129,8 @@ export class GoogleAuthenticationManager extends React.Component<{}> {
{this.showPasteTargetState ? <input className={'paste-target'} onChange={action(e => (this.authenticationCode = e.currentTarget.value))} placeholder={prompt} /> : null}
{this.credentials ? (
<>
- <img className={'avatar'} src={this.credentials.userInfo.picture} />
- <span className={'welcome'}>Welcome to Dash, {this.credentials.userInfo.name}</span>
+ <img className={'avatar'} src={this.credentials.user_info.picture} />
+ <span className={'welcome'}>Welcome to Dash, {this.credentials.user_info.name}</span>
<div
className={'disconnect'}
onClick={async () => {
diff --git a/src/client/apis/google_docs/GoogleApiClientUtils.ts b/src/client/apis/google_docs/GoogleApiClientUtils.ts
index 0b303eacf..c1ac352b1 100644
--- a/src/client/apis/google_docs/GoogleApiClientUtils.ts
+++ b/src/client/apis/google_docs/GoogleApiClientUtils.ts
@@ -1,7 +1,5 @@
-/* eslint-disable no-restricted-syntax */
/* eslint-disable no-use-before-define */
import { docs_v1 as docsV1 } from 'googleapis';
-// eslint-disable-next-line node/no-deprecated-api
import { isArray } from 'util';
import { EditorState } from 'prosemirror-state';
import { Opt } from '../../../fields/Doc';
@@ -37,7 +35,7 @@ export namespace GoogleApiClientUtils {
text: string | string[];
requests: docsV1.Schema$Request[];
}
- export type IdHandler = (id: DocumentId) => any;
+ export type IdHandler = (id: DocumentId) => unknown;
export type CreationResult = Opt<DocumentId>;
export type ReadLinesResult = Opt<{ title?: string; bodyLines?: string[] }>;
export type ReadResult = { title: string; body: string };
@@ -145,7 +143,7 @@ export namespace GoogleApiClientUtils {
if (paragraphs.length) {
const target = paragraphs[paragraphs.length - 1];
if (target.paragraph && target.paragraph.elements) {
- length = target.paragraph.elements.length;
+ const length = target.paragraph.elements.length;
if (length) {
const final = target.paragraph.elements[length - 1];
return final.endIndex ? final.endIndex - 1 : undefined;
@@ -208,13 +206,13 @@ export namespace GoogleApiClientUtils {
});
export const setStyle = async (options: UpdateOptions) => {
- const replies: any = await update({
+ const replies = await update({
documentId: options.documentId,
requests: options.requests,
});
- if ('errors' in replies) {
+ if (replies && 'errors' in replies) {
console.log('Write operation failed:');
- console.log(replies.errors.map((error: any) => error.message));
+ console.log(replies); //.errors.map((error: any) => error.message));
}
return replies;
};
@@ -229,7 +227,6 @@ export namespace GoogleApiClientUtils {
const { mode } = options;
if (!(index && mode === WriteMode.Insert)) {
const schema = await retrieve({ documentId });
- // eslint-disable-next-line no-cond-assign
if (!schema || !(index = Utils.endOf(schema))) {
return undefined;
}
@@ -258,10 +255,10 @@ export namespace GoogleApiClientUtils {
return undefined;
}
requests.push(...options.content.requests);
- const replies: any = await update({ documentId, requests });
- if ('errors' in replies) {
+ const replies = await update({ documentId, requests });
+ if (replies && 'errors' in replies) {
console.log('Write operation failed:');
- console.log(replies.errors.map((error: any) => error.message));
+ console.log(replies); // .errors.map((error: any) => error.message));
}
return replies;
};
diff --git a/src/client/apis/google_docs/GooglePhotosClientUtils.ts b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
index b238f07e9..4b86a8341 100644
--- a/src/client/apis/google_docs/GooglePhotosClientUtils.ts
+++ b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
@@ -1,5 +1,5 @@
/* eslint-disable no-use-before-define */
-import Photos = require('googlephotos');
+import Photos from 'googlephotos';
import { AssertionError } from 'assert';
import { EditorState } from 'prosemirror-state';
import { ClientUtils } from '../../../ClientUtils';
@@ -118,7 +118,7 @@ export namespace GooglePhotos {
}
export namespace Import {
- export type CollectionConstructor = (data: Array<Doc>, options: DocumentOptions, ...args: any) => Doc;
+ export type CollectionConstructor = (data: Array<Doc>, options: DocumentOptions, ...args: unknown[]) => Doc;
export const CollectionFromSearch = async (constructor: CollectionConstructor, requested: Opt<Partial<Query.SearchOptions>>): Promise<Doc> => {
await GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken();
@@ -147,7 +147,7 @@ export namespace GooglePhotos {
values.forEach(async value => {
const searched = (await ContentSearch({ included: [value] }))?.mediaItems?.map(({ id }) => id);
searched?.forEach(async id => {
- const image = await Cast(idMapping[id], Doc);
+ const image = await Cast(idMapping[id as string], Doc);
if (image) {
const key = image[Id];
const tags = tagMapping.get(key);
@@ -193,7 +193,7 @@ export namespace GooglePhotos {
}
export interface SearchResponse {
- mediaItems: any[];
+ mediaItems: MediaItem[];
nextPageToken: string;
}
@@ -204,7 +204,7 @@ export namespace GooglePhotos {
const found = 0;
do {
// eslint-disable-next-line no-await-in-loop
- const response: any = await photos.mediaItems.search(albumId, pageSize, nextPageTokenStored);
+ const response = await photos.mediaItems.search(albumId, pageSize, nextPageTokenStored);
mediaItems.push(...response.mediaItems);
nextPageTokenStored = response.nextPageToken;
} while (found);
@@ -278,9 +278,9 @@ export namespace GooglePhotos {
return undefined;
};
- export const WriteMediaItemsToServer = async (body: { mediaItems: any[] }): Promise<UploadInformation[]> => {
+ export const WriteMediaItemsToServer = async (body: { mediaItems: MediaItem[] }): Promise<UploadInformation[]> => {
const uploads = await Networking.PostToServer('/googlePhotosMediaGet', body);
- return uploads;
+ return uploads as UploadInformation[];
};
export const UploadThenFetch = async (sources: Doc[], album?: AlbumReference, descriptionKey = 'caption') => {
@@ -320,7 +320,7 @@ export namespace GooglePhotos {
});
if (media.length) {
const results = await Networking.PostToServer('/googlePhotosMediaPost', { media, album });
- return results;
+ return results as Opt<ImageUploadResults>;
}
return undefined;
};
@@ -331,7 +331,7 @@ export namespace GooglePhotos {
if (typeof target === 'string') {
description = target;
} else if (target instanceof RichTextField) {
- description = RichTextUtils.ToPlainText(EditorState.fromJSON(new FormattedTextBox({} as any).config, JSON.parse(target.Data)));
+ description = RichTextUtils.ToPlainText(EditorState.fromJSON(FormattedTextBox.MakeConfig(undefined, undefined), JSON.parse(target.Data)));
}
return description;
};