-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from sensebox/feat/libraries-api
Feat/libraries api
- Loading branch information
Showing
16 changed files
with
187 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ updates: | |
schedule: | ||
interval: "daily" | ||
assignees: | ||
- "mpfeil" | ||
- "mpfeil" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ yarn-error.log | |
*.bin | ||
*.hex | ||
|
||
ctrf | ||
ctrf | ||
|
||
*.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": false, | ||
"quoteProps": "preserve" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ | |
"program": "${workspaceFolder}/src/index.js" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"reporterEnabled": "spec, mocha-ctrf-json-reporter" | ||
} | ||
"reporterEnabled": "spec, mocha-ctrf-json-reporter" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,65 @@ | ||
const fs = require('fs'); | ||
const { boardBinaryFileextensions } = require('./builder'); | ||
const { HTTPError, rimraf_promise } = require('./utils'); | ||
const fs = require("fs"); | ||
const { boardBinaryFileextensions } = require("./builder"); | ||
const { HTTPError, rimraf_promise } = require("./utils"); | ||
|
||
const readFile = async function readFile ({ id, board }) { | ||
return Promise.resolve(fs.createReadStream(`/tmp/${id}/sketch.ino.${boardBinaryFileextensions[board]}`)); | ||
} | ||
const readFile = async function readFile({ id, board }) { | ||
return Promise.resolve( | ||
fs.createReadStream( | ||
`/tmp/${id}/sketch.ino.${boardBinaryFileextensions[board]}` | ||
) | ||
); | ||
}; | ||
|
||
const downloadHandler = async function downloadHandler (req, res, next) { | ||
if (req.method !== 'GET') { | ||
return next(new HTTPError({ code: 405, error: 'Invalid HTTP method. Only GET requests allowed on /download.' })); | ||
const downloadHandler = async function downloadHandler(req, res, next) { | ||
if (req.method !== "GET") { | ||
return next( | ||
new HTTPError({ | ||
code: 405, | ||
error: "Invalid HTTP method. Only GET requests allowed on /download.", | ||
}) | ||
); | ||
} | ||
|
||
const { id, board } = req._url.query; | ||
|
||
if (!id || !board) { | ||
return next(new HTTPError({ code: 422, error: 'Parameters \'id\' and \'board\' are required' })); | ||
return next( | ||
new HTTPError({ | ||
code: 422, | ||
error: "Parameters 'id' and 'board' are required", | ||
}) | ||
); | ||
} | ||
|
||
// execute builder with parameters from user | ||
try { | ||
const stream = await readFile(req._url.query); | ||
const filename = req._url.query.filename || 'sketch'; | ||
stream.on('error', function (err) { | ||
const filename = req._url.query.filename || "sketch"; | ||
stream.on("error", function (err) { | ||
return next(err); | ||
}); | ||
stream.on('end', async () => { | ||
stream.on("end", async () => { | ||
try { | ||
await rimraf_promise(`/tmp/${req._url.query.id}`) | ||
await rimraf_promise(`/tmp/${req._url.query.id}`); | ||
} catch (error) { | ||
console.log(`Error deleting compile sketch folder with ${req._url.query.id}: `, error); | ||
console.log( | ||
`Error deleting compile sketch folder with ${req._url.query.id}: `, | ||
error | ||
); | ||
} | ||
}); | ||
|
||
res.setHeader('Content-Type', 'application/octet-stream'); | ||
res.setHeader('Content-Disposition', `attachment; filename=${filename}.${boardBinaryFileextensions[req._url.query.board]}`); | ||
res.setHeader("Content-Type", "application/octet-stream"); | ||
res.setHeader( | ||
"Content-Disposition", | ||
`attachment; filename=${filename}.${boardBinaryFileextensions[req._url.query.board]}` | ||
); | ||
stream.pipe(res); | ||
} catch (err) { | ||
return next(new HTTPError({ error: err.message })); | ||
} | ||
} | ||
}; | ||
|
||
module.exports = { | ||
downloadHandler | ||
} | ||
downloadHandler, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.