-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
ore-sponge-versions.service.js
51 lines (44 loc) · 1.33 KB
/
ore-sponge-versions.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
49
50
51
import { BaseOreService, documentation, keywords } from './ore-base.js'
export default class OreSpongeVersions extends BaseOreService {
static category = 'platform-support'
static route = {
base: 'ore/sponge-versions',
pattern: ':pluginId',
}
static examples = [
{
title: 'Compatible versions (plugins on Ore)',
namedParams: {
pluginId: 'nucleus',
},
staticPreview: this.render({ versions: ['7.3', '6.0'] }),
documentation,
keywords,
},
]
static defaultBadgeData = {
label: 'sponge',
}
static render({ versions }) {
if (versions.length === 0) {
return { message: 'none', color: 'inactive' }
}
return { message: versions.join(' | '), color: 'blue' }
}
transform({ data }) {
const { promoted_versions: promotedVersions } = data
return {
versions: promotedVersions
.reduce((acc, { tags }) => acc.concat(tags), [])
.filter(({ name }) => name.toLowerCase() === 'sponge')
.map(({ display_data: displayData }) => displayData)
// display_data is not mandatory in the schema, filter null values
.filter(x => !!x),
}
}
async handle({ pluginId }) {
const data = await this.fetch({ pluginId })
const { versions } = this.transform({ data })
return this.constructor.render({ versions })
}
}