mirror of
https://github.com/HeyPuter/puter.git
synced 2026-02-19 21:21:23 -06:00
dev: add cost service integration to IPGeoService
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user