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

Function previewPackageHandler

src/cli/registerQuickAddCliHandlers.ts:834–877  ·  view source on GitHub ↗
(
	plugin: QuickAdd,
	params: CliData,
)

Source from the content-addressed store, hash-verified

832}
833
834async function previewPackageHandler(
835 plugin: QuickAdd,
836 params: CliData,
837): Promise<string> {
838 try {
839 const path =
840 typeof params.path === "string" ? params.path.trim() : "";
841 if (!path) {
842 return serialize({
843 ok: false,
844 command: CLI_COMMANDS.preview,
845 error: "Missing package path. Provide path=<vault-path>.",
846 });
847 }
848
849 const { pkg } = await readQuickAddPackage(plugin.app, path);
850 const preview = await analysePackagePreview(
851 plugin.app,
852 plugin.settings.choices,
853 pkg,
854 );
855
856 const response: PackagePreviewCliResponse = {
857 ok: true,
858 command: CLI_COMMANDS.preview,
859 preview,
860 };
861
862 if (isTruthy(params.decode)) {
863 response.contents = preview.files.map((file) => ({
864 path: file.originalPath,
865 ...decodeAssetPreview(pkg, file.originalPath),
866 }));
867 }
868
869 return serialize(response);
870 } catch (error) {
871 return serialize({
872 ok: false,
873 command: CLI_COMMANDS.preview,
874 error: error instanceof Error ? error.message : String(error),
875 });
876 }
877}
878
879export function registerQuickAddCliHandlers(plugin: QuickAdd): boolean {
880 const cliTarget = plugin as unknown as RegisterCliHandlerTarget;

Callers 1

Calls 5

readQuickAddPackageFunction · 0.90
analysePackagePreviewFunction · 0.90
decodeAssetPreviewFunction · 0.90
serializeFunction · 0.85
isTruthyFunction · 0.85

Tested by

no test coverage detected