Skip to content

Commit

Permalink
Add body on cloudsync-mock
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume60240 committed Oct 31, 2024
1 parent 1f32d92 commit 5e3c202
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions e2e-env/cloudsync-mock/src/lib/collector-api.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { Server } from "./server";
import {WsServer} from "./ws-server";
import { WsServer } from "./ws-server";
// @ts-expect-error we don't care about packaging here
import multer from "multer";

const storage = multer.memoryStorage()
const upload = multer({ storage })
const storage = multer.memoryStorage();
const upload = multer({ storage });

export class CollectorApiServer extends Server {
public constructor( probe: WsServer) {
super( probe);
public constructor(probe: WsServer) {
super(probe);

this.api.get("/", (_req, res) => {
res.status(200).end();
});

this.api.post("/upload/:jobid", upload.single('file'), (req, res) => {
this.api.post("/upload/:jobid", upload.single("file"), (req, res) => {
const jobId = req.params.jobid;
if (jobId.startsWith("valid-job-")) {
req.body.file = req.file.buffer.toString()
.split('\n')
.map(line => JSON.parse(line.trim()))
res.status(201).end();
req.body.file = req.file.buffer
.toString()
.split("\n")
.map((line) => JSON.parse(line.trim()));
res.send({ status: "success" }).status(201).end();
} else {
res.status(500).end();
}
Expand Down

0 comments on commit 5e3c202

Please sign in to comment.