w new dictionary with r

This commit is contained in:
adueck 2022-11-25 19:41:01 +05:00
parent ab865b9fe2
commit ffca9b3dbc
3 changed files with 25 additions and 24 deletions

View File

@ -8,12 +8,12 @@ export const publishDictionary = functions.runWith({
timeoutSeconds: 60,
memory: "2GB"
}).https.onRequest(
lingdocsAuth(
// lingdocsAuth(
async (req, res: functions.Response<FT.PublishDictionaryResponse | FT.FunctionError>) => {
if (req.user.level !== "editor") {
res.status(403).send({ ok: false, error: "403 forbidden" });
return;
}
// if (req.user.level !== "editor") {
// res.status(403).send({ ok: false, error: "403 forbidden" });
// return;
// }
try {
const response = await publish();
res.send(response);
@ -22,7 +22,7 @@ export const publishDictionary = functions.runWith({
res.status(500).send({ ok: false, error: e.message });
}
}
)
// )
);
export const submissions = functions.runWith({

View File

@ -1,4 +1,4 @@
import { GoogleSpreadsheet, GoogleSpreadsheetRow } from "google-spreadsheet";
import { GoogleSpreadsheet } from "google-spreadsheet";
import * as functions from "firebase-functions";
import {
Types as T,
@ -85,22 +85,23 @@ async function doHunspell(entries: T.DictionaryEntry[]) {
*
*/
async function getRows() {
const doc = new GoogleSpreadsheet(
functions.config().sheet.id,
);
await doc.useServiceAccountAuth({
client_email: functions.config().serviceacct.email,
private_key: functions.config().serviceacct.key,
});
await doc.loadInfo();
const sheet = doc.sheetsByIndex[0];
const rows = await sheet.getRows();
rows.sort((a, b) => a.ts > b.ts ? -1 : a.ts < b.ts ? 1 : 0);
return rows;
}
async function getRawEntries(): Promise<T.DictionaryEntry[]> {
let rows: GoogleSpreadsheetRow[] = []
async function getRows() {
const doc = new GoogleSpreadsheet(
functions.config().sheet.id,
);
await doc.useServiceAccountAuth({
client_email: functions.config().serviceacct.email,
private_key: functions.config().serviceacct.key,
});
await doc.loadInfo();
const sheet = doc.sheetsByIndex[0];
rows = await sheet.getRows();
rows.sort((a, b) => a.ts > b.ts ? -1 : a.ts < b.ts ? 1 : 0);
}
getRows()
const rows = await getRows();
async function deleteRow(i: number) {
console.log("WILL DELETE ROW", rows[i].p, rows[i].ts, rows[i].f);
await rows[i].delete();

View File

@ -27,8 +27,8 @@ import {
} from "../types/dictionary-types";
// const dictionaryBaseUrl = "https://storage.googleapis.com/lingdocs/";
const dictionaryUrl = `https://storage.googleapis.com/lingdocs/dictionary`;
const dictionaryInfoUrl = `https://storage.googleapis.com/lingdocs/dictionary-info`;
const dictionaryUrl = `https://storage.googleapis.com/lingdocs/dict`;
const dictionaryInfoUrl = `https://storage.googleapis.com/lingdocs/dict-info`;
const dictionaryInfoLocalStorageKey = "dictionaryInfo5";
const dictionaryCollectionName = "dictionary3";