Skip to content

Commit

Permalink
Merge pull request #36 from UdaraJay/0.8.2
Browse files Browse the repository at this point in the history
AI search & ask
  • Loading branch information
UdaraJay committed Dec 2, 2023
2 parents ad36837 + e16c31f commit 601d252
Show file tree
Hide file tree
Showing 44 changed files with 6,907 additions and 334 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@
"electron-updater": "^5.3.0",
"framer-motion": "^10.12.18",
"gray-matter": "^4.0.3",
"llamaindex": "^0.0.35",
"luxon": "^3.3.0",
"million": "^2.6.4",
"openai": "4.0.0-beta.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.11.2"
"react-router-dom": "^6.11.2",
"react-textarea-autosize": "^8.5.3"
},
"devDependencies": {
"@adobe/css-tools": "^4.3.1",
Expand Down
4 changes: 2 additions & 2 deletions release/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pile",
"version": "0.8.1",
"version": "0.8.2",
"description": "Pile: Everyday journal and thought companion.",
"license": "MIT",
"author": {
Expand Down
136 changes: 136 additions & 0 deletions src/main/handlers/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { ipcMain, app, dialog } from 'electron';
import fs from 'fs';
import path from 'path';
import pileHelper from '../utils/pileHelper';
import matter from 'gray-matter';

ipcMain.on('update-file', (event, { path, content }) => {
pileHelper.updateFile(path, content);
});

ipcMain.on('change-folder', (event, newPath) => {
pileHelper.changeWatchFolder(newPath);
});

ipcMain.handle('matter-parse', async (event, file) => {
try {
const post = matter(file);
return post;
} catch (error) {
return null;
}
});

ipcMain.handle('matter-stringify', async (event, { content, data }) => {
const stringifiedContent = matter.stringify(content, data);
return stringifiedContent;
});

ipcMain.handle('get-files', async (event, dirPath) => {
const files = await pileHelper.getFilesInFolder(dirPath);
return files;
});

ipcMain.handle('get-file', async (event, filePath) => {
const content = await pileHelper.getFile(filePath).catch(() => null);
return content;
});

ipcMain.on('get-config-file-path', (event) => {
const userHomeDirectoryPath = app.getPath('home');
const pilesConfig = path.join(userHomeDirectoryPath, 'Piles', 'piles.json');
event.returnValue = pilesConfig;
});

ipcMain.on('open-file-dialog', async (event) => {
const directory = await dialog.showOpenDialog({
properties: ['openDirectory'],
});
if (!directory.canceled) {
event.sender.send('selected-directory', directory.filePaths[0]);
}
});

ipcMain.handle(
'save-file',
async (event, { fileData, fileExtension, storePath }) => {
try {
const currentDate = new Date();
const year = String(currentDate.getFullYear()).slice(-2);
const month = String(currentDate.getMonth() + 1).padStart(2, '0');
const day = String(currentDate.getDate()).padStart(2, '0');
const hours = String(currentDate.getHours()).padStart(2, '0');
const minutes = String(currentDate.getMinutes()).padStart(2, '0');
const seconds = String(currentDate.getSeconds()).padStart(2, '0');
const fileName = `${year}${month}${day}-${hours}${minutes}${seconds}.${fileExtension}`;
const fullStorePath = path.join(
storePath,
String(currentDate.getFullYear()),
currentDate.toLocaleString('default', { month: 'short' }),
'media'
);
const newFilePath = path.join(fullStorePath, fileName);

// Convert Data URL to Buffer
const dataUrlParts = fileData.split(';base64,');
const fileBuffer = Buffer.from(dataUrlParts[1], 'base64');

await fs.promises.mkdir(fullStorePath, { recursive: true });
await fs.promises.writeFile(newFilePath, fileBuffer);
return newFilePath;
} catch (error) {
console.error('Failed to save the file:', error);
}
}
);

ipcMain.handle('open-file', async (event, data) => {
let attachments: string[] = [];
const storePath = data.storePath;
const selected = await dialog.showOpenDialog({
properties: ['openFile'],
filters: [
{ name: 'Images', extensions: ['jpg', 'jpeg', 'png', 'gif', 'svg'] },
{ name: 'Movies', extensions: ['mp4', 'mov'] },
],
});

const selectedFiles = selected.filePaths || [];

if (selected.canceled) {
return attachments;
}

for (const filePath of selectedFiles) {
const currentDate = new Date();
const year = String(currentDate.getFullYear()).slice(-2);
const month = String(currentDate.getMonth() + 1).padStart(2, '0');
const day = String(currentDate.getDate()).padStart(2, '0');
const hours = String(currentDate.getHours()).padStart(2, '0');
const minutes = String(currentDate.getMinutes()).padStart(2, '0');
const seconds = String(currentDate.getSeconds()).padStart(2, '0');
const selectedFileName = filePath.split('/').pop();

if (!selectedFileName) return;

const extension = selectedFileName.split('.').pop();
const fileName = `${year}${month}${day}-${hours}${minutes}${seconds}.${extension}`;
const fullStorePath = path.join(
storePath,
String(currentDate.getFullYear()),
currentDate.toLocaleString('default', { month: 'short' }),
'media'
);
const newFilePath = path.join(fullStorePath, fileName);

try {
await fs.promises.mkdir(fullStorePath, { recursive: true });
await fs.promises.copyFile(filePath, newFilePath);
attachments.push(newFilePath);
} catch (err) {
console.error(err);
}
}

return attachments;
});
20 changes: 20 additions & 0 deletions src/main/handlers/highlights.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ipcMain } from 'electron';
import pileHighlights from '../utils/pileHighlights';

ipcMain.handle('highlights-load', (event, pilePath) => {
const highlights = pileHighlights.load(pilePath);
return highlights;
});

ipcMain.handle('highlights-get', (event) => {
const highlights = pileHighlights.get();
return highlights;
});

ipcMain.handle('highlights-create', (event, highlight) => {
pileHighlights.create(highlight);
});

ipcMain.handle('highlights-delete', (event, highlight) => {
pileHighlights.delete(highlight);
});
23 changes: 23 additions & 0 deletions src/main/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ipcMain } from 'electron';
import { getLinkPreview, getLinkContent } from '../utils/linkPreview';
import pileIndex from '../utils/pileIndex';

ipcMain.handle('index-load', (event, pilePath) => {
const index = pileIndex.load(pilePath);
return index;
});

ipcMain.handle('index-get', (event) => {
const index = pileIndex.get();
return index;
});

ipcMain.handle('index-add', (event, filePath) => {
const index = pileIndex.add(filePath);
return index;
});

ipcMain.handle('index-remove', (event, filePath) => {
const index = pileIndex.remove(filePath);
return index;
});
14 changes: 14 additions & 0 deletions src/main/handlers/keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ipcMain } from 'electron';
import keytar from 'keytar';

ipcMain.handle('get-ai-key', async () => {
return await keytar.getPassword('pile', 'aikey');
});

ipcMain.handle('set-ai-key', async (event, secretKey) => {
return await keytar.setPassword('pile', 'aikey', secretKey);
});

ipcMain.handle('delete-ai-key', async () => {
return await keytar.deletePassword('pile', 'aikey');
});
29 changes: 29 additions & 0 deletions src/main/handlers/links.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ipcMain } from 'electron';
import pileLinks from '../utils/pileLinks';
import { getLinkPreview, getLinkContent } from '../utils/linkPreview';

ipcMain.handle('links-get', (event, pilePath, url) => {
const data = pileLinks.get(pilePath, url);
return data;
});

ipcMain.handle('links-set', (event, pilePath, url, data) => {
const status = pileLinks.set(pilePath, url, data);
return status;
});

ipcMain.handle('get-link-preview', async (event, url) => {
try {
return await getLinkPreview(url);
} catch {
return null;
}
});

ipcMain.handle('get-link-content', async (event, url) => {
try {
return await getLinkContent(url);
} catch {
return null;
}
});
24 changes: 24 additions & 0 deletions src/main/handlers/tags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ipcMain } from 'electron';
import pileTags from '../utils/pileTags';

ipcMain.handle('tags-load', (event, pilePath) => {
const tags = pileTags.load(pilePath);
return tags;
});

ipcMain.handle('tags-get', (event) => {
const tags = pileTags.get();
return tags;
});

ipcMain.handle('tags-sync', (event, filePath) => {
pileTags.sync(filePath);
});

ipcMain.handle('tags-add', (event, { tag, filePath }) => {
pileTags.add(tag, filePath);
});

ipcMain.handle('tags-remove', (event, { tag, filePath }) => {
pileTags.remove(tag, filePath);
});
26 changes: 26 additions & 0 deletions src/main/handlers/vectorIndex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ipcMain } from 'electron';
import pileVectorIndex from '../utils/pileVectorIndex';

ipcMain.handle('vectorindex-init', (event, pilePath) =>
pileVectorIndex.initialize(pilePath)
);

ipcMain.handle('vectorindex-add', (event, pilePath, entryPath, parentPath) =>
pileVectorIndex.add(pilePath, entryPath, parentPath)
);

ipcMain.handle('vectorindex-get', (event, pilePath) =>
pileVectorIndex.getVectorIndex(pilePath)
);

ipcMain.handle('vectorindex-rebuild', (event, pilePath) =>
pileVectorIndex.rebuildVectorIndex(pilePath)
);

ipcMain.handle('vectorindex-query', (event, text) =>
pileVectorIndex.query(text)
);

ipcMain.handle('vectorindex-retriever', (event, text) =>
pileVectorIndex.query(text)
);
Loading

0 comments on commit 601d252

Please sign in to comment.