Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang committed Dec 18, 2023
1 parent 6ae1896 commit af87928
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
34 changes: 34 additions & 0 deletions packages/canyon-backend/src/upload/helpers/uploadAnalyze.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function extractFileContents(inputString) {
const regex = /# path=(.*)\n([\s\S]*?)<<<<<< EOF/g;
const fileContents = [];
let match;

while ((match = regex.exec(inputString)) !== null) {
const [, filePath, fileContent] = match;
fileContents.push({ filePath, fileContent });
}

return fileContents;
}
// safeJSONParse
export function safeJSONParse(jsonString) {
try {
return JSON.parse(jsonString);
} catch (e) {
return null;
}
}
export function uploadAnalyze(filecontent) {
const [filenameList, filecontentList] = filecontent.split('<<<<<< network');
const filenameListFinal = filenameList.split('\n').filter((item) => item);
const filecontentListFinal = extractFileContents(filecontentList);
return {
type: 'javascript',
coverage: safeJSONParse(
filecontentListFinal.find((item) => {
return item.filePath.includes('coverage/coverage-final.json');
})['fileContent'],
),
filenameList: filenameListFinal,
};
}
8 changes: 4 additions & 4 deletions packages/canyon-backend/src/upload/upload.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
Body,
UseInterceptors,
} from '@nestjs/common';
import * as fs from 'fs';
import { RawBodyMiddleware } from './raw-body.middleware';
import { uploadAnalyze } from './helpers/uploadAnalyze';

@Controller('upload')
export class UploadController {
Expand All @@ -25,8 +25,8 @@ export class UploadController {
@HttpCode(200)
@UseInterceptors(RawBodyMiddleware)
test1(@Query() q, @Body() buffer: Buffer) {
console.log(q);
fs.writeFileSync('./test.txt', buffer);
return 'test';
const cov = uploadAnalyze(buffer.toString());
console.log(cov, 'cov');
return cov;
}
}
2 changes: 1 addition & 1 deletion packages/canyon-cli/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
debug

npm run build && node ./dist/bin/canyon.js --url http://localhost:8080
node ~/Desktop/github/canyon-project/canyon/packages/canyon-cli/dist/bin/canyon.js --url http://localhost:8080

0 comments on commit af87928

Please sign in to comment.