From bdb40fedce00a61dbb487646b1af2be8949ea90d Mon Sep 17 00:00:00 2001 From: adueck Date: Thu, 28 Nov 2024 01:10:31 +0500 Subject: [PATCH] w test piece --- .github/workflows/TODO-deploy-functions | 0 account/src/lib/submissions.ts | 1 + account/src/routers/submissions-router.ts | 33 +++++++++++++++++++++++ functions/lib/publishing-helpers.ts | 4 +-- 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/TODO-deploy-functions diff --git a/.github/workflows/TODO-deploy-functions b/.github/workflows/TODO-deploy-functions new file mode 100644 index 0000000..e69de29 diff --git a/account/src/lib/submissions.ts b/account/src/lib/submissions.ts index 2e96dc6..eaf8130 100644 --- a/account/src/lib/submissions.ts +++ b/account/src/lib/submissions.ts @@ -20,6 +20,7 @@ const reviewTasksDb = nano.db.use("review-tasks"); // TODO: get new env vars on server (remember base64 for key) const auth = new google.auth.GoogleAuth({ + // TODO: THESE CREDENTIALS ARE NOT WORKING SOMEHOW !! credentials: { private_key: Buffer.from(env.lingdocsServiceAccountKey, "base64").toString( "ascii" diff --git a/account/src/routers/submissions-router.ts b/account/src/routers/submissions-router.ts index 4a5a303..010a736 100644 --- a/account/src/routers/submissions-router.ts +++ b/account/src/routers/submissions-router.ts @@ -1,6 +1,12 @@ import express, { Response } from "express"; import * as T from "../../../website/src/types/account-types"; import { receiveSubmissions } from "../lib/submissions"; +import { google } from "googleapis"; +import { + getEntriesFromSheet, + Sheets, +} from "../../../functions/lib/spreadsheet-tools"; +import env from "../lib/env-vars"; // TODO: ADD PROPER ERROR HANDLING THAT WILL RETURN JSON ALWAYS @@ -10,6 +16,33 @@ function sendResponse(res: Response, payload: T.APIResponse) { const submissionsRouter = express.Router(); +const auth = new google.auth.GoogleAuth({ + // TODO: THESE CREDENTIALS ARE NOT WORKING SOMEHOW !! + credentials: { + private_key: Buffer.from(env.lingdocsServiceAccountKey, "base64").toString( + "ascii" + ), + client_email: env.lingdocsServiceAccountEmail, + }, + scopes: [ + "https://www.googleapis.com/auth/spreadsheets", + "https://www.googleapis.com/auth/drive.file", + ], +}); +const { spreadsheets } = google.sheets({ + version: "v4", + auth, +}); +const sheets: Sheets = { + spreadsheetId: env.lingdocsDictionarySpreadsheet, + spreadsheets, +}; + +submissionsRouter.get("/", async (req, res, next) => { + const r = await getEntriesFromSheet(sheets); + res.send(r); +}); + // Guard all api with authentication submissionsRouter.use((req, res, next) => { if (req.isAuthenticated()) { diff --git a/functions/lib/publishing-helpers.ts b/functions/lib/publishing-helpers.ts index e6f2475..f54eb87 100644 --- a/functions/lib/publishing-helpers.ts +++ b/functions/lib/publishing-helpers.ts @@ -3,8 +3,8 @@ import { Types as T, validateEntry } from "@lingdocs/inflect"; const title = "LingDocs Pashto Dictionary"; const license = `Copyright © ${new Date().getFullYear()} lingdocs.com All Rights Reserved - Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License - https://creativecommons.org/licenses/by-nc-sa/4.0/`; const baseUrl = `https://storage.lingdocs.com/dictionary/`; -export const dictionaryFilename = "dictionary2"; -export const dictionaryInfoFilename = "dictionary-info2"; +export const dictionaryFilename = "dictionary"; +export const dictionaryInfoFilename = "dictionary-info"; // const hunspellAffFileFilename = "ps_AFF.aff"; // const hunspellDicFileFilename = "ps_AFF.dic"; const allWordsJsonFilename = "all-words-dictionary.json";