[Chromewebstore] Extension size & last updated (#10613)

* Bump webextension-store-meta

* Add extension last updated

* Add extension size

* Run linter

* Rename last updated badge
This commit is contained in:
Aiden Gardner
2024-10-21 19:22:43 +11:00
committed by GitHub
parent 04f4fbd156
commit 4e4e3f82c6
6 changed files with 113 additions and 5 deletions

View File

@@ -0,0 +1,41 @@
import { age } from '../color-formatters.js'
import { formatDate } from '../text-formatters.js'
import { NotFound, pathParams } from '../index.js'
import BaseChromeWebStoreService from './chrome-web-store-base.js'
export default class ChromeWebStoreLastUpdated extends BaseChromeWebStoreService {
static category = 'activity'
static route = { base: 'chrome-web-store/last-updated', pattern: ':storeId' }
static openApi = {
'/chrome-web-store/last-updated/{storeId}': {
get: {
summary: 'Chrome Web Store Last Updated',
parameters: pathParams({
name: 'storeId',
example: 'nccfelhkfpbnefflolffkclhenplhiab',
}),
},
},
}
static defaultBadgeData = {
label: 'last updated',
}
async handle({ storeId }) {
const chromeWebStore = await this.fetch({ storeId })
const lastUpdated = chromeWebStore.lastUpdated()
if (lastUpdated == null) {
throw new NotFound({ prettyMessage: 'not found' })
}
const lastUpdatedDate = Date.parse(lastUpdated)
return {
message: formatDate(lastUpdatedDate),
color: age(lastUpdatedDate),
}
}
}

View File

@@ -0,0 +1,18 @@
import { isFormattedDate } from '../test-validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
t.create('Last updated')
.get('/nccfelhkfpbnefflolffkclhenplhiab.json')
.expectBadge({
label: 'last updated',
message: isFormattedDate,
})
t.create('Last updated (not found)')
.get('/invalid-name-of-addon.json')
.expectBadge({
label: 'last updated',
message: 'not found',
})

View File

@@ -0,0 +1,35 @@
import { NotFound, pathParams } from '../index.js'
import BaseChromeWebStoreService from './chrome-web-store-base.js'
export default class ChromeWebStoreSize extends BaseChromeWebStoreService {
static category = 'size'
static route = { base: 'chrome-web-store/size', pattern: ':storeId' }
static openApi = {
'/chrome-web-store/size/{storeId}': {
get: {
summary: 'Chrome Web Store Size',
parameters: pathParams({
name: 'storeId',
example: 'nccfelhkfpbnefflolffkclhenplhiab',
}),
},
},
}
static defaultBadgeData = {
label: 'extension size',
color: 'blue',
}
async handle({ storeId }) {
const chromeWebStore = await this.fetch({ storeId })
const size = chromeWebStore.size()
if (size == null) {
throw new NotFound({ prettyMessage: 'not found' })
}
return { message: size }
}
}

View File

@@ -0,0 +1,13 @@
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
const isFileSize = /^\d+(\.\d+)?(MiB|KiB)$/
t.create('Size').get('/nccfelhkfpbnefflolffkclhenplhiab.json').expectBadge({
label: 'extension size',
message: isFileSize,
})
t.create('Size (not found)')
.get('/invalid-name-of-addon.json')
.expectBadge({ label: 'extension size', message: 'not found' })