You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "suyanhanx (via GitHub)" <gi...@apache.org> on 2023/03/30 00:20:05 UTC

[GitHub] [incubator-opendal] suyanhanx commented on a diff in pull request #1798: chore(bindings/nodejs): update presign example and init benchmark

suyanhanx commented on code in PR #1798:
URL: https://github.com/apache/incubator-opendal/pull/1798#discussion_r1152610967


##########
bindings/nodejs/generated.js:
##########


Review Comment:
   We don't need to update this file. It is automatically generated.



##########
bindings/nodejs/package.json:
##########


Review Comment:
   Can we move these dependencies into the benchmark folder?



##########
bindings/nodejs/examples/presign.js:
##########
@@ -44,6 +49,22 @@ const server = http.createServer(async (req, res) => {
   }
 })
 
-server.listen(3000, () => {
+server.listen(3000, async () => {
   console.log('Server is listening on port 3000.')
+
+  /* Get presigned upload url */
+  const presignRequest = await fetch('http://127.0.0.1:3000/presign/upload?path=opendal.txt&expires=3600').then((v) =>
+    v.json(),
+  )
+  /* Upload file use presign data */
+  await fetch(presignRequest.uri, {

Review Comment:
   ```suggestion
     await fetch(presignRequest.url, {
   ```
   
   Same above.



##########
bindings/nodejs/examples/presign.js:
##########
@@ -18,24 +18,29 @@
  */
 
 const http = require('node:http')
-const url = require('node:url')
 const { Operator } = require('../index')
 
 const op = new Operator('s3', {
   root: '/',
-  bucket: 'example-bucket',
+  bucket: 'presign'
 })
 
 const server = http.createServer(async (req, res) => {
   res.setHeader('Content-Type', 'text/json; charset=utf-8')
-
-  if (req.url.startsWith('/presign') && req.method === 'GET') {
-    const urlParts = url.parse(req.url, true)
-    const path = urlParts.query.path
-    const expires = urlParts.query.expires
-
-    const presignedRequest = op.presignRead(path, parseInt(expires))
-
+  if (req.url.startsWith('/presign/download')) {
+    const url = new URL(req.url, 'http://locahost:3000')
+    const path = url.searchParams.get('path')
+    const expires = parseInt(url.searchParams.get('expires'), 10)
+    const presignedRequest = op.presignRead(path, expires)
+    /* Redirect client to download file from presigned url */
+    res.statusCode = 307
+    res.setHeader('Location', presignedRequest.uri)

Review Comment:
   ```suggestion
       res.setHeader('Location', presignedRequest.url)
   ```
   
   Sorry for updating the API. Please check the latest file.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org