diff options
author | Sam Wilkins <samwilkins333@gmail.com> | 2019-08-19 17:48:57 -0400 |
---|---|---|
committer | Sam Wilkins <samwilkins333@gmail.com> | 2019-08-19 17:48:57 -0400 |
commit | df11d1afdb271b37618ab9e1d362b2f4a1145982 (patch) | |
tree | 6b7bd2866f43115d059aad36961094d30e27f3a7 /src/client/apis/google_docs/GoogleApiClientUtils.ts | |
parent | 7ea6b44b10e1bf23287ba33e0081cacbfc595780 (diff) |
cleanup, pull push
Diffstat (limited to 'src/client/apis/google_docs/GoogleApiClientUtils.ts')
-rw-r--r-- | src/client/apis/google_docs/GoogleApiClientUtils.ts | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/client/apis/google_docs/GoogleApiClientUtils.ts b/src/client/apis/google_docs/GoogleApiClientUtils.ts index 9d78b632d..55b4a76f8 100644 --- a/src/client/apis/google_docs/GoogleApiClientUtils.ts +++ b/src/client/apis/google_docs/GoogleApiClientUtils.ts @@ -27,8 +27,8 @@ export namespace GoogleApiClientUtils { export type CreationResult = Opt<DocumentId>; export type RetrievalResult = Opt<docs_v1.Schema$Document>; export type UpdateResult = Opt<docs_v1.Schema$BatchUpdateDocumentResponse>; - export type ReadLinesResult = Opt<string[]>; - export type ReadResult = Opt<string>; + export type ReadLinesResult = Opt<{ title?: string, bodyLines?: string[] }>; + export type ReadResult = { title?: string, body?: string }; export interface CreateOptions { handler: IdHandler; // callback to process the documentId of the newly created Google Doc @@ -148,18 +148,27 @@ export namespace GoogleApiClientUtils { }; export const read = async (options: ReadOptions): Promise<ReadResult> => { - return retrieve(options).then(schema => { - return schema ? Utils.extractText(schema, options.removeNewlines) : undefined; + return retrieve(options).then(document => { + let result: ReadResult = {}; + if (document) { + let title = document.title; + let body = Utils.extractText(document, options.removeNewlines); + result = { title, body }; + } + return result; }); }; export const readLines = async (options: ReadOptions): Promise<ReadLinesResult> => { - return retrieve(options).then(schema => { - if (!schema) { - return undefined; + return retrieve(options).then(document => { + let result: ReadLinesResult = {}; + if (document) { + let title = document.title; + let bodyLines = Utils.extractText(document).split("\n"); + options.removeNewlines && (bodyLines = bodyLines.filter(line => line.length)); + result = { title, bodyLines }; } - const lines = Utils.extractText(schema).split("\n"); - return options.removeNewlines ? lines.filter(line => line.length) : lines; + return result; }); }; |