Skip to content

Commit 8479561

Browse files
authored
Merge pull request #162 from sensebox/feat/project-id
feat: add projectId param
2 parents 46f1b2c + 7d259b8 commit 8479561

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM node:22-alpine AS base
22

3-
ENV ARDUINO_CLI_VERSION=1.1.0
3+
ENV ARDUINO_CLI_VERSION=1.3.0
44
ENV SENSEBOXCORE_VERSION=2.0.0
55
ENV ARDUINO_SAMD_VERSION=1.8.13
66
ENV ARDUINO_AVR_VERSION=1.8.5
@@ -138,4 +138,4 @@ COPY splash.h ../root/Arduino/libraries/Adafruit_SSD1306/splash.h
138138

139139
# COPY platform.txt /app/src/arduino-ide/packages/arduino/hardware/samd/1.8.11
140140

141-
CMD ["yarn","start"]
141+
CMD ["yarn","start"]

src/builder.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,21 @@ export const payloadValidator = function payloadValidator(req, res, next) {
7373
next();
7474
};
7575

76-
const execBuilder = async function execBuilder({ board, sketch, buildDir }) {
76+
const execBuilder = async function execBuilder({
77+
board,
78+
projectId,
79+
sketch,
80+
buildDir,
81+
}) {
7782
// const tmpSketchPath = await tempWrite(sketch);
78-
const sketchDir = `${temporaryDirectory()}/sketch`;
79-
mkdirSync(sketchDir);
83+
84+
const sketchDir = projectId
85+
? `/tmp/${projectId}/sketch`
86+
: `${temporaryDirectory()}/sketch`;
87+
88+
mkdirSync(sketchDir, {
89+
recursive: true,
90+
});
8091

8192
const tmpSketchPath = `${sketchDir}/sketch.ino`;
8293
writeFileSync(tmpSketchPath, sketch);
@@ -108,8 +119,17 @@ export const compileHandler = async function compileHandler(req, res, next) {
108119
);
109120
}
110121

111-
const buildDir = temporaryDirectory();
112-
req._builderParams = { buildDir, ...req._builderParams };
122+
// create temporary directory for build
123+
// if projectId is provided, use it as part of the directory name
124+
let buildDir = req.body.projectId
125+
? `/tmp/${req.body.projectId}`
126+
: temporaryDirectory();
127+
128+
req._builderParams = {
129+
buildDir,
130+
projectId: req.body.projectId,
131+
...req._builderParams,
132+
};
113133

114134
// execute builder with parameters from user
115135
try {
@@ -127,7 +147,7 @@ export const compileHandler = async function compileHandler(req, res, next) {
127147
);
128148
} catch (err) {
129149
if (process.env.NODE_ENV === "test") {
130-
console.error(err.message)
150+
console.error(err.message);
131151
}
132152
return next(new HTTPError({ error: err.message }));
133153
}

0 commit comments

Comments
 (0)