From 21f60c6d7282c4935947e73eeee9ec3c87cfa43b Mon Sep 17 00:00:00 2001 From: Aiden Gardner <19619206+aiden2480@users.noreply.github.com> Date: Mon, 14 Oct 2024 22:03:40 +1100 Subject: [PATCH] Add extension size --- .../chrome-web-store-size.service.js | 35 +++++++++++++++++++ .../chrome-web-store-size.tester.js | 13 +++++++ 2 files changed, 48 insertions(+) create mode 100644 services/chrome-web-store/chrome-web-store-size.service.js create mode 100644 services/chrome-web-store/chrome-web-store-size.tester.js diff --git a/services/chrome-web-store/chrome-web-store-size.service.js b/services/chrome-web-store/chrome-web-store-size.service.js new file mode 100644 index 0000000000000..1ce05b3128052 --- /dev/null +++ b/services/chrome-web-store/chrome-web-store-size.service.js @@ -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 } + } +} diff --git a/services/chrome-web-store/chrome-web-store-size.tester.js b/services/chrome-web-store/chrome-web-store-size.tester.js new file mode 100644 index 0000000000000..94c2b89558049 --- /dev/null +++ b/services/chrome-web-store/chrome-web-store-size.tester.js @@ -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' })