/
Mativ
/
solo-master
Обзор
Документация
Войти
/
Mativ
/
solo-master
Код
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/services/ImageService.ts
36 строк
1 KB
mativ
fix by linter
02 май 2026, 16:53
02 май 2026, 16:53
c75054a
Код
Авторство
О чём код?
import { dialog } from 'electron'; import * as fs from 'fs'; import * as path from 'path'; import { WindowsService } from './WindowsService'; class ImageServiceImpl { loadAsBase64(): { base64: string, name: string } | undefined { const file = this.selectImage(); if (!file) return undefined; try { const data = fs.readFileSync(file); const base64 = `data:;base64,${data.toString('base64')}`; const name = path.basename(file, path.extname(file)); return { base64, name }; } catch { throw new Error("Не удалось прочитать файл изображения"); } } private selectImage(): string | undefined{ const files = dialog.showOpenDialogSync(WindowsService.getMain(), { properties: ['openFile'], filters: [ { name: 'Images', extensions: ['jpg', 'jpeg', 'png', 'gif', 'webp'] }, { name: 'All Files', extensions: ['*'] }, ] }); if (!files) { return undefined; } return files[0]; } } export const ImageService = new ImageServiceImpl();