-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Expand file tree
/
Copy pathamo-downloads.service.js
More file actions
66 lines (56 loc) · 1.82 KB
/
Copy pathamo-downloads.service.js
File metadata and controls
66 lines (56 loc) · 1.82 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { renderDownloadsBadge } from '../downloads.js'
import { deprecatedService, pathParam, queryParam } from '../index.js'
import {
BaseAmoService,
description as baseDescription,
queryParamSchema,
} from './amo-base.js'
const description = `${baseDescription}
Previously \`amo/d\` provided a “total downloads” badge. However,
[updates to the v3 API](https://github.com/badges/shields/issues/3079)
only give us weekly downloads. The route \`amo/d\` redirects to \`amo/dw\`.
`
class AmoWeeklyDownloads extends BaseAmoService {
static category = 'downloads'
static route = { base: 'amo/dw', pattern: ':addonId', queryParamSchema }
static openApi = {
'/amo/dw/{addonId}': {
get: {
summary: 'Mozilla Add-on Downloads',
description,
parameters: [
pathParam({ name: 'addonId', example: 'dustman' }),
queryParam({
name: 'registry',
example: 'thunderbird',
schema: { type: 'string', enum: ['firefox', 'thunderbird'] },
description:
'Registry to use. Can be `firefox` (default) or `thunderbird`.',
}),
],
},
},
}
static _cacheLength = 21600
static defaultBadgeData = { label: 'downloads' }
static render({ downloads }) {
return renderDownloadsBadge({ downloads, interval: 'week' })
}
async handle({ addonId }, { registry }) {
const data = await this.fetch({ addonId, registry })
return this.constructor.render({
downloads: data.weekly_downloads,
})
}
}
const AmoLegacyRedirect = deprecatedService({
category: 'downloads',
label: 'mozilla-add-on',
route: {
base: 'amo/d',
pattern: ':addonId',
},
dateAdded: new Date('2025-12-20'),
issueUrl: 'https://github.com/badges/shields/pull/11583',
})
export { AmoWeeklyDownloads, AmoLegacyRedirect }