dev: add cost service integration to IPGeoService

This commit is contained in:
KernelDeimos
2025-04-22 12:07:13 -04:00
parent 7945586050
commit b80052f177

View File

@@ -1,3 +1,4 @@
const APIError = require("../../api/APIError");
const BaseService = require("../../services/BaseService");
class IPGeoService extends BaseService {
@@ -40,6 +41,20 @@ class IPGeoService extends BaseService {
ip,
});
{
const microcents_per_request = this.config.microcents_per_request
?? 7000;
const svc_cost = this.services.get('cost');
const usageAllowed = await svc_cost.get_funding_allowed({
minimum: microcents_per_request,
});
if ( ! usageAllowed ) {
throw APIError.create('insufficient_funds');
}
await svc_cost.record_cost({ cost: microcents_per_request });
}
const resp = await axios.request({
method: 'GET',
url: 'https://api.ipgeolocation.io/ipgeo?' + qstr,