mirror of https://github.com/openclaw/openclaw.git
refactor: share tlon channel put requests
This commit is contained in:
parent
7ca8804a33
commit
5af8322ff5
|
|
@ -115,20 +115,7 @@ export class UrbitSSEClient {
|
||||||
app: string;
|
app: string;
|
||||||
path: string;
|
path: string;
|
||||||
}) {
|
}) {
|
||||||
const { response, release } = await urbitFetch({
|
const { response, release } = await this.putChannelPayload([subscription], {
|
||||||
baseUrl: this.url,
|
|
||||||
path: `/~/channel/${this.channelId}`,
|
|
||||||
init: {
|
|
||||||
method: "PUT",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Cookie: this.cookie,
|
|
||||||
},
|
|
||||||
body: JSON.stringify([subscription]),
|
|
||||||
},
|
|
||||||
ssrfPolicy: this.ssrfPolicy,
|
|
||||||
lookupFn: this.lookupFn,
|
|
||||||
fetchImpl: this.fetchImpl,
|
|
||||||
timeoutMs: 30_000,
|
timeoutMs: 30_000,
|
||||||
auditContext: "tlon-urbit-subscribe",
|
auditContext: "tlon-urbit-subscribe",
|
||||||
});
|
});
|
||||||
|
|
@ -359,20 +346,7 @@ export class UrbitSSEClient {
|
||||||
"event-id": eventId,
|
"event-id": eventId,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { response, release } = await urbitFetch({
|
const { response, release } = await this.putChannelPayload([ackData], {
|
||||||
baseUrl: this.url,
|
|
||||||
path: `/~/channel/${this.channelId}`,
|
|
||||||
init: {
|
|
||||||
method: "PUT",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Cookie: this.cookie,
|
|
||||||
},
|
|
||||||
body: JSON.stringify([ackData]),
|
|
||||||
},
|
|
||||||
ssrfPolicy: this.ssrfPolicy,
|
|
||||||
lookupFn: this.lookupFn,
|
|
||||||
fetchImpl: this.fetchImpl,
|
|
||||||
timeoutMs: 10_000,
|
timeoutMs: 10_000,
|
||||||
auditContext: "tlon-urbit-ack",
|
auditContext: "tlon-urbit-ack",
|
||||||
});
|
});
|
||||||
|
|
@ -445,20 +419,7 @@ export class UrbitSSEClient {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
{
|
{
|
||||||
const { response, release } = await urbitFetch({
|
const { response, release } = await this.putChannelPayload(unsubscribes, {
|
||||||
baseUrl: this.url,
|
|
||||||
path: `/~/channel/${this.channelId}`,
|
|
||||||
init: {
|
|
||||||
method: "PUT",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Cookie: this.cookie,
|
|
||||||
},
|
|
||||||
body: JSON.stringify(unsubscribes),
|
|
||||||
},
|
|
||||||
ssrfPolicy: this.ssrfPolicy,
|
|
||||||
lookupFn: this.lookupFn,
|
|
||||||
fetchImpl: this.fetchImpl,
|
|
||||||
timeoutMs: 30_000,
|
timeoutMs: 30_000,
|
||||||
auditContext: "tlon-urbit-unsubscribe",
|
auditContext: "tlon-urbit-unsubscribe",
|
||||||
});
|
});
|
||||||
|
|
@ -501,4 +462,27 @@ export class UrbitSSEClient {
|
||||||
await release();
|
await release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async putChannelPayload(
|
||||||
|
payload: unknown,
|
||||||
|
params: { timeoutMs: number; auditContext: string },
|
||||||
|
) {
|
||||||
|
return await urbitFetch({
|
||||||
|
baseUrl: this.url,
|
||||||
|
path: `/~/channel/${this.channelId}`,
|
||||||
|
init: {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Cookie: this.cookie,
|
||||||
|
},
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
},
|
||||||
|
ssrfPolicy: this.ssrfPolicy,
|
||||||
|
lookupFn: this.lookupFn,
|
||||||
|
fetchImpl: this.fetchImpl,
|
||||||
|
timeoutMs: params.timeoutMs,
|
||||||
|
auditContext: params.auditContext,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue