MCPcopy Index your code
hub / github.com/graphif/project-graph / getFileContent

Method getFileContent

app/src/core/Project.tsx:398–434  ·  view source on GitHub ↗
(options: { includeThumbnail?: boolean } = {})

Source from the content-addressed store, hash-verified

396
397 // 备份也要用到这个
398 async getFileContent(options: { includeThumbnail?: boolean } = {}) {
399 const includeThumbnail = options.includeThumbnail !== false;
400 const serializedStage = serialize(this.stage);
401 const encodedStage = this.encoder.encode(serializedStage);
402 const uwriter = new Uint8ArrayWriter();
403
404 // @zip.js/zip.js 从 ^2.7.63 升到了 ^2.8.26,需要显示指定 level: 0,防止保存的时候卡顿
405 const writer = new ZipWriter(uwriter, { level: 0 });
406 await writer.add("stage.msgpack", new Uint8ArrayReader(encodedStage), { level: 0 });
407 await writer.add("tags.msgpack", new Uint8ArrayReader(this.encoder.encode(this.tags)), { level: 0 });
408 await writer.add("reference.msgpack", new Uint8ArrayReader(this.encoder.encode(this.references)), { level: 0 });
409 await writer.add("metadata.msgpack", new Uint8ArrayReader(this.encoder.encode(this.metadata)), { level: 0 });
410 if (this.readme) {
411 await writer.add("README.md", new Uint8ArrayReader(new TextEncoder().encode(this.readme)), { level: 0 });
412 }
413 // 添加附件
414 for (const [uuid, attachment] of this.attachments.entries()) {
415 await writer.add(`attachments/${uuid}.${mime.getExtension(attachment.type)}`, new BlobReader(attachment), {
416 level: 0,
417 });
418 }
419 // 添加缩略图
420 if (includeThumbnail) {
421 try {
422 const thumbnailBlob = await generateThumbnail(this);
423 if (thumbnailBlob) {
424 await writer.add("thumbnail.png", new BlobReader(thumbnailBlob), { level: 0 });
425 }
426 } catch {
427 // 缩略图生成失败不阻止保存
428 }
429 }
430 await writer.close();
431
432 const fileContent = await uwriter.getData();
433 return fileContent;
434 }
435
436 /**
437 * 备份用:生成项目内容的哈希值,用于检测内容是否发生变化

Callers 3

saveMethod · 0.95
localAutoBackupMethod · 0.80
createBackupFileMethod · 0.80

Calls 5

serializeFunction · 0.90
generateThumbnailFunction · 0.90
entriesMethod · 0.80
closeMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected