MCPcopy Index your code
hub / github.com/FSoft-AI4Code/CodeWiki / serve_generated_docs

Method serve_generated_docs

codewiki/src/fe/routes.py:179–268  ·  view source on GitHub ↗

Serve generated documentation files.

(self, job_id: str, filename: str = "overview.md")

Source from the content-addressed store, hash-verified

177 return RedirectResponse(url=f"/static-docs/{job_id}/", status_code=status.HTTP_302_FOUND)
178
179 async def serve_generated_docs(self, job_id: str, filename: str = "overview.md") -> HTMLResponse:
180 """Serve generated documentation files."""
181 job = self.background_worker.get_job_status(job_id)
182 docs_path = None
183 repo_url = None
184
185 if job:
186 # Job status exists - use it
187 if job.status != 'completed' or not job.docs_path:
188 raise HTTPException(status_code=404, detail="Documentation not available")
189 docs_path = Path(job.docs_path)
190 repo_url = job.repo_url
191 else:
192 # No job status - try to find documentation in cache by job_id
193 # Convert job_id back to repo full name and construct potential paths
194 repo_full_name = self._job_id_to_repo_full_name(job_id)
195 potential_repo_url = f"https://github.com/{repo_full_name}"
196
197 # Check if documentation exists in cache
198 cached_docs = self.cache_manager.get_cached_docs(potential_repo_url)
199 if cached_docs and Path(cached_docs).exists():
200 docs_path = Path(cached_docs)
201 repo_url = potential_repo_url
202
203 # Recreate job status for consistency
204 job = JobStatus(
205 job_id=job_id,
206 repo_url=potential_repo_url,
207 status='completed',
208 created_at=datetime.now(),
209 completed_at=datetime.now(),
210 docs_path=cached_docs,
211 progress="Loaded from cache",
212 commit_id=None # No commit info available from cache
213 )
214 self.background_worker.job_status[job_id] = job
215 self.background_worker.save_job_statuses()
216 else:
217 raise HTTPException(status_code=404, detail="Documentation not found")
218
219 if not docs_path or not docs_path.exists():
220 raise HTTPException(status_code=404, detail="Documentation files not found")
221
222 # Load module tree
223 module_tree = None
224 module_tree_file = docs_path / "module_tree.json"
225 if module_tree_file.exists():
226 try:
227 module_tree = file_manager.load_json(module_tree_file)
228 except Exception:
229 pass
230
231 # Load metadata
232 metadata = None
233 metadata_file = docs_path / "metadata.json"
234 if metadata_file.exists():
235 try:
236 metadata = file_manager.load_json(metadata_file)

Callers 1

serve_generated_docsFunction · 0.80

Calls 10

markdown_to_htmlFunction · 0.85
get_file_titleFunction · 0.85
render_templateFunction · 0.85
get_cached_docsMethod · 0.80
save_job_statusesMethod · 0.80
load_jsonMethod · 0.80
load_textMethod · 0.80
JobStatusClass · 0.70
get_job_statusMethod · 0.45

Tested by

no test coverage detected