-
Notifications
You must be signed in to change notification settings - Fork 33
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
vod: specify content-length when creating presigned urls #1921
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -508,12 +508,17 @@ async function genUploadUrl( | |||||||||||||||||||||||||||
playbackId: string, | ||||||||||||||||||||||||||||
objectStoreId: string, | ||||||||||||||||||||||||||||
jwtSecret: string, | ||||||||||||||||||||||||||||
aud: string | ||||||||||||||||||||||||||||
aud: string, | ||||||||||||||||||||||||||||
contentLength?: number | ||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||
const uploadedObjectKey = `directUpload/${playbackId}`; | ||||||||||||||||||||||||||||
const os = await getActiveObjectStore(objectStoreId); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const presignedUrl = await getS3PresignedUrl(os, uploadedObjectKey); | ||||||||||||||||||||||||||||
const presignedUrl = await getS3PresignedUrl( | ||||||||||||||||||||||||||||
os, | ||||||||||||||||||||||||||||
uploadedObjectKey, | ||||||||||||||||||||||||||||
contentLength | ||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||
const uploadToken = jwt.sign({ playbackId, presignedUrl, aud }, jwtSecret, { | ||||||||||||||||||||||||||||
algorithm: "HS256", | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
|
@@ -877,7 +882,8 @@ app.post( | |||||||||||||||||||||||||||
playbackId, | ||||||||||||||||||||||||||||
vodObjectStoreId, | ||||||||||||||||||||||||||||
jwtSecret, | ||||||||||||||||||||||||||||
jwtAudience | ||||||||||||||||||||||||||||
jwtAudience, | ||||||||||||||||||||||||||||
req.body.contentLength | ||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const ingests = await req.getIngest(); | ||||||||||||||||||||||||||||
|
@@ -1049,7 +1055,6 @@ app.put("/upload/direct", async (req, res) => { | |||||||||||||||||||||||||||
jwtSecret, | ||||||||||||||||||||||||||||
jwtAudience | ||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// ensure upload exists and is pending | ||||||||||||||||||||||||||||
await getPendingAssetAndTask(playbackId); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
@@ -1064,7 +1069,17 @@ app.put("/upload/direct", async (req, res) => { | |||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
proxy.on("error", function (err, req, proxyRes) { | ||||||||||||||||||||||||||||
console.error("Proxy error:", err); | ||||||||||||||||||||||||||||
if (!res.headersSent) { | ||||||||||||||||||||||||||||
res.status(403); | ||||||||||||||||||||||||||||
res.end(); | ||||||||||||||||||||||||||||
proxyRes.end(); | ||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||
res.end(); | ||||||||||||||||||||||||||||
proxyRes.end(); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+1074
to
+1081
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
proxy.web(req, res, { | ||||||||||||||||||||||||||||
target: uploadUrl, | ||||||||||||||||||||||||||||
changeOrigin: true, | ||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,13 +223,22 @@ export async function getObjectStoreS3Config( | |
}; | ||
} | ||
|
||
export async function getS3PresignedUrl(os: ObjectStore, objectKey: string) { | ||
export async function getS3PresignedUrl( | ||
os: ObjectStore, | ||
objectKey: string, | ||
contentLength?: number | ||
) { | ||
const config = await getObjectStoreS3Config(os); | ||
const s3 = new S3Client(config); | ||
const putCommand = new PutObjectCommand({ | ||
let putCommandConfig = { | ||
Bucket: config.bucket, | ||
Key: objectKey, | ||
}); | ||
ContentLength: null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be just |
||
}; | ||
if (contentLength) { | ||
putCommandConfig.ContentLength = contentLength; | ||
} | ||
const putCommand = new PutObjectCommand(putCommandConfig); | ||
const expiresIn = 12 * 60 * 60; // 12h in seconds | ||
return getSignedUrl(s3, putCommand, { expiresIn }); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -920,6 +920,8 @@ components: | |
description: Object store ID where the asset is stored | ||
writeOnly: true | ||
example: 09F8B46C-61A0-4254-9875-F71F4C605BC7 | ||
contentLength: | ||
type: number | ||
Comment on lines
+923
to
+924
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be in |
||
catalystPipelineStrategy: | ||
$ref: "#/components/schemas/task/properties/params/properties/upload/properties/catalystPipelineStrategy" | ||
ipfs-file-info: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would this work?