electron#ProtocolRequest TypeScript Examples
The following examples show how to use
electron#ProtocolRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ares-pull-proto.ts From dev-manager-desktop with Apache License 2.0 | 6 votes |
export function AresPullProtoHandler(request: ProtocolRequest, callback: ((response: Buffer | ProtocolResponse) => void)): void {
const url = new URL(request.url);
lock.acquire(url.hostname, async (done) => {
try {
const ssh = await obtainSession(url.hostname);
const exec = util.promisify(Client.prototype.exec).bind(ssh);
const channel: ClientChannel = await exec(`cat ${url.pathname}`, {pty: false});
const buffers: Buffer[] = [];
channel.on('data', (data: Buffer) => {
buffers.push(data);
});
channel.on('close', () => {
done(null, Buffer.concat(buffers));
});
} catch (e) {
done(e, null);
}
}).then((buffer) => callback(buffer), (reason) => {
console.log(reason);
callback(null);
});
}