MCPcopy Create free account
hub / github.com/async-labs/builderbook / syncOneChapter

Function syncOneChapter

server/api/sync-one-inside-fork.js:218–242  ·  view source on GitHub ↗
({ id, githubAccessToken, chapterId })

Source from the content-addressed store, hash-verified

216};
217
218const syncOneChapter = async ({ id, githubAccessToken, chapterId }) => {
219 const book = await Book.findById(id, 'userId githubRepo').lean();
220
221 const chapter = await Chapter.findById(chapterId, 'githubFilePath').lean();
222
223 if (!book) {
224 throw new Error('Not found');
225 }
226
227 const chapterContent = await getContent({
228 accessToken: githubAccessToken,
229 repoName: book.githubRepo,
230 path: chapter.githubFilePath,
231 });
232
233 const data = frontmatter(Buffer.from(chapterContent.data.content, 'base64').toString('utf8'));
234 data.path = chapter.githubFilePath;
235
236 try {
237 await syncContent({ book, data });
238 logger.info('Content is synced', { path: chapter.githubFilePath });
239 } catch (error) {
240 logger.info('Content sync has error', { path: chapter.githubFilePath, error });
241 }
242};
243
244const syncOneChapterInsideFork = async ({ bookId, chapterId, userGithubToken }) => {
245 const githubAccessToken = userGithubToken;

Callers 1

syncOneChapterInsideForkFunction · 0.70

Calls 2

syncContentFunction · 0.70
getContentFunction · 0.50

Tested by

no test coverage detected