mirror of
https://git.mirrors.martin98.com/https://github.com/jina-ai/reader.git
synced 2025-08-20 21:29:08 +08:00
search now requires authentication
This commit is contained in:
parent
5d865651b1
commit
bd629a836b
@ -93,17 +93,20 @@ export class SearcherHost extends RPCHost {
|
|||||||
const noSlashPath = decodeURIComponent(ctx.req.path).slice(1);
|
const noSlashPath = decodeURIComponent(ctx.req.path).slice(1);
|
||||||
if (!noSlashPath && !q) {
|
if (!noSlashPath && !q) {
|
||||||
const latestUser = uid ? await auth.assertUser() : undefined;
|
const latestUser = uid ? await auth.assertUser() : undefined;
|
||||||
|
const index = this.crawler.getIndex(latestUser);
|
||||||
|
if (!uid) {
|
||||||
|
index.note = 'Authentication is required to use this endpoint. Please provide a valid API key via Authorization header.';
|
||||||
|
}
|
||||||
if (!ctx.req.accepts('text/plain') && (ctx.req.accepts('text/json') || ctx.req.accepts('application/json'))) {
|
if (!ctx.req.accepts('text/plain') && (ctx.req.accepts('text/json') || ctx.req.accepts('application/json'))) {
|
||||||
|
|
||||||
return this.crawler.getIndex(latestUser);
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
return assignTransferProtocolMeta(`${this.crawler.getIndex(latestUser)}`,
|
return assignTransferProtocolMeta(`${index}`,
|
||||||
{ contentType: 'text/plain', envelope: null }
|
{ contentType: 'text/plain', envelope: null }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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.`);
|
||||||
@ -122,7 +125,7 @@ export class SearcherHost extends RPCHost {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const apiRoll = await this.rateLimitControl.simpleRPCUidBasedLimit(
|
const apiRoll = await this.rateLimitControl.simpleRPCUidBasedLimit(
|
||||||
rpcReflect, uid, [rpcReflect.name.toUpperCase()],
|
rpcReflect, uid!, [rpcReflect.name.toUpperCase()],
|
||||||
...rateLimitPolicy
|
...rateLimitPolicy
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -134,20 +137,6 @@ export class SearcherHost extends RPCHost {
|
|||||||
apiRoll.chargeAmount = chargeAmount;
|
apiRoll.chargeAmount = chargeAmount;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (ctx.req.ip) {
|
|
||||||
this.threadLocal.set('ip', ctx.req.ip);
|
|
||||||
const apiRoll = await this.rateLimitControl.simpleRpcIPBasedLimit(rpcReflect, ctx.req.ip, [rpcReflect.name.toUpperCase()],
|
|
||||||
[
|
|
||||||
// 5 requests per minute
|
|
||||||
new Date(Date.now() - 60 * 1000), 5
|
|
||||||
]
|
|
||||||
);
|
|
||||||
rpcReflect.finally(() => {
|
|
||||||
if (chargeAmount) {
|
|
||||||
apiRoll.chargeAmount = chargeAmount;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
delete crawlerOptions.html;
|
delete crawlerOptions.html;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user