MCPcopy
hub / github.com/compiler-explorer/compiler-explorer / storedCodeHandler

Method storedCodeHandler

lib/handlers/route-api.ts:85–118  ·  view source on GitHub ↗
(req: express.Request, res: express.Response, next: express.NextFunction)

Source from the content-addressed store, hash-verified

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);

Callers

nothing calls this directly

Calls 8

fromGoldenLayoutMethod · 0.95
findSessionByIdMethod · 0.80
setMethod · 0.65
unwrapStringFunction · 0.50
SentryCaptureFunction · 0.50
expandIdMethod · 0.45
parseMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected