fix: callbacks cleanup and credential timestamp validation (#1669)
Release NapCat / validate-version (push) Canceled after 0s
Release NapCat / Build-Framework (push) Canceled after 0s
Release NapCat / Build-Shell (push) Canceled after 0s
Release NapCat / Download-QNX64 (push) Canceled after 0s
Release NapCat / release-napcat (push) Canceled after 0s
Release NapCat / validate-version (push) Canceled after 0s
Release NapCat / Build-Framework (push) Canceled after 0s
Release NapCat / Build-Shell (push) Canceled after 0s
Release NapCat / Download-QNX64 (push) Canceled after 0s
Release NapCat / release-napcat (push) Canceled after 0s
* fix(rpc): clean callbacks when sending failed * chore: format * fix(pty): handle ws message properly * fix(webui-backend): unify credential timestamp validation Store credential CreatedTime in seconds and validate expiry using the same unit. Keep backward compatibility for legacy millisecond timestamps. * chore: format * Revert "chore: format" This reverts commit 6f2e9f1b53b55e8f4bf4a747ed7b05a0d6e4dbb4. * fix: naming Rename ONE_HOUR_SECONDS to MAX_CREDENTIAL_VALID_SECONDS for clearer intent. Simplify CreatedTime parsing by using Math.floor(Number(...)) and remove the legacy millisecond-to-second conversion branch. Update the time-difference check to use the new constant name.
This commit is contained in:
4 files changed
+39
-10
No files matched your search
@@ -67,6 +67,7 @@ export class MessageTransport implements RpcTransport {
|
||||
resolve: (response: RpcResponse) => void;
|
||||
reject: (error: Error) => void;
|
||||
}>();
|
||||
|
||||
private callbackHandler?: (callbackId: string, args: SerializedValue[]) => Promise<SerializedValue>;
|
||||
private sendMessage: (message: string) => void | Promise<void>;
|
||||
|
||||
@@ -113,15 +114,25 @@ export class MessageTransport implements RpcTransport {
|
||||
}
|
||||
|
||||
async send (request: RpcRequest): Promise<RpcResponse> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.pendingRequests.set(request.id, { resolve, reject });
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
return new Promise(async (resolve, _reject) => {
|
||||
const id = request.id;
|
||||
const reject = (error: any) => {
|
||||
this.pendingRequests.delete(id);
|
||||
_reject(error);
|
||||
};
|
||||
this.pendingRequests.set(id, { resolve, reject });
|
||||
|
||||
const message = JSON.stringify({
|
||||
type: 'request',
|
||||
request,
|
||||
});
|
||||
|
||||
Promise.resolve(this.sendMessage(message)).catch(reject);
|
||||
try {
|
||||
await this.sendMessage(message);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user