Skip to content

Commit cf82784

Browse files
committed
lsp
1 parent cb2090d commit cf82784

File tree

5 files changed

+84
-38
lines changed

5 files changed

+84
-38
lines changed

src/config/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export const memoryLimit = 256; // in megabytes
2-
export const timeLimit = 5000; // in milliseconds
1+
export const memoryLimit = 512; // in megabytes
2+
export const timeLimit = 50000; // in milliseconds

src/tracers/LspTracer.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import AWS from 'aws-sdk';
2+
import express from 'express';
3+
import { Release, Tracer } from 'tracers/Tracer';
4+
import { awsAccessKeyId, awsSecretAccessKey } from 'config/environments';
5+
import { BadRequest } from 'ts-httpexceptions';
6+
7+
export class LspTracer extends Tracer {
8+
static lambda = new AWS.Lambda({
9+
region: 'us-east-2',
10+
accessKeyId: awsAccessKeyId,
11+
secretAccessKey: awsSecretAccessKey,
12+
});
13+
14+
async build(release: Release) {
15+
}
16+
17+
route(router: express.Router) {
18+
router.post(`/${this.lang}`, (req, res, next) => {
19+
const {code} = req.body;
20+
LspTracer.lambda.invoke({
21+
FunctionName: `extractor-${this.lang}`,
22+
InvocationType: 'RequestResponse',
23+
Payload: JSON.stringify(code),
24+
}, function (err, data) {
25+
if (err) return next(err);
26+
if (typeof data.Payload !== 'string') return next(new Error('Unexpected Payload Type'));
27+
const payload = JSON.parse(data.Payload);
28+
if (!payload.success) return next(new BadRequest(payload.errorMessage));
29+
res.send(payload.commands);
30+
});
31+
});
32+
}
33+
}

src/tracers/RunTracer.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import path from 'path';
2+
import { Release, Tracer } from 'tracers/Tracer';
3+
import express from 'express';
4+
import uuid from 'uuid';
5+
import fs from 'fs-extra';
6+
import { memoryLimit, timeLimit } from 'config/constants';
7+
import { codesDir } from 'config/paths';
8+
import { execute } from 'utils/misc';
9+
10+
export class RunTracer extends Tracer {
11+
private readonly directory: string;
12+
13+
constructor(lang: string) {
14+
super(lang);
15+
this.directory = path.resolve(__dirname, lang);
16+
}
17+
18+
async build(release: Release) {
19+
const {tag_name} = release;
20+
}
21+
22+
route(router: express.Router) {
23+
router.post(`/${this.lang}`, (req, res, next) => {
24+
const {code} = req.body;
25+
const tempPath = path.resolve(codesDir, uuid.v4());
26+
fs.outputFile(path.resolve(tempPath, `Main.${this.lang}`), code)
27+
.then(() => {
28+
return execute([
29+
'julia',
30+
`${tempPath}`,
31+
].join(' ')).then((data) => {
32+
//const payload = JSON.parse(data.Payload);
33+
//if (!payload.success) return next(new BadRequest(payload.errorMessage));
34+
//res.send(payload.commands);
35+
res.send(data);
36+
}).catch(error => {
37+
throw error;
38+
}).finally(() => {});
39+
})
40+
.catch(next)
41+
.finally(() => fs.remove(tempPath));
42+
});
43+
}
44+
}

src/tracers/julia/JuliaTracer.ts

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
1-
import path from 'path';
2-
import { Release, Tracer } from 'tracers/Tracer';
3-
import express from 'express';
4-
import { GitHubApi } from 'utils/apis';
1+
//import { LspTracer } from 'tracers/LspTracer';
2+
import { RunTracer as LspTracer } from 'tracers/RunTracer';
53

6-
export class JuliaTracer extends Tracer {
7-
readonly workerPath: string;
8-
tagName?: string;
4+
import { Release } from 'tracers/Tracer';
5+
import { GitHubApi } from 'utils/apis';
96

7+
export class JuliaTracer extends LspTracer {
108
constructor() {
119
super('julia');
12-
this.workerPath = path.resolve(__dirname, 'worker.js');
13-
}
14-
15-
async build(release: Release) {
16-
const {tag_name} = release;
17-
this.tagName = tag_name;
18-
}
19-
20-
route(router: express.Router) {
21-
router.get(`/${this.lang}`, (req, res) => {
22-
if (!this.tagName) throw new Error('JuliaTracer has not been built yet.');
23-
const version = this.tagName.slice(1);
24-
res.redirect(`https://unpkg.com/algorithm-visualizer@${version}/dist/algorithm-visualizer.umd.js`);
25-
});
26-
router.get(`/${this.lang}/worker`, (req, res) => res.sendFile(this.workerPath));
2710
}
2811

2912
async update(release?: Release) {

src/tracers/julia/worker.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy