Skip to content
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

Single Bucket - Unknown Typo #101

Closed
wants to merge 13 commits into from
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ module.exports = {
extends: '@adobe/helix',
rules: {
'no-await-in-loop': 0,
'max-len': ["error", { "code": 200 }],
},
};
9 changes: 4 additions & 5 deletions .nycrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
"check-coverage": true,
"all": true,
"include": ["src/**/*.js"],
"lines": 45,
"branches": 80,
"statements": 45,
"functions": 45,
"skip-full": true
"statements": 75,
"branches": 90,
"functions": 70,
"lines": 75
}
4,290 changes: 1,839 additions & 2,451 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@
"docs:build": "npx @redocly/cli build-docs -o docs/index.html admin@v1",
"docs:watch": "npx @redocly/cli preview-docs admin@v1",
"lint": "eslint .",
"test": "c8 mocha --spec=test/**/*.test.js",
"dev": "wrangler dev",
"test": "c8 mocha --spec=test/**/*.test.js && mocha --spec=test/it/**/*.spec.js",
"test:unit": "c8 mocha --spec=test/**/*.test.js",
"test:perf": "mocha --spec=test/**/*.perf.js",
"test:it": "mocha --spec=test/it/**/*.spec.js",
"dev": "wrangler dev --env dev",
"deploy:prod": "wrangler deploy",
"deploy:stage": "wrangler deploy --env stage",
"start": "wrangler dev"
"start": "wrangler dev --env dev"
},
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"@adobe/eslint-config-helix": "2.0.6",
"@redocly/cli": "^1.4.1",
"aws-sdk-client-mock": "^4.0.0",
"c8": "^8.0.1",
"eslint": "8.56.0",
"esmock": "^2.6.4",
"miniflare": "^3.20240605.0",
"mocha": "^10.2.0",
"wrangler": "^3.57.0"
},
Expand All @@ -34,9 +37,6 @@
"*.cjs": "eslint"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.456.0",
"@aws-sdk/s3-request-presigner": "^3.468.0",
"@ssttevee/cfw-formdata-polyfill": "^0.2.1",
"jose": "^5.1.3"
}
}
2 changes: 1 addition & 1 deletion src/handlers/unkown.js → src/handlers/unknown.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
export default function unkownHandler() {
export default function unknownHandler() {
const body = JSON.stringify({ message: 'Unknown method. Please see: https://docs.da.live for more information.' });
return { body, status: 501 };
}
10 changes: 9 additions & 1 deletion src/helpers/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/**
* Creates the copy source/dest object from the current contexts
* @param {Request} req the Request object
* @param {Object} daCtx the DA Context
* @return {Promise<{destination: string, source: string}|{}>}
*/
export default async function copyHelper(req, daCtx) {
const formData = await req.formData();
if (!formData) return {};
const fullDest = formData.get('destination');
const continuationToken = formData.get('continuation-token');
const lower = fullDest.slice(1).toLowerCase();
const sanitized = lower.endsWith('/') ? lower.slice(0, -1) : lower;
const destination = sanitized.split('/').slice(1).join('/');
const source = daCtx.key;
return { source, destination };
return { source, destination, continuationToken };
}
21 changes: 21 additions & 0 deletions src/helpers/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
export default async function deleteHelper(req) {
try {
const formData = await req.formData();
if (!formData) return {};
const continuationToken = formData.get('continuation-token');
return { continuationToken };
} catch {
return {};
}
}
15 changes: 15 additions & 0 deletions src/helpers/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ const NO_PARENT_ERROR = {
status: 400,
};

/**
* @typedef MoveDetails
* @property {String=} source the source path
* @property {String=} destination the destination path
* @property {Object=} error the error object
* @property {String=} error.body the error message
* @property {Number=} error.status the error status code
*/

/**
* Creates the copy source/dest object from the current contexts
* @param {Request} req the Request object
* @param {Object} daCtx the DA Context
* @return {Promise<MoveDetails>}
*/
export default async function moveHelper(req, daCtx) {
try {
const formData = await req.formData();
Expand Down
1 change: 1 addition & 0 deletions src/helpers/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

export default async function renameHelper(req, daCtx) {
const formData = await req.formData();
if (!formData) return {};
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { FORM_TYPES } from '../utils/constants.js';

/**
* Builds a source response
* @param {*} key
* @param {DaCtx} daCtx
*/
export function sourceRespObject(daCtx) {
const {
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import headHandler from './handlers/head.js';
import getHandler from './handlers/get.js';
import postHandler from './handlers/post.js';
import deleteHandler from './handlers/delete.js';
import unkownHandler from './handlers/unkown.js';
import unknownHandler from './handlers/unknown.js';

export default {
async fetch(req, env) {
Expand Down Expand Up @@ -45,7 +45,7 @@ export default {
respObj = await deleteHandler({ req, env, daCtx });
break;
default:
respObj = unkownHandler();
respObj = unknownHandler();
}

return daResp(respObj);
Expand Down
38 changes: 34 additions & 4 deletions src/routes/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,40 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import listBuckets from '../storage/bucket/list.js';
import listObjects from '../storage/object/list.js';
import listOrgs from '../storage/org/list.js';

export default function getList({ env, daCtx }) {
if (!daCtx.org) return listBuckets(env, daCtx);
return listObjects(env, daCtx);
/**
* Response object for the list endpoint
* @typedef {Object} ListResponse
* @property {String} body the response body
* @property {Number} status the response status
* @property {String|undefined} contentType the response content type
*/

/**
* Lists the objects in the current context - either orgs or objects/folders in an context
* @param {Object} env the worker environment
* @param {Object} daCtx current context
* @return {Promise<ListResponse>} the list
*/
export default async function getList({ env, daCtx }) {
if (!daCtx.org) {
const body = await listOrgs(env, daCtx);
if (body && body.length) {
return {
body: JSON.stringify(body),
status: 200,
contentType: 'application/json',
};
} else {
return { body: '', status: 404 };
}
}
const body = await listObjects(env, daCtx);
return {
body: JSON.stringify(body || []),
status: 200,
contentType: 'application/json',
};
}
32 changes: 6 additions & 26 deletions src/routes/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,20 @@
import getObject from '../storage/object/get.js';
import putObject from '../storage/object/put.js';
import deleteObjects from '../storage/object/delete.js';

import putHelper from '../helpers/source.js';
import { postObjectVersion } from '../storage/version/put.js';

async function invalidateCollab(api, url, env) {
const invPath = `/api/v1/${api}?doc=${url}`;

// Use dacollab service binding, hostname is not relevant
const invURL = `https://localhost${invPath}`;
await env.dacollab.fetch(invURL);
}
import deleteHelper from '../helpers/delete.js';
import { syncCollab } from '../storage/utils/collab.js';

export async function deleteSource({ req, env, daCtx }) {
await postObjectVersion(req, env, daCtx);
const resp = await deleteObjects(env, daCtx);

if (resp.status === 204) {
const initiator = req.headers.get('x-da-initiator');
if (initiator !== 'collab') {
await invalidateCollab('deleteadmin', req.url, env);
}
}
return resp;
const details = await deleteHelper(req);
return deleteObjects(env, daCtx, details);
}

export async function postSource({ req, env, daCtx }) {
const obj = await putHelper(req, env, daCtx);
const resp = await putObject(env, daCtx, obj);

if (resp.status === 201 || resp.status === 200) {
const initiator = req.headers.get('x-da-initiator');
if (initiator !== 'collab') {
await invalidateCollab('syncadmin', req.url, env);
}
if (resp.status === 200 || resp.status === 201) {
await syncCollab(env, daCtx);
}
return resp;
}
Expand Down
44 changes: 0 additions & 44 deletions src/storage/bucket/list.js

This file was deleted.

Loading
Loading