({ id, githubAccessToken, chapterId })
| 216 | }; |
| 217 | |
| 218 | const 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 | |
| 244 | const syncOneChapterInsideFork = async ({ bookId, chapterId, userGithubToken }) => { |
| 245 | const githubAccessToken = userGithubToken; |
no test coverage detected