Add get profile endpoint

This commit is contained in:
2026-01-19 15:41:49 -07:00
parent d3e6c3863b
commit 5648f813a2
3 changed files with 147 additions and 8 deletions

View File

@@ -63,9 +63,9 @@ export const checkClientDatabaseVersion = (request: Request) => {
if (!allowedDatabaseVersions.includes(clientVersion)) return '-998'
}
export const genTimestamp = (time: number): string => {
time = Math.floor(Date.now() / 1000) - time
time = time < 1 ? 1 : time
export const genTimestamp = (time: number, extra = 0): string => {
let remaining = Math.floor(Date.now() / 1000) - time
remaining = remaining < 1 ? 1 : remaining
const tokens: [number, string][] = [
[31536000, 'year'],
@@ -77,12 +77,17 @@ export const genTimestamp = (time: number): string => {
[1, 'second']
]
for (const [unit, text] of tokens) {
if (time < unit) continue
const parts: string[] = []
const numberOfUnits = Math.floor(time / unit)
return numberOfUnits + ' ' + text + (numberOfUnits > 1 ? 's' : '')
for (const [unit, text] of tokens) {
if (remaining < unit) continue
if (parts.length > extra) break
const value = Math.floor(remaining / unit)
remaining -= value * unit
parts.push(value + ' ' + text + (value > 1 ? 's' : ''))
}
return '1 second'
return parts.length ? parts.join(' ') : '1 second'
}