diff --git a/src/tracers/js/JsTracer.ts b/src/tracers/js/JsTracer.ts index b253a92..3ab18a5 100644 --- a/src/tracers/js/JsTracer.ts +++ b/src/tracers/js/JsTracer.ts @@ -1,26 +1,27 @@ import path from 'path'; -import { download } from 'utils/misc'; import { Release, Tracer } from 'tracers/Tracer'; import express from 'express'; -import { publicDir } from 'config/paths'; export class JsTracer extends Tracer { - readonly tracerPath: string; readonly workerPath: string; + tagName?: string; constructor() { super('js'); - this.tracerPath = path.resolve(publicDir, 'algorithm-visualizer.js'); this.workerPath = path.resolve(__dirname, 'worker.js'); } - build(release: Release) { + async build(release: Release) { const {tag_name} = release; - return download(`https://github.com/algorithm-visualizer/tracers.js/releases/download/${tag_name}/algorithm-visualizer.js`, this.tracerPath); + this.tagName = tag_name; } route(router: express.Router) { - router.get(`/${this.lang}`, (req, res) => res.sendFile(this.tracerPath)); + router.get(`/${this.lang}`, (req, res) => { + if (!this.tagName) throw new Error('JsTracer has not been built yet.'); + const version = this.tagName.slice(1); + res.redirect(`https://unpkg.com/algorithm-visualizer@${version}/dist/index.umd.js`); + }); router.get(`/${this.lang}/worker`, (req, res) => res.sendFile(this.workerPath)); } }