fix: recurse for indexed items properly
This commit is contained in:
parent
e46f9cefb7
commit
8f70191586
3 changed files with 103 additions and 54 deletions
|
|
@ -7,6 +7,7 @@ import * as fs from '@std/fs';
|
|||
import { FSDB_INDEXER, FSDB_SEARCH_OPTIONS } from '../fsdb.ts';
|
||||
import * as path from '@std/path';
|
||||
import sanitize from '../utils/sanitize.ts';
|
||||
import { walk, WALK_ENTRY } from '../utils/walk.ts';
|
||||
|
||||
interface FSDB_INDEXER_SYMLINKS_CONFIG_SHARED {
|
||||
name: string;
|
||||
|
|
@ -14,7 +15,7 @@ interface FSDB_INDEXER_SYMLINKS_CONFIG_SHARED {
|
|||
id_field?: string;
|
||||
to_many?: boolean;
|
||||
organize?: (value: string) => string[];
|
||||
organize_id?: (value: string) => string[];
|
||||
organize_id?: (value: string, organized: string) => string[];
|
||||
}
|
||||
|
||||
interface FSDB_INDEXER_SYMLINKS_CONFIG_WITH_FIELD extends FSDB_INDEXER_SYMLINKS_CONFIG_SHARED {
|
||||
|
|
@ -93,7 +94,6 @@ export class FSDB_INDEXER_SYMLINKS<T> implements FSDB_INDEXER<T> {
|
|||
const filename: string = organized_paths.pop() ?? ''; // remove filename
|
||||
const parsed_filename = path.parse(filename);
|
||||
organized_paths.push(parsed_filename.name); // add back filename without extension for a directory
|
||||
organized_paths.push('*'); // wildcard to get all references
|
||||
}
|
||||
|
||||
const limit = options?.limit ?? 100;
|
||||
|
|
@ -109,20 +109,37 @@ export class FSDB_INDEXER_SYMLINKS<T> implements FSDB_INDEXER<T> {
|
|||
});
|
||||
}
|
||||
|
||||
const glob_pattern = path.resolve(path.join(this.config.root, ...organized_paths));
|
||||
for await (const item_file of fs.expandGlob(glob_pattern)) {
|
||||
const file_info: Deno.FileInfo = await Deno.lstat(item_file.path);
|
||||
const resolved_path = path.resolve(path.join(this.config.root, ...organized_paths));
|
||||
for await (
|
||||
const entry of walk(resolved_path, {
|
||||
filter: (entry: WALK_ENTRY<T>): boolean => {
|
||||
const extension = path.extname(entry.path);
|
||||
if (extension.toLowerCase() !== '.json') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entry.info.isDirectory) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
sort: options?.sort
|
||||
})
|
||||
) {
|
||||
const file_info: Deno.FileInfo = await Deno.lstat(entry.path);
|
||||
if (file_info.isSymlink) {
|
||||
if (counter < offset) {
|
||||
++counter;
|
||||
continue;
|
||||
}
|
||||
|
||||
const resolved_item_path = await Deno.readLink(item_file.path);
|
||||
const normalized_path = path.normalize(path.resolve(path.dirname(item_file.path), resolved_item_path));
|
||||
const resolved_item_path = await Deno.readLink(entry.path);
|
||||
const normalized_path = path.normalize(path.resolve(path.dirname(entry.path), resolved_item_path));
|
||||
|
||||
if (Deno.env.get('FSDB_DEBUG')) {
|
||||
console.dir({
|
||||
entry,
|
||||
resolved_item_path,
|
||||
normalized_path
|
||||
});
|
||||
|
|
@ -211,7 +228,7 @@ export class FSDB_INDEXER_SYMLINKS<T> implements FSDB_INDEXER<T> {
|
|||
}
|
||||
|
||||
if (this.config.organize_id) {
|
||||
organized_paths.push(...this.config.organize_id(item_id));
|
||||
organized_paths.push(...this.config.organize_id(item_id, parsed_filename.name));
|
||||
} else {
|
||||
organized_paths.push(`${item_id}.json`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue