-
Notifications
You must be signed in to change notification settings - Fork 0
#50 Enable list submission (PDF upload) #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ff56b43
WIP
ianpaschal 384c0cd
WIP
ianpaschal ac557de
Merge branch 'main' into 50-enable-list-submission
ianpaschal b6eddca
Update getTournamentRegistrationsCsv.ts
ianpaschal 1b16996
Update context menus
ianpaschal 93e79c1
Delete settings.json
ianpaschal a66e654
Update .gitignore
ianpaschal 3b36c86
Update convex/_model/files/actions/getFileDownloadUrl.ts
ianpaschal 45d2538
Update convex/_model/lists/_helpers/checkListSubmittedOnTime.ts
ianpaschal 7ff80e0
Update convex/_model/tournamentCompetitors/_helpers/checkUsersAreTeam…
ianpaschal eb3df80
Update src/components/CommentThread/CommentThread.tsx
ianpaschal cdabe84
Update src/components/FileButton/FileButton.tsx
ianpaschal 79abe27
Update convex/_model/lists/mutations/updateList.ts
ianpaschal 979f423
PR Feedback
ianpaschal fa12424
PR Feedback
ianpaschal f12fe71
PR Feedback & Remove unused <ListProvider/>
ianpaschal a5756c4
Update combat-command-components
ianpaschal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,27 @@ | ||
| import { GenericDatabaseReader } from 'convex/server'; | ||
| import { ConvexError, GenericId } from 'convex/values'; | ||
|
|
||
| import { | ||
| DataModel, | ||
| Doc, | ||
| TableNames, | ||
| } from '../../../_generated/dataModel'; | ||
|
|
||
| /** | ||
| * Fetches a document by ID, throwing a `ConvexError` if it doesn't exist. | ||
| * | ||
| * @param ctx - A context object with a database reader. | ||
| * @param id - The ID of the document to fetch. | ||
| * @returns The document. | ||
| * @throws {ConvexError} If no document exists with the given ID. | ||
| */ | ||
| export const getDocStrict = async <T extends TableNames>( | ||
| ctx: { db: GenericDatabaseReader<DataModel> }, | ||
| id: GenericId<T>, | ||
| ): Promise<Doc<T>> => { | ||
| const doc = await ctx.db.get(id); | ||
| if (!doc) { | ||
| throw new ConvexError({ message: `Document not found: ${id}`, code: 'DOCUMENT_NOT_FOUND' }); | ||
| } | ||
| return doc; | ||
| }; | ||
This file contains hidden or 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,56 @@ | ||
| import { PDFDocument } from '@pdfme/pdf-lib'; | ||
| import { | ||
| ConvexError, | ||
| Infer, | ||
| v, | ||
| } from 'convex/values'; | ||
|
|
||
| import { Id } from '../../../_generated/dataModel'; | ||
| import { ActionCtx } from '../../../_generated/server'; | ||
| import { getErrorMessage } from '../../common/errors'; | ||
|
|
||
| const IMAGE_MIME_TYPES = ['image/png', 'image/jpeg', 'image/jpg'] as const; | ||
ianpaschal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| type ImageMimeType = (typeof IMAGE_MIME_TYPES)[number]; | ||
|
|
||
| const isImageMimeType = (mimeType: string): mimeType is ImageMimeType => (IMAGE_MIME_TYPES as ReadonlyArray<string>).includes(mimeType); | ||
|
|
||
| export const convertImageToPdfArgs = v.object({ | ||
| storageId: v.id('_storage'), | ||
| mimeType: v.string(), | ||
| }); | ||
|
|
||
| export const convertImageToPdf = async ( | ||
| ctx: ActionCtx, | ||
| args: Infer<typeof convertImageToPdfArgs>, | ||
| ): Promise<Id<'_storage'>> => { | ||
| if (!isImageMimeType(args.mimeType)) { | ||
| throw new ConvexError({ message: `Unsupported MIME type: ${args.mimeType}. Expected one of: ${IMAGE_MIME_TYPES.join(', ')}` }); | ||
| } | ||
|
|
||
| const blob = await ctx.storage.get(args.storageId); | ||
| if (!blob) { | ||
| throw new ConvexError(getErrorMessage('FILE_NOT_FOUND')); | ||
| } | ||
ianpaschal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const imageBytes = new Uint8Array(await blob.arrayBuffer()); | ||
| const pdfDoc = await PDFDocument.create(); | ||
|
|
||
| const image = args.mimeType === 'image/png' ? await pdfDoc.embedPng(imageBytes) : await pdfDoc.embedJpg(imageBytes); | ||
|
|
||
| const page = pdfDoc.addPage([image.width, image.height]); | ||
| page.drawImage(image, { | ||
| x: 0, | ||
| y: 0, | ||
| width: image.width, | ||
| height: image.height, | ||
| }); | ||
|
|
||
| const pdfBytes = await pdfDoc.save(); | ||
| const pdfBuffer = pdfBytes.buffer as ArrayBuffer; | ||
| const pdfBlob = new Blob([pdfBuffer], { type: 'application/pdf' }); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const pdfStorageId = await ctx.storage.store(pdfBlob); | ||
|
|
||
| await ctx.storage.delete(args.storageId); | ||
|
|
||
| return pdfStorageId; | ||
| }; | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.