mirror of
https://github.com/engineer-man/piston.git
synced 2025-04-20 20:16:26 +02:00
Support for uploading files in base64/hex format
This commit is contained in:
parent
8a89af7512
commit
24a352699d
3 changed files with 13 additions and 7 deletions
|
@ -16,12 +16,12 @@ const job_states = {
|
|||
let uid = 0;
|
||||
let gid = 0;
|
||||
|
||||
let remainingJobSpaces = config.max_concurrent_jobs;
|
||||
let remaining_job_spaces = config.max_concurrent_jobs;
|
||||
let jobQueue = [];
|
||||
|
||||
setInterval(() => {
|
||||
// Every 10ms try resolve a new job, if there is an available slot
|
||||
if (jobQueue.length > 0 && remainingJobSpaces > 0) {
|
||||
if (jobQueue.length > 0 && remaining_job_spaces > 0) {
|
||||
jobQueue.shift()();
|
||||
}
|
||||
}, 10);
|
||||
|
@ -33,6 +33,9 @@ class Job {
|
|||
this.files = files.map((file, i) => ({
|
||||
name: file.name || `file${i}.code`,
|
||||
content: file.content,
|
||||
encoding: ['base64', 'hex', 'utf8'].includes(file.encoding)
|
||||
? file.encoding
|
||||
: 'utf8',
|
||||
}));
|
||||
|
||||
this.args = args;
|
||||
|
@ -59,7 +62,7 @@ class Job {
|
|||
}
|
||||
|
||||
async prime() {
|
||||
if (remainingJobSpaces < 1) {
|
||||
if (remaining_job_spaces < 1) {
|
||||
logger.info(`Awaiting job slot uuid=${this.uuid}`);
|
||||
await new Promise(resolve => {
|
||||
jobQueue.push(resolve);
|
||||
|
@ -67,7 +70,7 @@ class Job {
|
|||
}
|
||||
|
||||
logger.info(`Priming job uuid=${this.uuid}`);
|
||||
remainingJobSpaces--;
|
||||
remaining_job_spaces--;
|
||||
logger.debug('Writing files to job cache');
|
||||
|
||||
logger.debug(`Transfering ownership uid=${this.uid} gid=${this.gid}`);
|
||||
|
@ -76,8 +79,9 @@ class Job {
|
|||
await fs.chown(this.dir, this.uid, this.gid);
|
||||
|
||||
for (const file of this.files) {
|
||||
let file_path = path.join(this.dir, file.name);
|
||||
const file_path = path.join(this.dir, file.name);
|
||||
const rel = path.relative(this.dir, file_path);
|
||||
const file_content = Buffer.from(file.content, file.encoding);
|
||||
|
||||
if (rel.startsWith('..'))
|
||||
throw Error(
|
||||
|
@ -90,7 +94,7 @@ class Job {
|
|||
});
|
||||
await fs.chown(path.dirname(file_path), this.uid, this.gid);
|
||||
|
||||
await fs.write_file(file_path, file.content);
|
||||
await fs.write_file(file_path, file_content);
|
||||
await fs.chown(file_path, this.uid, this.gid);
|
||||
}
|
||||
|
||||
|
@ -387,7 +391,7 @@ class Job {
|
|||
|
||||
await this.cleanup_filesystem();
|
||||
|
||||
remainingJobSpaces++;
|
||||
remaining_job_spaces++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue