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

Function decodeAssetPreview

src/services/packagePreview.ts:998–1036  ·  view source on GitHub ↗
(
	pkg: QuickAddPackage,
	originalPath: string,
)

Source from the content-addressed store, hash-verified

996 * when the user expands a file, never during initial analysis.
997 */
998export function decodeAssetPreview(
999 pkg: QuickAddPackage,
1000 originalPath: string,
1001): AssetPreviewContent {
1002 const asset = pkg.assets.find((a) => a.originalPath === originalPath);
1003 if (!asset) {
1004 return {
1005 found: false,
1006 text: "",
1007 truncated: false,
1008 sizeBytes: 0,
1009 looksMinified: false,
1010 error: "File is not bundled in this package.",
1011 };
1012 }
1013
1014 try {
1015 const decoded = decodeFromBase64(asset.content);
1016 const truncated = decoded.length > MAX_PREVIEW_CHARS;
1017 const text = truncated ? decoded.slice(0, MAX_PREVIEW_CHARS) : decoded;
1018 return {
1019 found: true,
1020 text,
1021 truncated,
1022 sizeBytes: byteLength(decoded),
1023 // Scan only the previewed slice — enough to spot minification.
1024 looksMinified: looksMinified(text),
1025 };
1026 } catch (error) {
1027 return {
1028 found: true,
1029 text: "",
1030 truncated: false,
1031 sizeBytes: 0,
1032 looksMinified: false,
1033 error: error instanceof Error ? error.message : String(error),
1034 };
1035 }
1036}
1037
1038/** A package needs explicit acknowledgement when it has any critical capability. */
1039export function requiresAcknowledgement(preview: PackagePreview): boolean {

Callers 3

previewPackageHandlerFunction · 0.90

Calls 3

decodeFromBase64Function · 0.90
looksMinifiedFunction · 0.85
byteLengthFunction · 0.70

Tested by

no test coverage detected