-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
ore-version.service.js
48 lines (41 loc) · 1.08 KB
/
ore-version.service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { renderVersionBadge } from '../version.js'
import { BaseOreService, documentation, keywords } from './ore-base.js'
export default class OreVersion extends BaseOreService {
static category = 'version'
static route = {
base: 'ore/v',
pattern: ':pluginId',
}
static examples = [
{
title: 'Ore Version',
namedParams: {
pluginId: 'nucleus',
},
staticPreview: renderVersionBadge({ version: '2.2.3' }),
documentation,
keywords,
},
]
static defaultBadgeData = {
label: 'version',
}
static render({ version }) {
if (!version) {
return { message: 'none', color: 'inactive' }
}
return renderVersionBadge({ version })
}
transform({ data }) {
const { promoted_versions: promotedVersions } = data
return {
version:
promotedVersions.length === 0 ? undefined : promotedVersions[0].version,
}
}
async handle({ pluginId }) {
const data = await this.fetch({ pluginId })
const { version } = this.transform({ data })
return this.constructor.render({ version })
}
}