MCPcopy Create free account
hub / github.com/chhoumann/quickadd / resolveCaptureTarget

Function resolveCaptureTarget

src/engine/helpers/captureTargetResolution.ts:49–129  ·  view source on GitHub ↗
(
	formattedCaptureTo: string,
	deps: CaptureTargetDeps,
)

Source from the content-addressed store, hash-verified

47 * 6) ambiguous => folder if it exists and no same-name file exists; else file
48 */
49export function resolveCaptureTarget(
50 formattedCaptureTo: string,
51 deps: CaptureTargetDeps,
52): CaptureTargetResolution {
53 const rawCaptureTo = formattedCaptureTo.trim().replace(/^\/+/, "");
54
55 if (rawCaptureTo === "") {
56 return { kind: "vault" };
57 }
58
59 // `property:<field>[=<value>]` pre-filters by a frontmatter field (issue #466).
60 // Checked before the `.base`/extension/folder branches so a property value
61 // containing `.md`/`/` (or a trailing `/`) can never misroute to a file/folder.
62 const propertyTarget = parsePropertyTarget(rawCaptureTo);
63 if (propertyTarget) {
64 if (!propertyTarget.field) {
65 throw new ChoiceAbortError(
66 "Property capture target needs a field name, e.g. property:type=draft",
67 );
68 }
69 return {
70 kind: "property",
71 field: propertyTarget.field,
72 value: propertyTarget.value,
73 filter: propertyTarget.filter,
74 };
75 }
76
77 const fileFilterTarget = parseCaptureFileFilterTarget(rawCaptureTo);
78 if (fileFilterTarget) {
79 if (fileFilterTarget.multiSelect) {
80 throw new ChoiceAbortError(
81 "Capture target filters select one destination file. Use {{FILE:...|multi}} in the capture format for multi-value metadata.",
82 );
83 }
84 return {
85 kind: "filter",
86 filter: fileFilterTarget.filter,
87 };
88 }
89
90 const normalizedCaptureTo = normalizeGeneratedFilePath(
91 rawCaptureTo,
92 "Capture target file path",
93 );
94
95 if (BASE_FILE_EXTENSION_REGEX.test(normalizedCaptureTo)) {
96 throw new ChoiceAbortError(
97 `Capture to '.base' files is not supported (${normalizedCaptureTo}). Use a Template choice instead.`,
98 );
99 }
100
101 const endsWithSlash = normalizedCaptureTo.endsWith("/");
102 const folderPath = normalizedCaptureTo.replace(/\/+$/, "");
103
104 if (endsWithSlash) {
105 return { kind: "folder", folder: folderPath };
106 }

Callers 1

Calls 6

parsePropertyTargetFunction · 0.90
getAbstractFileByPathMethod · 0.80
isFolderMethod · 0.65

Tested by

no test coverage detected