Skip to content

Commit

Permalink
added handling of loose notes in local dir
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Dec 20, 2023
1 parent 79d3008 commit e9fe073
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

patreon: xilinota
github: XilinJia
# custom: https://joplinapp.org/donate/
custom: ["https://www.paypal.me/XilinJia"]
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ _vieux/
!var/SymfonyRequirements.php
.DS_Store
.vscode/*
/.directory/
*.map
*.pro.user
*.sublime-workspace
Expand Down Expand Up @@ -48,6 +49,7 @@ TODO.md
packages/tools/commit_hook.txt
packages/tools/github_oauth_token.txt
lerna-debug.log
archive.bash
.env
docs/**/*.mustache
.idea
Expand Down
31 changes: 20 additions & 11 deletions packages/lib/models/LocalFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,13 @@ export default class LocalFile extends BaseItem {
const path_note_map = new Map<string, NoteEntity>();
for (const note of dbNotes) {
const p = await LocalFile.sysPathFromRoot(note);
if (p[0] === '.') continue;
notePaths.add(p);
path_note_map.set(p, note);
// this.logger().info('doDB_FS_Diffs: p', p);
let p1 = p;
if (p.startsWith(`.${path.sep}`)) {
p1 = p.substring(p.indexOf(path.sep) + 1);
}
notePaths.add(p1);
path_note_map.set(p1, note);
}
this.logger().info('doDB_FS_Diffs: DB note path list:', notePaths);

Expand Down Expand Up @@ -448,6 +452,17 @@ export default class LocalFile extends BaseItem {
// for notes in FS but not in DB
const Folder = BaseItem.getClass('Folder');

const addFolder = async (title: string, parent_id: string): Promise<string> => {
const folder = {
title: title,
parent_id: parent_id,
updated_time: time.unixMs(),
};
this.logger().info('addFolders adding in DB', path.basename(title));
const savedFolder: FolderEntity = await Folder.save(folder);
return savedFolder.id;
};

const addFolders = async () => {
for (const dp of dirSet) {
const dList = dp.split(path.sep);
Expand All @@ -470,14 +485,7 @@ export default class LocalFile extends BaseItem {
}
}
if (!exist_) {
const folder = {
title: d,
parent_id: parent_id,
updated_time: time.unixMs(),
};
this.logger().info('addFolders adding in DB', path.basename(d));
const savedFolder: FolderEntity = await Folder.save(folder);
parent_id = savedFolder.id;
parent_id = await addFolder(d, parent_id);
}
parent_path = p_;
}
Expand All @@ -490,6 +498,7 @@ export default class LocalFile extends BaseItem {
// this.logger().info('do_FS_extras: note file stat', stat);
if (!stat) continue;
if (LocalFile.isMDFile(p)) {
// this.logger().info('do_FS_extras: p', p, path.dirname(p));
const filename = path.basename(p);
const title = filename.slice(0, filename.lastIndexOf('.md'));
const tDirFile = `${path.dirname(p)}${path.sep}.dir_props.md`;
Expand Down

0 comments on commit e9fe073

Please sign in to comment.