From afedaa7c9f3bf32abbd669d5339ed10e6a72f87d Mon Sep 17 00:00:00 2001 From: saibotk Date: Mon, 1 Jun 2020 04:32:25 +0200 Subject: [PATCH] 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> --- services/steam/steam-workshop.service.js | 41 ++++++++++++++++++++++++ services/steam/steam-workshop.tester.js | 8 +++++ 2 files changed, 49 insertions(+) diff --git a/services/steam/steam-workshop.service.js b/services/steam/steam-workshop.service.js index 8c438fdfb1..eb53f0d86a 100644 --- a/services/steam/steam-workshop.service.js +++ b/services/steam/steam-workshop.service.js @@ -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, diff --git a/services/steam/steam-workshop.tester.js b/services/steam/steam-workshop.tester.js index 82178e5f53..c2963e3828 100644 --- a/services/steam/steam-workshop.tester.js +++ b/services/steam/steam-workshop.tester.js @@ -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' })