add init demos
This commit is contained in:
		
							
								
								
									
										28
									
								
								server/src/routes/file-code/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								server/src/routes/file-code/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
import { app } from '@/app.ts';
 | 
			
		||||
import path from 'node:path'
 | 
			
		||||
import glob from 'fast-glob';
 | 
			
		||||
import fs from 'node:fs'
 | 
			
		||||
const list = async () => {
 | 
			
		||||
  const root = path.join(process.cwd(), 'code');
 | 
			
		||||
  const files = await glob('**/*.ts', { cwd: root });
 | 
			
		||||
  type FileContent = {
 | 
			
		||||
    path: string;
 | 
			
		||||
    content: string;
 | 
			
		||||
  }
 | 
			
		||||
  const filesContent: FileContent[] = [];
 | 
			
		||||
  for (const file of files) {
 | 
			
		||||
    if (file.startsWith('node_modules') || file.startsWith('dist') || file.startsWith('.git')) continue;
 | 
			
		||||
    const fullPath = path.join(root, file);
 | 
			
		||||
    const content = fs.readFileSync(fullPath, 'utf-8');
 | 
			
		||||
    if (content) {
 | 
			
		||||
      filesContent.push({ path: file, content: content });
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return filesContent;
 | 
			
		||||
}
 | 
			
		||||
app.route({
 | 
			
		||||
  path: 'file-code'
 | 
			
		||||
}).define(async (ctx) => {
 | 
			
		||||
  const files = await list();
 | 
			
		||||
  ctx.body = files
 | 
			
		||||
}).addTo(app);
 | 
			
		||||
		Reference in New Issue
	
	Block a user