Files
shields/services/date/date.service.js
chris48s 5d1ddbc3fe migrate examples to openApi part 13; affects [curseforge date fedora hsts modrinth ore] (#9499)
* migrate some services from examples to openApi

* improve and de-dupe service titles

* improve ore description
2023-12-04 12:53:21 +00:00

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),
})
}
}