Skip to content

Commit

Permalink
finish add thumbnails files in upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ArceDanielShok committed Dec 2, 2024
1 parent dc6a016 commit 65fc4a4
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 342 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
"detect-port": "^1.3.0",
"dotenv": "^10.0.0",
"dotenv-webpack": "^7.0.3",
"electron": "^25.8.1",
"electron": "^27.3.11",
"electron-builder": "^23.6.0",
"electron-devtools-installer": "^3.2.0",
"electron-notarize": "^1.1.1",
Expand Down Expand Up @@ -303,7 +303,6 @@
"react-router-dom": "^6.2.1",
"reflect-metadata": "^0.1.13",
"regenerator-runtime": "^0.13.9",
"sharp": "^0.33.5",
"socket.io-client": "^4.4.1",
"tiny-glob": "^0.2.9",
"uuid": "^8.3.2"
Expand Down
5 changes: 4 additions & 1 deletion src/apps/main/fordwardToWindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,14 @@ ipcMainDrive.on('FILE_CREATED', async (_, payload) => {
Logger.info('FILE_CREATED', fullPath);
Logger.info('FILE_CREATED', isAbsolutePath(fullPath));

if (!path.isAbsolute(fullPath)) {
if (!isAbsolutePath(fullPath)) {
const root = configStore.get('syncRoot');
Logger.info('FILE_CREATED', root);
fullPath = path.join(root, fullPath);
}

Logger.info('FILE_CREATED', fullPath);

await createAndUploadThumbnail(fileId, nameWithExtension, fullPath);

broadcastToWindows('sync-info-update', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
isImageThumbnailable,
isPdfThumbnailable,
} from '../domain/ThumbnableExtension';
// import sharp from 'sharp';
import fs from 'fs';
import { nativeImage } from 'electron';

export const ThumbnailConfig = {
MaxWidth: 300,
Expand Down Expand Up @@ -50,6 +49,22 @@ const PAGE_TO_PDF_THUMBNAIL = 1;
// .toBuffer();
// }

async function generateImageThumbnail(filePath: string): Promise<Buffer> {
const image = nativeImage.createFromPath(filePath);

if (!image.isEmpty()) {
// Redimensionar la imagen manteniendo el aspecto
const resizedImage = image.resize({ width: ThumbnailConfig.MaxHeight });

// Obtener el buffer como PNG
const buffer = resizedImage.toPNG();

return buffer; // Devolver el buffer
} else {
throw new Error('No se pudo cargar la imagen.');
}
}

function getExtension(pathLike: string) {
const { ext } = path.parse(pathLike);

Expand All @@ -63,9 +78,9 @@ export async function obtainImageToThumbnailIt(

Logger.info(`[THUMBNAIL] Extension: ${ext}`);

// if (isImageThumbnailable(ext)) {
// return await generateImageThumbnail(filePath);
// }
if (isImageThumbnailable(ext)) {
return await generateImageThumbnail(filePath);
}

// if (isPdfThumbnailable(ext)) {
// return await generatePDFThumbnail(filePath);
Expand Down
14 changes: 0 additions & 14 deletions src/apps/main/virtual-root-folder/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ const HOME_FOLDER_PATH = app.getPath('home');

const VIRTUAL_DRIVE_FOLDER = path.join(HOME_FOLDER_PATH, ROOT_FOLDER_NAME);

async function existsFolder(pathname: string): Promise<boolean> {
try {
await fs.access(pathname);

return true;
} catch {
return false;
}
}

export async function clearDirectory(pathname: string): Promise<boolean> {
try {
Expand All @@ -32,11 +23,6 @@ export async function clearDirectory(pathname: string): Promise<boolean> {
}
}

async function isEmptyFolder(pathname: string): Promise<boolean> {
const filesInFolder = await fs.readdir(pathname);

return filesInFolder.length === 0;
}

function setSyncRoot(pathname: string): void {
const pathNameWithSepInTheEnd =
Expand Down
133 changes: 0 additions & 133 deletions test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
"src/workers/backups",
"src/workers/filesystems",
]
}
}
Loading

0 comments on commit 65fc4a4

Please sign in to comment.