Files
inbuxa-webmail/server/src/source.ts
T
jcoffey-dev 2f90e9fbed
ci / node (pull_request) Skipped
ci / version (pull_request) Skipped
github/ci (branch) GitHub Actions
ci / github (pull_request) Successful in 2m17s
ci / docker-build (pull_request) Skipped
ci / publish (pull_request) Skipped
ci / announce (pull_request) Skipped
Serve /.well-known/source
SOURCE_URL and the commit the build was made from, in the form
https://coffeylabs.org/specs/well-known-source/ defines, at the host's
root whatever the base path. The image build passes the commit as
INBUXA_REVISION, like the version; a clean checkout asks git. A build
that can't name its commit, or a checkout with uncommitted changes,
answers 404.
2026-10-28 21:57:33 -07:00

34 lines
1.2 KiB
TypeScript

/**
* ihasmail-inbuxa: `/.well-known/source`, what this webmail runs and where its
* source is, in the form https://coffeylabs.org/specs/well-known-source/
* gives it.
*
* It names SOURCE_URL as the repository and the commit the build was made
* from (`resolveRevision` in scripts/version.mjs). A build that doesn't know
* its commit says nothing and the address is a 404, since a repository without
* a revision doesn't name the build. So does a checkout with uncommitted
* changes: no public revision holds them.
*/
/** A full commit id: 40 hex digits (SHA-1) or 64 (SHA-256). */
export function isCommitId(revision: string | null | undefined): revision is string {
return typeof revision === "string" && /^([0-9a-f]{40}|[0-9a-f]{64})$/i.test(revision);
}
/** The document for a build, or null when it can't name its commit. */
export function sourceDocument(build: { version: string; repository: string; revision: string | null }): string | null {
if (!isCommitId(build.revision)) return null;
return JSON.stringify({
version: 1,
software: [
{
name: "inbuxa Webmail",
version: build.version,
license: "AGPL-3.0-or-later",
repository: build.repository,
revision: build.revision,
},
],
});
}