(req: express.Request, res: express.Response, next: express.NextFunction)
| 83 | } |
| 84 | |
| 85 | storedCodeHandler(req: express.Request, res: express.Response, next: express.NextFunction) { |
| 86 | const id = unwrapString(req.params.id); |
| 87 | const sessionid = Number.parseInt(unwrapString(req.params.session), 10); |
| 88 | this.storageHandler |
| 89 | .expandId(id) |
| 90 | .then(result => { |
| 91 | const config = JSON.parse(result.config); |
| 92 | |
| 93 | let clientstate: ClientState | null; |
| 94 | if (config.content) { |
| 95 | const normalizer = new ClientStateNormalizer(); |
| 96 | normalizer.fromGoldenLayout(config); |
| 97 | |
| 98 | clientstate = normalizer.normalized; |
| 99 | } else { |
| 100 | clientstate = new ClientState(config); |
| 101 | } |
| 102 | |
| 103 | const session = clientstate.findSessionById(sessionid); |
| 104 | if (!session) throw {msg: `Session ${sessionid} doesn't exist in this shortlink`}; |
| 105 | |
| 106 | res.set('Content-Type', 'text/plain'); |
| 107 | res.send(session.source); |
| 108 | }) |
| 109 | .catch(err => { |
| 110 | logger.debug(`Exception thrown when expanding ${id}: `, err); |
| 111 | logger.warn('Exception value:', err); |
| 112 | SentryCapture(err, 'storedCodeHandler'); |
| 113 | next({ |
| 114 | statusCode: 404, |
| 115 | message: `ID "${id}/${sessionid}" could not be found`, |
| 116 | }); |
| 117 | }); |
| 118 | } |
| 119 | |
| 120 | storedStateHandler(req: express.Request, res: express.Response, next: express.NextFunction) { |
| 121 | const id = unwrapString(req.params.id); |
nothing calls this directly
no test coverage detected