-
Notifications
You must be signed in to change notification settings - Fork 507
Extending blocknote #518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Extending blocknote #518
Changes from all commits
d1269bc
1a9dfce
62ad58b
6d88c62
ad9638a
b6c8aeb
08007bb
187dab5
ea0e789
99e7611
44d735a
c1b9a31
6dddc7d
14272e1
8387172
64878dd
5f69f60
edc6c6c
428f768
28f2e74
478256f
68df180
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,19 +112,26 @@ export function GetFilesInfoListForListOfPaths(paths: string[]): FileInfo[] { | |
| return fileInfoListWithoutDuplicates | ||
| } | ||
|
|
||
| export function createFileRecursive(filePath: string, content: string, charset?: BufferEncoding): void { | ||
| export function createFileRecursive(filePath: string, content: string, charset?: BufferEncoding): FileInfo | null { | ||
| const dirname = path.dirname(filePath) | ||
|
|
||
| if (!fs.existsSync(dirname)) { | ||
| fs.mkdirSync(dirname, { recursive: true }) | ||
| } | ||
|
|
||
| if (fs.existsSync(filePath)) { | ||
| return | ||
| return null | ||
| } | ||
| const filePathWithExtension = addExtensionToFilenameIfNoExtensionPresent(filePath, markdownExtensions, '.md') | ||
|
|
||
| fs.writeFileSync(filePathWithExtension, content, charset) | ||
| return { | ||
| name: path.basename(filePathWithExtension), | ||
| path: filePathWithExtension, | ||
| relativePath: path.relative(dirname, filePathWithExtension), | ||
| dateModified: new Date(), | ||
| dateCreated: new Date(), | ||
| } | ||
| } | ||
|
|
||
| export function updateFileListForRenderer(win: BrowserWindow, directory: string): void { | ||
|
|
@@ -194,3 +201,26 @@ export function splitDirectoryPathIntoBaseAndRepo(fullPath: string) { | |
|
|
||
| return { localModelPath, repoName } | ||
| } | ||
|
|
||
| export function findFileRecursive(dir: string, filename: string): string | null { | ||
| const files = fs.readdirSync(dir) | ||
| const basename = path.parse(filename).name | ||
|
|
||
| for (const file of files) { | ||
| const fullPath = path.resolve(dir, file) | ||
| const stat = fs.statSync(fullPath) | ||
|
|
||
| if (stat.isDirectory()) { | ||
| const result = findFileRecursive(fullPath, filename) | ||
| if (result) return result | ||
| } else { | ||
| // Check if files match | ||
| const fileName = path.parse(file).name | ||
| if (fileName === basename) { | ||
| return fullPath | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return null | ||
| } | ||
|
Comment on lines
+205
to
+226
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: The recursive file search doesn't handle file extensions, which could lead to incorrect matches when multiple files have the same basename but different extensions. |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,7 +9,7 @@ import { StoreSchema } from '../electron-store/storeConfig' | |||||||||||||||||||||||||||||||||||||||||||||||||
| import { handleFileRename, updateFileInTable } from '../vector-database/tableHelperFunctions' | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| import { GetFilesInfoTree, createFileRecursive, isHidden, GetFilesInfoListForListOfPaths } from './filesystem' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { FileInfoTree, WriteFileProps, RenameFileProps, FileInfoWithContent } from './types' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { FileInfoTree, WriteFileProps, RenameFileProps, FileInfoWithContent, FileInfo } from './types' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import ImageStorage from './storage/ImageStore' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import VideoStorage from './storage/VideoStore' | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -145,8 +145,10 @@ const registerFileHandlers = (store: Store<StoreSchema>, _windowsManager: Window | |||||||||||||||||||||||||||||||||||||||||||||||||
| await updateFileInTable(windowInfo.dbTableClient, filePath) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| ipcMain.handle('create-file', async (event, filePath: string, content: string): Promise<void> => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| createFileRecursive(filePath, content, 'utf-8') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ipcMain.handle('create-file', async (event, filePath: string, content: string): Promise<FileInfo | undefined> => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const fileObject = createFileRecursive(filePath, content, 'utf-8') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (fileObject) return fileObject | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return undefined | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| ipcMain.handle('create-directory', async (event, dirPath: string): Promise<void> => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -217,6 +219,17 @@ const registerFileHandlers = (store: Store<StoreSchema>, _windowsManager: Window | |||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return result.filePaths | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| ipcMain.handle('get-file-info', (event, absolutePath: string, parentRelativePath: string): FileInfo => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const fileInfo = fs.statSync(absolutePath) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| name: path.basename(absolutePath), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| path: absolutePath, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| relativePath: parentRelativePath, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| dateModified: fileInfo.mtime, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| dateCreated: fileInfo.birthtime, // Add the birthtime property here | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+223
to
+232
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: get-file-info doesn't handle errors from fs.statSync which could crash the app. Should use try/catch
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| export default registerFileHandlers | ||||||||||||||||||||||||||||||||||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: The function now returns a FileInfo object with hardcoded dates. Consider using the actual file stats (mtime and birthtime) from fs.statSync() after file creation for accuracy.