Browse Source

moved platform check logic to API layer

Abhinav 2 years ago
parent
commit
edf6274750
2 changed files with 11 additions and 7 deletions
  1. 10 0
      src/api/imageProcessor.ts
  2. 1 7
      src/services/imageProcessor.ts

+ 10 - 0
src/api/imageProcessor.ts

@@ -1,10 +1,15 @@
+import { CustomErrors } from '../constants/errors';
 import { ipcRenderer } from 'electron/renderer';
 import { ipcRenderer } from 'electron/renderer';
 import { existsSync } from 'fs';
 import { existsSync } from 'fs';
 import { writeStream } from '../services/fs';
 import { writeStream } from '../services/fs';
 import { logError } from '../services/logging';
 import { logError } from '../services/logging';
 import { ElectronFile } from '../types';
 import { ElectronFile } from '../types';
+import { isPlatform } from '../utils/common/platform';
 
 
 export async function convertHEIC(fileData: Uint8Array): Promise<Uint8Array> {
 export async function convertHEIC(fileData: Uint8Array): Promise<Uint8Array> {
+    if (isPlatform('windows')) {
+        throw Error(CustomErrors.WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED);
+    }
     const convertedFileData = await ipcRenderer.invoke(
     const convertedFileData = await ipcRenderer.invoke(
         'convert-heic',
         'convert-heic',
         fileData
         fileData
@@ -20,6 +25,11 @@ export async function generateImageThumbnail(
     let inputFilePath = null;
     let inputFilePath = null;
     let createdTempInputFile = null;
     let createdTempInputFile = null;
     try {
     try {
+        if (isPlatform('windows')) {
+            throw Error(
+                CustomErrors.WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED
+            );
+        }
         if (!existsSync(inputFile.path)) {
         if (!existsSync(inputFile.path)) {
             const tempFilePath = await ipcRenderer.invoke(
             const tempFilePath = await ipcRenderer.invoke(
                 'get-temp-file-path',
                 'get-temp-file-path',

+ 1 - 7
src/services/imageProcessor.ts

@@ -5,7 +5,7 @@ import { existsSync, rmSync } from 'fs';
 import { readFile, writeFile } from 'promise-fs';
 import { readFile, writeFile } from 'promise-fs';
 import { generateTempFilePath } from '../utils/temp';
 import { generateTempFilePath } from '../utils/temp';
 import { logErrorSentry } from './sentry';
 import { logErrorSentry } from './sentry';
-import { isPlatform } from '../utils/main';
+import { isPlatform } from '../utils/common/platform';
 import { isDev } from '../utils/common';
 import { isDev } from '../utils/common';
 import path from 'path';
 import path from 'path';
 import log from 'electron-log';
 import log from 'electron-log';
@@ -82,9 +82,6 @@ export async function convertHEIC(
 ): Promise<Uint8Array> {
 ): Promise<Uint8Array> {
     let tempInputFilePath: string;
     let tempInputFilePath: string;
     let tempOutputFilePath: string;
     let tempOutputFilePath: string;
-    if (isPlatform('windows')) {
-        throw Error(CustomErrors.WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED);
-    }
     try {
     try {
         tempInputFilePath = await generateTempFilePath('input.heic');
         tempInputFilePath = await generateTempFilePath('input.heic');
         tempOutputFilePath = await generateTempFilePath('output.jpeg');
         tempOutputFilePath = await generateTempFilePath('output.jpeg');
@@ -173,9 +170,6 @@ export async function generateImageThumbnail(
 ): Promise<Uint8Array> {
 ): Promise<Uint8Array> {
     let tempOutputFilePath: string;
     let tempOutputFilePath: string;
     let quality = MAX_QUALITY;
     let quality = MAX_QUALITY;
-    if (isPlatform('windows')) {
-        throw Error(CustomErrors.WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED);
-    }
     try {
     try {
         tempOutputFilePath = await generateTempFilePath('thumb.jpeg');
         tempOutputFilePath = await generateTempFilePath('thumb.jpeg');
         let thumbnail: Uint8Array;
         let thumbnail: Uint8Array;