mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-02 16:15:39 +00:00
feat: add file-based env variables for LibreTranslate and Stalwart
Impersonation
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { readFileEnv } from "@/lib/read-file-env";
|
||||
import { getStalwartCredentials } from '@/lib/stalwart/credentials';
|
||||
|
||||
// Host-side proxy backing the "Translate" plugin (manifest apiPostPaths:
|
||||
@@ -11,7 +12,7 @@ import { getStalwartCredentials } from '@/lib/stalwart/credentials';
|
||||
// langpair needs an explicit source language, so when the
|
||||
// plugin asks for "auto" we detect it locally first.
|
||||
// - "libretranslate" — only available when the host sets LIBRETRANSLATE_URL
|
||||
// (and optionally LIBRETRANSLATE_API_KEY). Supports native
|
||||
// (and optionally LIBRETRANSLATE_API_KEY or LIBRETRANSLATE_API_KEY_FILE). Supports native
|
||||
// source auto-detection.
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
@@ -225,7 +226,9 @@ async function translateLibre(
|
||||
if (!endpoint) {
|
||||
throw new Error('LibreTranslate is not configured on this server');
|
||||
}
|
||||
const apiKey = process.env.LIBRETRANSLATE_API_KEY;
|
||||
const apiKey =
|
||||
process.env.LIBRETRANSLATE_API_KEY ||
|
||||
readFileEnv(process.env.LIBRETRANSLATE_API_KEY_FILE);
|
||||
const url = endpoint.replace(/\/+$/, '') + '/translate';
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { configManager } from '@/lib/admin/config-manager';
|
||||
import { readFileEnv } from "@/lib/read-file-env";
|
||||
|
||||
export interface ImpersonationConfig {
|
||||
jwtSecret: string;
|
||||
@@ -16,13 +17,27 @@ export interface ImpersonationConfig {
|
||||
* BULWARK_STALWART_MASTER_USER master account address (e.g. master@example.com)
|
||||
* BULWARK_STALWART_MASTER_PASSWORD
|
||||
*
|
||||
* Alternatively the file-based env:
|
||||
* BULWARK_JWT_AUTH_SECRET_FILE
|
||||
* BULWARK_STALWART_MASTER_USER_FILE
|
||||
* BULWARK_STALWART_MASTER_PASSWORD_FILE
|
||||
*
|
||||
* Optional env:
|
||||
* BULWARK_JWT_AUTH_ISSUER (default: "platform-api/webmail")
|
||||
*/
|
||||
export function readImpersonationConfig(): ImpersonationConfig | null {
|
||||
const jwtSecret = process.env.BULWARK_JWT_AUTH_SECRET ?? '';
|
||||
const masterUser = process.env.BULWARK_STALWART_MASTER_USER ?? '';
|
||||
const masterPassword = process.env.BULWARK_STALWART_MASTER_PASSWORD ?? '';
|
||||
const jwtSecret =
|
||||
process.env.BULWARK_JWT_AUTH_SECRET ??
|
||||
readFileEnv(process.env.BULWARK_JWT_AUTH_SECRET_FILE) ??
|
||||
"";
|
||||
const masterUser =
|
||||
process.env.BULWARK_STALWART_MASTER_USER ??
|
||||
readFileEnv(process.env.BULWARK_STALWART_MASTER_USER_FILE) ??
|
||||
"";
|
||||
const masterPassword =
|
||||
process.env.BULWARK_STALWART_MASTER_PASSWORD ??
|
||||
readFileEnv(process.env.BULWARK_STALWART_MASTER_PASSWORD_FILE) ??
|
||||
"";
|
||||
if (!jwtSecret || !masterUser || !masterPassword) return null;
|
||||
return {
|
||||
jwtSecret,
|
||||
|
||||
Reference in New Issue
Block a user