Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chromewebstore] Extension size & last updated #10613

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"smol-toml": "1.3.0",
"svg-path-bbox": "^2.1.0",
"svgpath": "^2.6.0",
"webextension-store-meta": "^1.2.3",
"webextension-store-meta": "^1.2.4",
"xpath": "~0.0.34"
},
"scripts": {
Expand Down
41 changes: 41 additions & 0 deletions services/chrome-web-store/chrome-web-store-last-updated.service.js
Original file line number Diff line number Diff line change
@@ -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: 'extension 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),
}
}
}
18 changes: 18 additions & 0 deletions services/chrome-web-store/chrome-web-store-last-updated.tester.js
Original file line number Diff line number Diff line change
@@ -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: 'extension last updated',
message: isFormattedDate,
})

t.create('Last updated (not found)')
.get('/invalid-name-of-addon.json')
.expectBadge({
label: 'extension last updated',
message: 'not found',
})
35 changes: 35 additions & 0 deletions services/chrome-web-store/chrome-web-store-size.service.js
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 }
}
}
13 changes: 13 additions & 0 deletions services/chrome-web-store/chrome-web-store-size.tester.js
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' })
Loading