mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-30 11:00:11 +08:00
always create a jwt when connecting to a space if a hf_token is present (#8296)
* fix param name * format * always create a jwt if a hf token is present * add changeset * add changeset * remove throw --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
4350215348
commit
929d216d49
6
.changeset/ready-hotels-create.md
Normal file
6
.changeset/ready-hotels-create.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"@gradio/client": patch
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:always create a jwt when connecting to a space if a hf_token is present
|
@ -136,28 +136,24 @@ export class Client {
|
||||
|
||||
try {
|
||||
await this._resolve_config().then(async ({ config }) => {
|
||||
if (config) {
|
||||
this.config = config;
|
||||
if (this.config && this.config.connect_heartbeat) {
|
||||
if (this.config.space_id && this.options.hf_token) {
|
||||
this.jwt = await get_jwt(
|
||||
this.config.space_id,
|
||||
this.options.hf_token
|
||||
);
|
||||
}
|
||||
this.config = config;
|
||||
|
||||
// connect to the heartbeat endpoint via GET request
|
||||
const heartbeat_url = new URL(
|
||||
`${this.config.root}/heartbeat/${this.session_hash}`
|
||||
);
|
||||
if (config.space_id && this.options.hf_token) {
|
||||
this.jwt = await get_jwt(config.space_id, this.options.hf_token);
|
||||
}
|
||||
|
||||
// if the jwt is available, add it to the query params
|
||||
if (this.jwt) {
|
||||
heartbeat_url.searchParams.set("__sign", this.jwt);
|
||||
}
|
||||
if (this.config && this.config.connect_heartbeat) {
|
||||
// connect to the heartbeat endpoint via GET request
|
||||
const heartbeat_url = new URL(
|
||||
`${this.config.root}/heartbeat/${this.session_hash}`
|
||||
);
|
||||
|
||||
this.heartbeat_event = await this.stream(heartbeat_url); // Just connect to the endpoint without parsing the response. Ref: https://github.com/gradio-app/gradio/pull/7974#discussion_r1557717540
|
||||
// if the jwt is available, add it to the query params
|
||||
if (this.jwt) {
|
||||
heartbeat_url.searchParams.set("__sign", this.jwt);
|
||||
}
|
||||
|
||||
this.heartbeat_event = await this.stream(heartbeat_url); // Just connect to the endpoint without parsing the response. Ref: https://github.com/gradio-app/gradio/pull/7974#discussion_r1557717540
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
|
Loading…
Reference in New Issue
Block a user