import path from 'path'; import { createWriteStream } from 'fs-extra'; import { t } from '../../../shared/services/translation/t'; import { container, Service } from '../../core/container'; import { ipcServer } from '../ipc/ipc-server'; ipcServer.answer(IpcChannel.NHENTAI_SAVE_FAVORITES, async (): Promise => { const nhentaiApi = container.get(Service.NHENTAI_API); const dialog = container.get(Service.DIALOG); const result = await dialog.selectFolder({ title: t('imperatives.dialog.select_torrent_save_location'), }); if (result.canceled) { return; } const favoritesStream = await nhentaiApi.getFavorites(); return new Promise((resolve) => { favoritesStream.on('data', (favorite: Nhentai.Favorite) => { const writable = createWriteStream(path.resolve(result.filePaths[0], favorite.name)); favorite.torrentFile.pipe(writable); }); favoritesStream.once('end', resolve); }); }); ipcServer.answer( IpcChannel.NHENTAI_GET_WORK, async ({ galleryId }: { galleryId: string }): Promise => { const nhentaiSourceGetter = container.get(Service.NHENTAI_SOURCE_GETTER); const work = await nhentaiSourceGetter.find(galleryId); return work; }, );