-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e2878b
commit a0ebad9
Showing
12 changed files
with
204 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { consumePolygonUploadSession, consumeUploadSession, uploadTestcase } from '../services/testcase.services.js' | ||
import { uploadPolygon } from '../services/polygon.services.js' | ||
|
||
import { Type } from '@sinclair/typebox' | ||
import multipart, { type MultipartFile } from '@fastify/multipart' | ||
import { type FastifyTypeBox } from '../types.js' /*=*/ | ||
import { BadRequestError, badRequestSchema, PayloadTooLargeError, unauthorizedSchema } from 'http-errors-enhanced' | ||
|
||
export async function polygonRoutes (routes: FastifyTypeBox): Promise<void> { | ||
await routes.register(multipart.default, { | ||
limits: { | ||
fileSize: 20971520, | ||
files: 1 | ||
} | ||
}) | ||
|
||
/** | ||
* Uploads a zipped Polygon package. | ||
* Unzips and parses the package, and update the problem. | ||
*/ | ||
routes.post( | ||
'/:uploadId', | ||
{ | ||
schema: { | ||
params: Type.Object({ uploadId: Type.String() }), | ||
response: { | ||
201: Type.Object({ problemId: Type.String() }), | ||
400: badRequestSchema, | ||
401: unauthorizedSchema, | ||
413: Type.Object({ statusCode: Type.Number(), error: Type.String(), message: Type.String() }) | ||
} | ||
} | ||
}, | ||
async (request, reply) => { | ||
const { uploadId } = request.params | ||
const { domainId } = await consumePolygonUploadSession(uploadId) | ||
|
||
try { | ||
const archive: MultipartFile | undefined = await request.file() | ||
if (archive === undefined) { | ||
throw new BadRequestError('No file found in request') | ||
} | ||
|
||
const problemId = await uploadPolygon({ domainId, archive }) | ||
|
||
return await reply.status(201).send({ problemId }) | ||
} catch (err) { | ||
if (err instanceof routes.multipartErrors.InvalidMultipartContentTypeError) { | ||
throw new BadRequestError('Request must be multipart') | ||
} else if (err instanceof routes.multipartErrors.FilesLimitError) { | ||
throw new PayloadTooLargeError('Too many files in one request') | ||
} else if (err instanceof routes.multipartErrors.RequestFileTooLargeError) { | ||
throw new PayloadTooLargeError('Testcase too large to be processed') | ||
} else { | ||
throw err | ||
} | ||
} | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.