Add the /steam/update-date badge, run [steam] (#5154)

* Add the /steam/update-date badge

This adds the /steam/update-date badge, to also provide a badge that shows the date of a file on steam when it was last updated.

* Add class to module exports

* Add new field to schema definition

This fixes the tests

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
saibotk
2020-06-01 04:32:25 +02:00
committed by GitHub
parent 88ea1f9149
commit afedaa7c9f
2 changed files with 49 additions and 0 deletions

View File

@@ -63,6 +63,7 @@ const steamFileSchema = Joi.object({
Joi.object({
file_size: Joi.number().integer().required(),
time_created: Joi.number().integer().required(),
time_updated: Joi.number().integer().required(),
subscriptions: Joi.number().integer().required(),
favorited: Joi.number().integer().required(),
lifetime_subscriptions: Joi.number().integer().required(),
@@ -276,6 +277,45 @@ class SteamFileReleaseDate extends SteamFileService {
}
}
class SteamFileUpdateDate extends SteamFileService {
static get category() {
return 'activity'
}
static get route() {
return {
base: 'steam/update-date',
pattern: ':fileId',
}
}
static get examples() {
return [
{
title: 'Steam Update Date',
namedParams: { fileId: '100' },
staticPreview: this.render({
updateDate: new Date(0).setUTCSeconds(1538288239),
}),
documentation,
},
]
}
static get defaultBadgeData() {
return { label: 'update date' }
}
static render({ updateDate }) {
return { message: formatDate(updateDate), color: ageColor(updateDate) }
}
async onRequest({ response }) {
const updateDate = new Date(0).setUTCSeconds(response.time_updated)
return this.constructor.render({ updateDate })
}
}
class SteamFileSubscriptions extends SteamFileService {
static get category() {
return 'rating'
@@ -426,6 +466,7 @@ module.exports = {
SteamCollectionSize,
SteamFileSize,
SteamFileReleaseDate,
SteamFileUpdateDate,
SteamFileSubscriptions,
SteamFileFavorites,
SteamFileDownloads,

View File

@@ -18,6 +18,10 @@ t.create('Release Date')
.get('/release-date/1523924535.json')
.expectBadge({ label: 'release date', message: isFormattedDate })
t.create('Update Date')
.get('/update-date/1523924535.json')
.expectBadge({ label: 'update date', message: isFormattedDate })
t.create('Subscriptions')
.get('/subscriptions/1523924535.json')
.expectBadge({ label: 'subscriptions', message: isMetric })
@@ -46,6 +50,10 @@ t.create('Release Date | File Not Found')
.get('/release-date/1.json')
.expectBadge({ label: 'release date', message: 'file not found' })
t.create('Update Date | File Not Found')
.get('/update-date/1.json')
.expectBadge({ label: 'update date', message: 'file not found' })
t.create('Subscriptions | File Not Found')
.get('/subscriptions/1.json')
.expectBadge({ label: 'subscriptions', message: 'file not found' })