forked from Mirrors/keyoxide-web
feat: optimize version number generation
This commit is contained in:
parent
fe96ab2c35
commit
4b764583d9
2 changed files with 23 additions and 11 deletions
|
@ -31,7 +31,6 @@ import express from 'express'
|
|||
import markdownImport from 'markdown-it'
|
||||
import { readFileSync } from 'fs'
|
||||
import { getMetaFromReq } from '../server/utils.js'
|
||||
import app from '../index.js'
|
||||
|
||||
const router = express.Router()
|
||||
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) => {
|
||||
// TODO Support responding with JSON object when requested
|
||||
|
||||
let versionDetails = app.get('git_branch')
|
||||
? `+${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}`)
|
||||
const meta = getMetaFromReq(req)
|
||||
return res.status(200).contentType('text/plain').send(meta.keyoxide.semver)
|
||||
})
|
||||
|
||||
router.get('/users/keyoxide', (req, res) => {
|
||||
|
|
|
@ -82,10 +82,30 @@ export function encodeZBase32 (data) {
|
|||
}
|
||||
|
||||
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 {
|
||||
env: req.app.get('env'),
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue