-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
services/chrome-web-store/chrome-web-store-size.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' }) |