From a350e1d731f39060432f8c5640299b4f10d6317f Mon Sep 17 00:00:00 2001 From: Chris Millar Date: Fri, 29 Mar 2024 12:21:45 -0600 Subject: [PATCH] Fix copy route --- src/handlers/post.js | 2 ++ src/routes/copy.js | 10 +++------- src/storage/object/copy.js | 6 +----- src/utils/daResp.js | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/handlers/post.js b/src/handlers/post.js index 4280144..3c03eae 100644 --- a/src/handlers/post.js +++ b/src/handlers/post.js @@ -11,12 +11,14 @@ */ import { postSource } from '../routes/source.js'; import { postConfig } from '../routes/config.js'; +import copyHandler from '../routes/copy.js'; export default async function postHandler({ req, env, daCtx }) { const { path } = daCtx; if (path.startsWith('/source')) return postSource({ req, env, daCtx }); if (path.startsWith('/config')) return postConfig({ req, env, daCtx }); + if (path.startsWith('/copy')) return copyHandler({ req, env, daCtx }); return undefined; } diff --git a/src/routes/copy.js b/src/routes/copy.js index c3d39d2..836b9bb 100644 --- a/src/routes/copy.js +++ b/src/routes/copy.js @@ -12,11 +12,7 @@ import copyObject from '../storage/object/copy.js'; import copyHelper from '../helpers/copy.js'; -export default async function copyHandler(req, env, daCtx) { - if (req.method === 'POST') { - const details = await copyHelper(req, daCtx); - return copyObject(env, daCtx, details); - } - - return { body: JSON.stringify([]), status: 200, contentType: 'application/json' }; +export default async function copyHandler({ req, env, daCtx }) { + const details = await copyHelper(req, daCtx); + return copyObject(env, daCtx, details); } diff --git a/src/storage/object/copy.js b/src/storage/object/copy.js index 3530b7d..2fe99cd 100644 --- a/src/storage/object/copy.js +++ b/src/storage/object/copy.js @@ -39,10 +39,6 @@ const copyFile = async (client, org, sourceKey, details) => { // eslint-disable-next-line no-console console.log(e.$metadata); } - - // const delCommand = new DeleteObjectCommand({ Bucket: `${org}-content`, Key: sourceKey }); - // const url = await getSignedUrl(client, delCommand, { expiresIn: 3600 }); - // await fetch(url, { method: 'DELETE' }); }; export default async function copyObject(env, daCtx, details) { @@ -78,5 +74,5 @@ export default async function copyObject(env, daCtx, details) { } } while (ContinuationToken); - return { body: '', status: 204 }; + return { status: 204 }; } diff --git a/src/utils/daResp.js b/src/utils/daResp.js index 6286b16..adac5df 100644 --- a/src/utils/daResp.js +++ b/src/utils/daResp.js @@ -11,7 +11,7 @@ */ export default function daResp({ status, - body = '', + body, contentType = 'application/json', contentLength, }) {