MCPcopy Create free account
hub / github.com/compiler-explorer/compiler-explorer / storedStateHandler

Method storedStateHandler

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

Source from the content-addressed store, hash-verified

118 }
119
120 storedStateHandler(req: express.Request, res: express.Response, next: express.NextFunction) {
121 const id = unwrapString(req.params.id);
122 this.storageHandler
123 .expandId(id)
124 .then(result => {
125 let config = JSON.parse(result.config);
126 if (config.sessions) {
127 config = this.getGoldenLayoutFromClientState(new ClientState(config));
128 }
129 const metadata = this.getMetaDataFromLink(req, result, config);
130 this.renderGoldenLayout(config, metadata, req, res);
131 // And finally, increment the view count
132 // If any errors pop up, they are just logged, but the response should still be valid
133 // It's really unlikely that it happens as a result of the id not being there though,
134 // but can be triggered with a missing implementation for a derived storage (s3/local...)
135 this.storageHandler.incrementViewCount(id).catch(err => {
136 logger.error(`Error incrementing view counts for ${id} - ${err}`);
137 });
138 })
139 .catch(err => {
140 logger.warn(`Could not expand ${id}: ${err}`);
141 next({
142 statusCode: 404,
143 message: `ID "${id}" could not be found`,
144 });
145 });
146 }
147
148 getGoldenLayoutFromClientState(state: ClientState) {
149 const goldenifier = new ClientStateGoldenifier();

Callers 1

unfurl-tests.tsFile · 0.80

Calls 7

getMetaDataFromLinkMethod · 0.95
errorMethod · 0.80
unwrapStringFunction · 0.50
expandIdMethod · 0.45
parseMethod · 0.45
incrementViewCountMethod · 0.45

Tested by

no test coverage detected