* Add [polymart] badges (#7429) * fix misspelling issue * add required to all joi objects * fix not found badge return a valid resource issue * fix misspelling issue * fix invalid resource issue * remove default badge color Co-authored-by: chris48s <chris48s@users.noreply.github.com> * remove version default badge color * change version label to the service name * add renderVersionBadge() method for version rendering * fix method name issue * change version regex * fix code style issue * add renderVersionBadge from version and remove the manually added renderer Co-authored-by: chris48s <chris48s@users.noreply.github.com>
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
import Joi from 'joi'
|
|
import { BaseJsonService } from '../index.js'
|
|
|
|
const resourceSchema = Joi.object({
|
|
response: Joi.object({
|
|
resource: Joi.object({
|
|
price: Joi.number().required(),
|
|
downloads: Joi.string().required(),
|
|
reviews: Joi.object({
|
|
count: Joi.number().required(),
|
|
stars: Joi.number().required(),
|
|
}).required(),
|
|
updates: Joi.object({
|
|
latest: Joi.object({
|
|
version: Joi.string().required(),
|
|
}).required(),
|
|
}).required(),
|
|
}).required(),
|
|
}).required(),
|
|
}).required()
|
|
|
|
const notFoundResourceSchema = Joi.object({
|
|
response: Joi.object({
|
|
success: Joi.boolean().required(),
|
|
errors: Joi.object().required(),
|
|
}).required(),
|
|
})
|
|
|
|
const resourceFoundOrNotSchema = Joi.alternatives(
|
|
resourceSchema,
|
|
notFoundResourceSchema
|
|
)
|
|
|
|
const documentation = `
|
|
<p>You can find your resource ID in the url for your resource page.</p>
|
|
<p>Example: <code>https://polymart.org/resource/polymart-plugin.323</code> - Here the Resource ID is 323.</p>`
|
|
|
|
class BasePolymartService extends BaseJsonService {
|
|
async fetch({
|
|
resourceId,
|
|
schema = resourceFoundOrNotSchema,
|
|
url = `https://api.polymart.org/v1/getResourceInfo/?resource_id=${resourceId}`,
|
|
}) {
|
|
return this._requestJson({
|
|
schema,
|
|
url,
|
|
})
|
|
}
|
|
}
|
|
|
|
export { documentation, BasePolymartService }
|