Skip to content

Commit

Permalink
Add begin sample file upload endpoint, decouple it from create sample…
Browse files Browse the repository at this point in the history
… file

Signed-off-by: cosa65 <[email protected]>
  • Loading branch information
cosa65 committed Oct 5, 2023
1 parent aebec9e commit 3ee03ab
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 18 deletions.
26 changes: 19 additions & 7 deletions src/api.v2/controllers/sampleFileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const logger = getLogger('[SampleFileController] - ');
const createFile = async (req, res) => {
const {
params: { experimentId, sampleId, sampleFileType },
body: { sampleFileId, size, metadata = {} },
body: { sampleFileId, size },
} = req;
logger.log(`Creating file ${sampleFileType} for sample ${sampleId} in experiment ${experimentId}`);

Expand All @@ -25,19 +25,31 @@ const createFile = async (req, res) => {
upload_status: 'uploading',
};

let uploadUrlParams;


await sqlClient.get().transaction(async (trx) => {
await new SampleFile(trx).create(newSampleFile);
await new Sample(trx).setNewFile(sampleId, sampleFileId, sampleFileType);

logger.log(`Getting multipart upload urls for ${experimentId}, sample ${sampleId}, sampleFileType ${sampleFileType}`);
uploadUrlParams = await getFileUploadUrls(sampleFileId, metadata, size, bucketNames.SAMPLE_FILES);
});


logger.log(`Finished creating sample file for experiment ${experimentId}, sample ${sampleId}, sampleFileType ${sampleFileType}`);
res.json(uploadUrlParams);

res.json(OK());
};

const beginUpload = async (req, res) => {
const {
params: { experimentId, sampleFileId },
body: { metadata, size },
} = req;

logger.log(`Generating multipart upload urls for ${experimentId}, sample file ${sampleFileId}`);
const uploadParams = await getFileUploadUrls(
sampleFileId, metadata, size, bucketNames.SAMPLE_FILES,
);

res.json(uploadParams);
};

const patchFile = async (req, res) => {
Expand Down Expand Up @@ -66,5 +78,5 @@ const getS3DownloadUrl = async (req, res) => {
};

module.exports = {
createFile, patchFile, getS3DownloadUrl,
createFile, beginUpload, patchFile, getS3DownloadUrl,
};
6 changes: 5 additions & 1 deletion src/api.v2/routes/sampleFile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {
createFile, patchFile, getS3DownloadUrl,
createFile, patchFile, getS3DownloadUrl, beginUpload,
} = require('../controllers/sampleFileController');

const { expressAuthorizationMiddleware } = require('../middlewares/authMiddlewares');
Expand All @@ -13,6 +13,10 @@ module.exports = {
expressAuthorizationMiddleware,
(req, res, next) => patchFile(req, res).catch(next),
],
'sampleFile#beginUpload': [
expressAuthorizationMiddleware,
(req, res, next) => beginUpload(req, res).catch(next),
],
'sampleFile#downloadUrl': [
expressAuthorizationMiddleware,
(req, res, next) => getS3DownloadUrl(req, res).catch(next),
Expand Down
73 changes: 72 additions & 1 deletion src/specs/api.v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ paths:
content:
application/json:
schema:
type: object
$ref: "#/components/schemas/HTTPSuccess"
"400":
description: Bad Request
content:
Expand Down Expand Up @@ -1537,6 +1537,75 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/HTTPError"
"/experiments/{experimentId}/sampleFiles/{sampleFileId}/beginUpload":
post:
summary: Begins the multipart upload of a sample file
description: Begins the multipart upload of a sample file
operationId: beginUpload
x-eov-operation-id: sampleFile#beginUpload
x-eov-operation-handler: routes/sampleFile
parameters:
- name: experimentId
required: true
in: path
description: ID of the experiment.
schema:
type: string
- name: sampleFileId
in: path
description: Type of the file.
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/BeginSampleFileUpload"
responses:
"200":
description: Success
content:
application/json:
schema:
type: object
properties:
signedUrls:
type: array
items:
type: string
uploadId:
type: string
"400":
description: Bad Request
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPError"
"401":
description: The request lacks authentication credentials.
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPError"
"403":
description: Forbidden request for this user.
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPError"
"404":
description: Not found error.
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPError"
"424":
description: Terms not accepted error.
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPError"
/completeMultipartUpload:
post:
summary: Complete a multipart upload
Expand Down Expand Up @@ -2481,6 +2550,8 @@ components:
$ref: ./models/samples-bodies/CreateSampleFile.v2.yaml
PatchSampleFile:
$ref: ./models/samples-bodies/PatchSampleFile.v2.yaml
BeginSampleFileUpload:
$ref: ./models/samples-bodies/BeginSampleFileUpload.v2.yaml
UpdateSamplesOptions:
$ref: ./models/samples-bodies/UpdateSamplesOptions.v2.yaml
CellSets:
Expand Down
21 changes: 21 additions & 0 deletions src/specs/models/samples-bodies/BeginSampleFileUpload.v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
title: Begin sample file multipart upload
description: 'Data to begin an s3 multipart upload'
type: object
properties:
size:
type: number
metadata:
description: Metadata to append to the s3 object on upload
type: object
properties:
cellrangerVersion:
type: string
oneOf:
- pattern: v2
- pattern: v3

required:
- size
- metadata

additionalProperties: false
9 changes: 0 additions & 9 deletions src/specs/models/samples-bodies/CreateSampleFile.v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ properties:
type: string
size:
type: number
metadata:
description: Metadata to append to the s3 object on upload
type: object
properties:
cellrangerVersion:
type: string
oneOf:
- pattern: v2
- pattern: v3

required:
- sampleFileId
Expand Down

0 comments on commit 3ee03ab

Please sign in to comment.