sidecar network host
This commit is contained in:
@@ -1,12 +1,10 @@
|
|||||||
import { mkdir } from 'node:fs/promises';
|
import { mkdir } from 'node:fs/promises';
|
||||||
import { dirname, join } from 'node:path';
|
import { dirname, join } from 'node:path';
|
||||||
import { homedir } from 'node:os';
|
|
||||||
import { createRouter } from '../../create-router';
|
import { createRouter } from '../../create-router';
|
||||||
import { DATA_PATH } from '@@/data-path';
|
import { DATA_PATH, SERVER_CONFIG_DIR } from '@@/data-path';
|
||||||
import { CustomError } from '../../custom-errors';
|
import { CustomError } from '../../custom-errors';
|
||||||
|
|
||||||
const configDir = `${homedir()}/.config/officer.dev`;
|
const googleConfigPath = join(SERVER_CONFIG_DIR, 'google-oauth.json');
|
||||||
const googleConfigPath = join(configDir, 'google-oauth.json');
|
|
||||||
|
|
||||||
const GOOGLE_SCOPES = [
|
const GOOGLE_SCOPES = [
|
||||||
'https://www.googleapis.com/auth/gmail.readonly',
|
'https://www.googleapis.com/auth/gmail.readonly',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createRouter } from '../../create-router';
|
import { createRouter } from '../../create-router';
|
||||||
import { homedir } from 'node:os';
|
|
||||||
import { mkdir } from 'node:fs/promises';
|
import { mkdir } from 'node:fs/promises';
|
||||||
|
import { SERVER_CONFIG_DIR } from '@@/data-path';
|
||||||
import { readdirSync, existsSync } from 'node:fs';
|
import { readdirSync, existsSync } from 'node:fs';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { claudeCodeRouter } from './claude-code';
|
import { claudeCodeRouter } from './claude-code';
|
||||||
@@ -14,12 +14,11 @@ import { sttRouter } from './stt';
|
|||||||
import { ocrRouter } from './ocr';
|
import { ocrRouter } from './ocr';
|
||||||
import { searxngRouter } from './searxng';
|
import { searxngRouter } from './searxng';
|
||||||
|
|
||||||
const configDir = `${homedir()}/.config/officer.dev`;
|
export const settingsPath = `${SERVER_CONFIG_DIR}/server-settings.json`;
|
||||||
export const settingsPath = `${configDir}/server-settings.json`;
|
|
||||||
|
|
||||||
const settingsFile = Bun.file(settingsPath);
|
const settingsFile = Bun.file(settingsPath);
|
||||||
if (!(await settingsFile.exists())) {
|
if (!(await settingsFile.exists())) {
|
||||||
await mkdir(configDir, { recursive: true });
|
await mkdir(SERVER_CONFIG_DIR, { recursive: true });
|
||||||
await Bun.write(settingsPath, '{}');
|
await Bun.write(settingsPath, '{}');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import type { ServerWebSocket } from 'bun';
|
import type { ServerWebSocket } from 'bun';
|
||||||
import { existsSync, mkdirSync, statSync, writeFileSync } from 'node:fs';
|
import { existsSync, mkdirSync, statSync, writeFileSync } from 'node:fs';
|
||||||
import { homedir } from 'node:os';
|
|
||||||
import { dirname, join } from 'node:path';
|
import { dirname, join } from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { getHomeDir, getGlobalSkillsDir, getGlobalToolsDir, getGlobalExtensionsDir, getUserSkillsDir, getUserToolsDir, DATA_PATH } from '@@/data-path';
|
import { getHomeDir, getGlobalSkillsDir, getGlobalToolsDir, getGlobalExtensionsDir, getUserSkillsDir, getUserToolsDir, DATA_PATH, SERVER_CONFIG_DIR } from '@@/data-path';
|
||||||
import { syncUserPiConfig } from '@@/api/server-settings/sync-user-pi-config';
|
import { syncUserPiConfig } from '@@/api/server-settings/sync-user-pi-config';
|
||||||
import { getUsers } from 'officerdb';
|
import { getUsers } from 'officerdb';
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ const startDockerSidecar = (port: number, homeDir: string, userId: number, usern
|
|||||||
}
|
}
|
||||||
|
|
||||||
const containerHome = `/home/${username}`;
|
const containerHome = `/home/${username}`;
|
||||||
const googleConfigHost = join(homedir(), '.config', 'officer.dev', 'google-oauth.json');
|
const googleConfigHost = join(SERVER_CONFIG_DIR, 'google-oauth.json');
|
||||||
const googleMounts: string[] = existsSync(googleConfigHost)
|
const googleMounts: string[] = existsSync(googleConfigHost)
|
||||||
? ['-v', `${googleConfigHost}:/officer/google-oauth.json:ro`]
|
? ['-v', `${googleConfigHost}:/officer/google-oauth.json:ro`]
|
||||||
: [];
|
: [];
|
||||||
@@ -152,12 +152,11 @@ const startDockerSidecar = (port: number, homeDir: string, userId: number, usern
|
|||||||
dockerId,
|
dockerId,
|
||||||
'--restart',
|
'--restart',
|
||||||
'unless-stopped',
|
'unless-stopped',
|
||||||
'-p',
|
'--network', 'host',
|
||||||
`127.0.0.1:${port}:${port}`,
|
|
||||||
'-e',
|
'-e',
|
||||||
`TERMINAL_PTY_PORT=${port}`,
|
`TERMINAL_PTY_PORT=${port}`,
|
||||||
'-e',
|
'-e',
|
||||||
'TERMINAL_PTY_HOST=0.0.0.0',
|
'TERMINAL_PTY_HOST=127.0.0.1',
|
||||||
'-e',
|
'-e',
|
||||||
`TERMINAL_USER=${username}`,
|
`TERMINAL_USER=${username}`,
|
||||||
'-e',
|
'-e',
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { join, resolve } from 'node:path';
|
|||||||
|
|
||||||
export const DATA_PATH = process.env.DATA_PATH ?? join(process.cwd(), 'data');
|
export const DATA_PATH = process.env.DATA_PATH ?? join(process.cwd(), 'data');
|
||||||
|
|
||||||
|
export const SERVER_CONFIG_DIR = join(DATA_PATH, 'server-settings');
|
||||||
|
|
||||||
export const PI_CONFIG_DIR = join(DATA_PATH, 'pi-config');
|
export const PI_CONFIG_DIR = join(DATA_PATH, 'pi-config');
|
||||||
|
|
||||||
export const SEED_PATH = resolve(import.meta.dir, '../../seed');
|
export const SEED_PATH = resolve(import.meta.dir, '../../seed');
|
||||||
|
|||||||
+1
-1
@@ -31,5 +31,5 @@ export async function sign(payload: any, expiration = '30d') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function verify(token: string): Promise<any> {
|
export async function verify(token: string): Promise<any> {
|
||||||
return jwtVerify(token, JWT_SECRET!);
|
return jwtVerify(token, JWT_SECRET!, 'HS256');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { homedir } from 'node:os';
|
|
||||||
import type { Database } from 'bun:sqlite';
|
import type { Database } from 'bun:sqlite';
|
||||||
import type { JobHandler } from '../types';
|
import type { JobHandler } from '../types';
|
||||||
import { registerHandler } from '../handler-registry';
|
import { registerHandler } from '../handler-registry';
|
||||||
import { DATA_PATH } from '../../data-path';
|
import { DATA_PATH, SERVER_CONFIG_DIR } from '../../data-path';
|
||||||
import { openEmailDb, upsertFromRawEml, getSyncMeta, setSyncMeta, updateEmailLabels } from '../../api/email/email-db';
|
import { openEmailDb, upsertFromRawEml, getSyncMeta, setSyncMeta, updateEmailLabels } from '../../api/email/email-db';
|
||||||
|
|
||||||
type GoogleCredentials = {
|
type GoogleCredentials = {
|
||||||
@@ -14,7 +13,7 @@ type GoogleCredentials = {
|
|||||||
clientSecret: string;
|
clientSecret: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const googleConfigPath = join(homedir(), '.config', 'officer.dev', 'google-oauth.json');
|
const googleConfigPath = join(SERVER_CONFIG_DIR, 'google-oauth.json');
|
||||||
|
|
||||||
async function loadCredentials(userId: string): Promise<GoogleCredentials> {
|
async function loadCredentials(userId: string): Promise<GoogleCredentials> {
|
||||||
const config = await Bun.file(googleConfigPath).json().catch(() => null);
|
const config = await Bun.file(googleConfigPath).json().catch(() => null);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { createTransport, type Transporter } from 'nodemailer';
|
import { createTransport, type Transporter } from 'nodemailer';
|
||||||
import { homedir } from 'node:os';
|
import { join } from 'node:path';
|
||||||
|
|
||||||
const { MAIL_TRANSPORT } = process.env;
|
const { MAIL_TRANSPORT, DATA_PATH } = process.env;
|
||||||
|
const dataPath = DATA_PATH ?? join(process.cwd(), 'data');
|
||||||
|
|
||||||
type SmtpConfig = {
|
type SmtpConfig = {
|
||||||
provider: 'resend' | 'smtp' | 'mailhog';
|
provider: 'resend' | 'smtp' | 'mailhog';
|
||||||
@@ -15,7 +16,7 @@ type SmtpConfig = {
|
|||||||
fromEmail: string;
|
fromEmail: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const settingsPath = `${homedir()}/.config/officer.dev/server-settings.json`;
|
const settingsPath = join(dataPath, 'server-settings', 'server-settings.json');
|
||||||
|
|
||||||
let cachedTransport: Transporter | null = null;
|
let cachedTransport: Transporter | null = null;
|
||||||
let cachedConfigHash: string | null = null;
|
let cachedConfigHash: string | null = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user