|
1 | 1 | import path from 'path';
|
2 |
| -import { download } from 'utils/misc'; |
3 | 2 | import { Release, Tracer } from 'tracers/Tracer';
|
4 | 3 | import express from 'express';
|
5 |
| -import { publicDir } from 'config/paths'; |
6 | 4 |
|
7 | 5 | export class JsTracer extends Tracer {
|
8 |
| - readonly tracerPath: string; |
9 | 6 | readonly workerPath: string;
|
| 7 | + tagName?: string; |
10 | 8 |
|
11 | 9 | constructor() {
|
12 | 10 | super('js');
|
13 |
| - this.tracerPath = path.resolve(publicDir, 'algorithm-visualizer.js'); |
14 | 11 | this.workerPath = path.resolve(__dirname, 'worker.js');
|
15 | 12 | }
|
16 | 13 |
|
17 |
| - build(release: Release) { |
| 14 | + async build(release: Release) { |
18 | 15 | const {tag_name} = release;
|
19 |
| - return download(`https://github.com/algorithm-visualizer/tracers.js/releases/download/${tag_name}/algorithm-visualizer.js`, this.tracerPath); |
| 16 | + this.tagName = tag_name; |
20 | 17 | }
|
21 | 18 |
|
22 | 19 | route(router: express.Router) {
|
23 |
| - router.get(`/${this.lang}`, (req, res) => res.sendFile(this.tracerPath)); |
| 20 | + router.get(`/${this.lang}`, (req, res) => { |
| 21 | + if (!this.tagName) throw new Error('JsTracer has not been built yet.'); |
| 22 | + const version = this.tagName.slice(1); |
| 23 | + res.redirect(`https://unpkg.com/algorithm-visualizer@${version}/dist/index.umd.js`); |
| 24 | + }); |
24 | 25 | router.get(`/${this.lang}/worker`, (req, res) => res.sendFile(this.workerPath));
|
25 | 26 | }
|
26 | 27 | }
|
0 commit comments