Files
Docwell/Database/pb_hooks/docwell.pb.js
T
tajniak81andClaude Opus 5.5 ad26727521
CI / go (Server) (push) Successful in 16m33s
CI / go (Web-App) (push) Successful in 12m1s
CI / frontend (push) Failing after 6m32s
CI / desktop (ubuntu-latest) (push) Failing after 21m52s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
CI / mobile (push) Failing after 5m2s
CI / docker (push) Successful in 18m56s
Docs / build (push) Successful in 10m45s
Docs / deploy (push) Skipped
Add production compose variants and base docwell-db on the PocketBase image
Docker/ and Docker-AIO/ each get docker-compose.prod.yml plus S3,
SeaweedFS and SeaweedFS-split variants, with matching .env.prod*.example
templates and a README.

docwell-db is now built FROM tajniak81/pocketbase-docker-root, which
creates the superuser and serves PocketBase on 8090; data moves to
/pb/pb_data. The boot hook applies DOCWELL_S3_* settings when set.
The AIO start script accepts PB_ENCRYPTION_KEY. The base image is
amd64-only, so the docwell-db release builds amd64 only for now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 11:39:01 +01:00

97 lines
3.4 KiB
JavaScript

// SPDX-License-Identifier: AGPL-3.0-or-later
/// <reference path="../pb_data/types.d.ts" />
// Token check used by docwell-server: returns the "users" record that owns the
// bearer token (with its organization expanded), or 401. Unlike auth-refresh,
// it does not issue a new token.
routerAdd(
"GET",
"/api/docwell/auth/verify",
(e) => {
e.auth.ignoreEmailVisibility(true);
e.app.expandRecord(e.auth, ["organization"], null);
return e.json(200, e.auth);
},
$apis.requireAuth("users"),
);
// Sends one email through PocketBase's SMTP settings, so docwell-server's own
// emails (invites, test mails) use the same mail configuration as the auth
// emails PocketBase sends itself.
routerAdd(
"POST",
"/api/docwell/mail",
(e) => {
const body = e.requestInfo().body;
const to = String(body.to || "").trim();
const subject = String(body.subject || "").trim();
if (!to || !subject) {
throw new BadRequestError("to and subject are required");
}
const meta = e.app.settings().meta;
const message = new MailerMessage({
from: { address: meta.senderAddress, name: meta.senderName },
to: [{ address: to }],
subject: subject,
html: String(body.html || ""),
text: String(body.text || ""),
});
e.app.newMailClient().send(message);
return e.noContent(204);
},
$apis.requireSuperuserAuth(),
);
// Settings that come from the environment are applied on every start, so
// changing an env var and restarting is enough. Settings without an env var
// are left alone: the admin panel manages them.
onBootstrap((e) => {
e.next();
const env = (key) => $os.getenv(key) || "";
const settings = e.app.settings();
if (env("DOCWELL_APP_NAME")) {
settings.meta.appName = env("DOCWELL_APP_NAME");
} else if (settings.meta.appName === "Acme") {
// PocketBase's placeholder name on a fresh database.
settings.meta.appName = "Docwell";
}
settings.meta.appURL = env("DOCWELL_WEB_URL") || "http://localhost:3000";
settings.meta.senderName = settings.meta.appName;
if (env("DOCWELL_MAIL_FROM")) {
settings.meta.senderAddress = env("DOCWELL_MAIL_FROM");
} else if (settings.meta.senderAddress === "support@example.com") {
settings.meta.senderAddress = "no-reply@docwell.localhost";
}
const smtpHost = env("DOCWELL_SMTP_HOST");
if (smtpHost) {
settings.smtp.enabled = true;
settings.smtp.host = smtpHost;
settings.smtp.port = parseInt(env("DOCWELL_SMTP_PORT") || "587", 10);
settings.smtp.username = env("DOCWELL_SMTP_USERNAME");
settings.smtp.password = env("DOCWELL_SMTP_PASSWORD");
settings.smtp.tls = env("DOCWELL_SMTP_TLS") === "true";
}
// File storage. Only when DOCWELL_S3_ENABLED is set: "true" moves uploads to
// the bucket, "false" back to local disk. Unset leaves the admin panel's
// Storage screen in charge.
const s3Enabled = env("DOCWELL_S3_ENABLED");
if (s3Enabled === "true") {
settings.s3.enabled = true;
settings.s3.bucket = env("DOCWELL_S3_BUCKET") || "docwell";
settings.s3.endpoint = env("DOCWELL_S3_ENDPOINT");
settings.s3.region = env("DOCWELL_S3_REGION") || "us-east-1";
settings.s3.accessKey = env("DOCWELL_S3_ACCESS_KEY");
settings.s3.secret = env("DOCWELL_S3_SECRET");
settings.s3.forcePathStyle = env("DOCWELL_S3_FORCE_PATH_STYLE") !== "false";
} else if (s3Enabled === "false") {
settings.s3.enabled = false;
}
e.app.save(settings);
});