Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into support-ollama-api
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldschilly committed Feb 26, 2024
2 parents d6c763e + 00e3cbe commit ed19f8c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 52 deletions.
42 changes: 17 additions & 25 deletions src/packages/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions src/packages/server/email/sendgrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@ The cocalc ASM group numbers are at
https://app.sendgrid.com/suppressions/advanced_suppression_manager
*/

import getPool from "@cocalc/database/pool";
import sgMail from "@sendgrid/mail";
import type { Message } from "./message";
import getHelpEmail from "./help";
import appendFooter from "./footer";

import getPool from "@cocalc/database/pool";
import { SENDGRID_TEMPLATE_ID } from "@cocalc/util/theme";
import appendFooter from "./footer";
import getHelpEmail from "./help";
import type { Message } from "./message";

// Init throws error if we can't initialize Sendgrid right now.
// It also updates the key if it changes in at most one minute (?).
let initialized = 0;
export async function getSendgrid(): Promise<any> {
const now = new Date().valueOf();
const now = Date.now();
if (now - initialized < 1000 * 30) {
// initialized recently
return sgMail;
}
const pool = getPool("long");
const { rows } = await pool.query(
"SELECT value FROM server_settings WHERE name='sendgrid_key'"
"SELECT value FROM server_settings WHERE name='sendgrid_key'",
);
if (rows.length == 0 || !rows[0]?.value) {
if (initialized) {
Expand All @@ -35,7 +36,7 @@ export async function getSendgrid(): Promise<any> {
throw Error("no sendgrid key");
}
sgMail.setApiKey(rows[0].value);
initialized = new Date().valueOf();
initialized = Date.now();
return sgMail;
}

Expand Down
37 changes: 19 additions & 18 deletions src/packages/server/hub/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,37 @@

const BANNED_DOMAINS = { "qq.com": true };

import { promisify } from "util";
import sendgrid from "@sendgrid/client";
import * as async from "async";
import * as fs from "fs";
import { isEqual, template } from "lodash";
import { createTransport } from "nodemailer";
import * as os_path from "path";
import { isEqual } from "lodash";
const fs_readFile_prom = promisify(fs.readFile);
import { getLogger } from "@cocalc/backend/logger";
import { template } from "lodash";
import { AllSiteSettingsCached } from "@cocalc/util/db-schema/types";
import { KUCALC_COCALC_COM } from "@cocalc/util/db-schema/site-defaults";
import sanitizeHtml from "sanitize-html";
import { promisify } from "util";

import base_path from "@cocalc/backend/base-path";
import { secrets } from "@cocalc/backend/data";
import { getLogger } from "@cocalc/backend/logger";
import { KUCALC_COCALC_COM } from "@cocalc/util/db-schema/site-defaults";
import { AllSiteSettingsCached } from "@cocalc/util/db-schema/types";
// sendgrid API: https://sendgrid.com/docs/API_Reference/Web_API/mail.html
import sendgrid from "@sendgrid/client";
import { createTransport } from "nodemailer";
import { defaults, required, split, to_json } from "@cocalc/util/misc";
import { site_settings_conf } from "@cocalc/util/db-schema/site-defaults";
import sanitizeHtml from "sanitize-html";
import { contains_url } from "@cocalc/backend/misc";
import { site_settings_conf } from "@cocalc/util/db-schema/site-defaults";
import { defaults, required, split, to_json } from "@cocalc/util/misc";
import {
SENDGRID_TEMPLATE_ID,
SENDGRID_ASM_NEWSLETTER,
SENDGRID_ASM_INVITES,
COMPANY_NAME,
COMPANY_EMAIL,
SITE_NAME,
COMPANY_NAME,
DNS,
HELP_EMAIL,
LIVE_DEMO_REQUEST,
SENDGRID_ASM_INVITES,
SENDGRID_ASM_NEWSLETTER,
SENDGRID_TEMPLATE_ID,
SITE_NAME,
} from "@cocalc/util/theme";
import * as async from "async";

const fs_readFile_prom = promisify(fs.readFile);

const winston = getLogger("server:hub:email");

Expand Down
4 changes: 2 additions & 2 deletions src/packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"@passport-js/passport-twitter": "^1.0.8",
"@passport-next/passport-google-oauth2": "^1.0.0",
"@passport-next/passport-oauth2": "^2.1.4",
"@sendgrid/client": "^7.7.0",
"@sendgrid/mail": "^7.5.0",
"@sendgrid/client": "^8.1.1",
"@sendgrid/mail": "^8.1.1",
"@types/async": "^2.0.43",
"@types/cloudflare": "^2.7.11",
"@types/dot-object": "^2.1.2",
Expand Down

0 comments on commit ed19f8c

Please sign in to comment.