@fyko/export-api

0.3.1 • Public • Published

@fyko/export-api

Generated code for interacting with the Export API.

Example

import { credentials } from '@grpc/grpc-js';
import { ExporterClient } from '@fyko/export-api/client';
import { CreateExportRequest, CreateExportResponse, ExportFormat } from '@fyko/export-api/types';
import { writeFile } from 'fs/promises';

const client = new ExporterClient(
    `localhost:${process.env.PORT}`,
    credentials.createInsecure(),
);

void (async () => {
	const request = new CreateExportRequest();
	request.setChannelId(process.env.DISCORD_CHANNEL!);
	request.setToken(process.env.DISCORD_TOKEN!);
	request.setExportFormat(ExportFormat.HTMLDARK);

	return new Promise(async (res, rej) => {
		const stream = client.createExport(request);


		const chunks: (string | Uint8Array)[] = [];
		stream.on('data', (response: CreateExportResponse) => {
			const progress = response.getProgress()
			if (progress) console.log(progress);
			
			const data = response.getData();
			const inner = data?.getData();
			if (inner) {
				console.log(`Inner exists!`); 
				chunks.push(inner);
			}
		});

		stream.on('end', async () => {
			await writeFile('./foo.html', chunks);
			return res(void 0);
		});

        stream.on('error', rej);
	});
})();

Readme

Keywords

none

Package Sidebar

Install

npm i @fyko/export-api

Weekly Downloads

1

Version

0.3.1

License

MIT

Unpacked Size

42.6 kB

Total Files

17

Last publish

Collaborators

  • fyko