feat: optimize version number generation

This commit is contained in:
Yarmo Mackenbach 2024-01-27 22:35:21 +01:00
parent fe96ab2c35
commit 4b764583d9
No known key found for this signature in database
GPG key ID: C248C28D432560ED
2 changed files with 23 additions and 11 deletions

View file

@ -31,7 +31,6 @@ import express from 'express'
import markdownImport from 'markdown-it' import markdownImport from 'markdown-it'
import { readFileSync } from 'fs' import { readFileSync } from 'fs'
import { getMetaFromReq } from '../server/utils.js' import { getMetaFromReq } from '../server/utils.js'
import app from '../index.js'
const router = express.Router() const router = express.Router()
const md = markdownImport({ typographer: true }) const md = markdownImport({ typographer: true })
@ -70,15 +69,8 @@ router.get('/.well-known/webfinger', (req, res) => {
router.get('/.well-known/keyoxide/version', async (req, res) => { router.get('/.well-known/keyoxide/version', async (req, res) => {
// TODO Support responding with JSON object when requested // TODO Support responding with JSON object when requested
const meta = getMetaFromReq(req)
let versionDetails = app.get('git_branch') return res.status(200).contentType('text/plain').send(meta.keyoxide.semver)
? `+${app.get('git_branch')}`
: ''
versionDetails += (app.get('git_branch') && app.get('git_hash'))
? `.${app.get('git_hash').substring(0, 10)}`
: ''
return res.status(200).contentType('text/plain').send(`${app.get('keyoxide_name')}/${app.get('keyoxide_version')}${versionDetails}`)
}) })
router.get('/users/keyoxide', (req, res) => { router.get('/users/keyoxide', (req, res) => {

View file

@ -82,10 +82,30 @@ export function encodeZBase32 (data) {
} }
export function getMetaFromReq (req) { export function getMetaFromReq (req) {
let versionDetails = req.app.get('git_branch')
? `+${req.app.get('git_branch')}`
: ''
versionDetails += (req.app.get('git_branch') && req.app.get('git_hash'))
? `.${req.app.get('git_hash').substring(0, 10)}`
: ''
const semver = `${req.app.get('keyoxide_name')}/${req.app.get('keyoxide_version')}${versionDetails}`
const sourceUrl = req.app.get('git_hash')
? `https://codeberg.org/keyoxide/keyoxide-web/src/commit/${req.app.get('git_hash')}`
: req.app.get('git_branch')
? `https://codeberg.org/keyoxide/keyoxide-web/src/branch/${req.app.get('git_branch')}`
: 'https://codeberg.org/keyoxide/keyoxide-web'
return { return {
env: req.app.get('env'), env: req.app.get('env'),
keyoxide: { keyoxide: {
version: req.app.get('keyoxide_version') name: req.app.get('keyoxide_name'),
version: req.app.get('keyoxide_version'),
branch: req.app.get('git_branch'),
hash: req.app.get('git_hash'),
semver,
sourceUrl
} }
} }
} }