mirror of
https://git.mirrors.martin98.com/https://github.com/jina-ai/reader
synced 2025-08-18 18:25:58 +08:00
fix: log charge amount
This commit is contained in:
parent
04eb6b3087
commit
f171e54ac9
@ -364,14 +364,13 @@ ${authMixin}`,
|
|||||||
{ contentType: 'text/plain', envelope: null }
|
{ contentType: 'text/plain', envelope: null }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uid) {
|
if (uid) {
|
||||||
const user = await auth.assertUser();
|
const user = await auth.assertUser();
|
||||||
if (!(user.wallet.total_balance > 0)) {
|
if (!(user.wallet.total_balance > 0)) {
|
||||||
throw new InsufficientBalanceError(`Account balance not enough to run this query, please recharge.`);
|
throw new InsufficientBalanceError(`Account balance not enough to run this query, please recharge.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.rateLimitControl.simpleRPCUidBasedLimit(rpcReflect, uid, ['CRAWL'],
|
const apiRoll = await this.rateLimitControl.simpleRPCUidBasedLimit(rpcReflect, uid, ['CRAWL'],
|
||||||
[
|
[
|
||||||
// 1000 requests per minute
|
// 1000 requests per minute
|
||||||
new Date(Date.now() - 60 * 1000), 1000
|
new Date(Date.now() - 60 * 1000), 1000
|
||||||
@ -383,15 +382,26 @@ ${authMixin}`,
|
|||||||
auth.reportUsage(chargeAmount, 'reader-crawl').catch((err) => {
|
auth.reportUsage(chargeAmount, 'reader-crawl').catch((err) => {
|
||||||
this.logger.warn(`Unable to report usage for ${uid}`, { err: marshalErrorLike(err) });
|
this.logger.warn(`Unable to report usage for ${uid}`, { err: marshalErrorLike(err) });
|
||||||
});
|
});
|
||||||
|
apiRoll._ref?.set({
|
||||||
|
chargeAmount,
|
||||||
|
}, { merge: true }).catch((err) => this.logger.warn(`Failed to log charge amount in apiRoll`, { err }));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (ctx.req.ip) {
|
} else if (ctx.req.ip) {
|
||||||
await this.rateLimitControl.simpleRpcIPBasedLimit(rpcReflect, ctx.req.ip, ['CRAWL'],
|
const apiRoll = await this.rateLimitControl.simpleRpcIPBasedLimit(rpcReflect, ctx.req.ip, ['CRAWL'],
|
||||||
[
|
[
|
||||||
// 100 requests per minute
|
// 100 requests per minute
|
||||||
new Date(Date.now() - 60 * 1000), 100
|
new Date(Date.now() - 60 * 1000), 100
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
rpcReflect.finally(() => {
|
||||||
|
if (chargeAmount) {
|
||||||
|
apiRoll._ref?.set({
|
||||||
|
chargeAmount,
|
||||||
|
}, { merge: true }).catch((err) => this.logger.warn(`Failed to log charge amount in apiRoll`, { err }));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let urlToCrawl;
|
let urlToCrawl;
|
||||||
@ -653,6 +663,10 @@ ${authMixin}`,
|
|||||||
}
|
}
|
||||||
|
|
||||||
getChargeAmount(formatted: { [k: string]: any; }) {
|
getChargeAmount(formatted: { [k: string]: any; }) {
|
||||||
|
if (!formatted) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const textContent = formatted?.content || formatted?.text || formatted?.html;
|
const textContent = formatted?.content || formatted?.text || formatted?.html;
|
||||||
|
|
||||||
if (typeof textContent === 'string') {
|
if (typeof textContent === 'string') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user