Skip to content

Commit ed192b9

Browse files
committed
Playground API - retrieveSample
1 parent 533da0c commit ed192b9

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

playground-api/handler.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,45 @@ async function retrieveResult(request: HttpRequest): Promise<HttpResponse> {
294294
}
295295
}
296296

297+
async function retrieveSample(request: HttpRequest): Promise<HttpResponse> {
298+
try {
299+
const id = request.queryStringParameters.id;
300+
const object = await s3.getObject({
301+
Bucket: 'phpstan-playground',
302+
Key: 'api/results/' + id + '.json',
303+
}).promise();
304+
const json = JSON.parse(object.Body as string);
305+
const strictRules = typeof json.config.strictRules !== 'undefined' ? json.config.strictRules : false;
306+
const bleedingEdge = typeof json.config.bleedingEdge !== 'undefined' ? json.config.bleedingEdge : false;
307+
const treatPhpDocTypesAsCertain = typeof json.config.treatPhpDocTypesAsCertain !== 'undefined' ? json.config.treatPhpDocTypesAsCertain : true;
308+
309+
const bodyJson: any = {
310+
code: json.code,
311+
errors: json.errors,
312+
version: json.version,
313+
level: json.level,
314+
config: {
315+
strictRules,
316+
bleedingEdge,
317+
treatPhpDocTypesAsCertain,
318+
},
319+
};
320+
if (typeof json.versionedErrors !== 'undefined') {
321+
bodyJson.versionedErrors = json.versionedErrors;
322+
} else {
323+
bodyJson.versionedErrors = [{errors: json.errors, title: 'PHP 7.4'}];
324+
}
325+
return Promise.resolve({
326+
statusCode: 200,
327+
body: JSON.stringify(bodyJson),
328+
});
329+
} catch (e) {
330+
console.error(e);
331+
captureException(e);
332+
return Promise.resolve({statusCode: 500});
333+
}
334+
}
335+
297336
async function retrieveLegacyResult(request: HttpRequest): Promise<HttpResponse> {
298337
try {
299338
const id = request.queryStringParameters.id;
@@ -343,5 +382,6 @@ const corsMiddleware = cors();
343382
module.exports = {
344383
analyseResult: middy(analyseResult).use(corsMiddleware),
345384
retrieveResult: middy(retrieveResult).use(corsMiddleware),
385+
retrieveSample: middy(retrieveSample).use(corsMiddleware),
346386
retrieveLegacyResult: middy(retrieveLegacyResult).use(corsMiddleware),
347387
};

playground-api/serverless.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ functions:
2929
path: /result
3030
cors: true
3131

32+
retrieveSample:
33+
handler: handler.retrieveSample
34+
role: arn:aws:iam::928192134594:role/lambda-phpstan-playground
35+
events:
36+
- http:
37+
method: get
38+
path: /sample
39+
cors: true
40+
3241
retrieveLegacyResult:
3342
handler: handler.retrieveLegacyResult
3443
role: arn:aws:iam::928192134594:role/lambda-phpstan-playground

0 commit comments

Comments
 (0)