-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from UdaraJay/0.8.2
AI search & ask
- Loading branch information
Showing
44 changed files
with
6,907 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); |
Oops, something went wrong.