* migrate some services from examples to openApi * improve and de-dupe service titles * improve ore description
42 lines
971 B
JavaScript
42 lines
971 B
JavaScript
import { formatRelativeDate } from '../text-formatters.js'
|
|
import { BaseService, pathParams } from '../index.js'
|
|
|
|
const description = `
|
|
<p>
|
|
Supply a unix timestamp in seconds to display the relative time from/to now
|
|
</p>
|
|
`
|
|
|
|
export default class Date extends BaseService {
|
|
static category = 'other'
|
|
static route = { base: 'date', pattern: ':timestamp(-?[0-9]+)' }
|
|
|
|
static openApi = {
|
|
'/date/{timestamp}': {
|
|
get: {
|
|
summary: 'Relative date',
|
|
description,
|
|
parameters: pathParams({
|
|
name: 'timestamp',
|
|
example: '1540814400',
|
|
}),
|
|
},
|
|
},
|
|
}
|
|
|
|
static defaultBadgeData = { label: 'date' }
|
|
|
|
static render({ relativeDateString }) {
|
|
return {
|
|
message: relativeDateString,
|
|
color: relativeDateString === 'invalid date' ? 'grey' : 'blue',
|
|
}
|
|
}
|
|
|
|
async handle({ timestamp }) {
|
|
return this.constructor.render({
|
|
relativeDateString: formatRelativeDate(timestamp),
|
|
})
|
|
}
|
|
}
|