-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from safeinsights/file-drop
Replace container push screen with file upload
- Loading branch information
Showing
24 changed files
with
5,810 additions
and
5,416 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,47 @@ | ||
import { db } from '@/database' | ||
import { NextResponse } from 'next/server' | ||
import { PROD_ENV } from '@/server/config' | ||
import { getUploadTmpDirectory } from '@/server/config' | ||
import { pathForStudyRunCode } from '@/lib/paths' | ||
import path from 'path' | ||
import fs from 'fs' | ||
|
||
export const dynamic = 'force-dynamic' // defaults to auto | ||
|
||
export async function POST(req: Request, { params }: { params: Promise<{ studyRunIdentifier: string }> }) { | ||
const { studyRunIdentifier } = await params | ||
if (PROD_ENV) { | ||
return NextResponse.json({ error: 'This route is only available in development' }, { status: 403 }) | ||
} | ||
|
||
const info = await db | ||
.selectFrom('studyRun') | ||
.innerJoin('study', 'study.id', 'studyRun.studyId') | ||
.innerJoin('member', 'member.id', 'study.memberId') | ||
.select(['studyRun.id as studyRunId', 'studyId', 'member.identifier as memberIdentifier']) | ||
.where('studyRun.id', '=', studyRunIdentifier) | ||
.executeTakeFirst() | ||
|
||
if (!info) { | ||
return NextResponse.json({ status: 'fail', error: 'run not found' }, { status: 404 }) | ||
} | ||
|
||
const formData = await req.formData() | ||
const file = formData.get('file') as File | ||
|
||
const dir = path.join(getUploadTmpDirectory(), pathForStudyRunCode(info), path.dirname(file.name)) | ||
fs.mkdirSync(dir, { recursive: true }) | ||
const filePath = path.join(dir, path.basename(file.name)) | ||
const buffer = await file.arrayBuffer() | ||
await fs.promises.writeFile(filePath, Buffer.from(buffer)) | ||
|
||
await db | ||
.updateTable('studyRun') | ||
.set({ | ||
status: 'CODE-SUBMITTED', | ||
}) | ||
.where('id', '=', info.studyRunId) | ||
.executeTakeFirstOrThrow() | ||
|
||
return new NextResponse('ok', { status: 200 }) | ||
} |
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
Empty file.
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
Oops, something went wrong.