Skip to content

Commit

Permalink
Add headers, fix other smaller issues
Browse files Browse the repository at this point in the history
  • Loading branch information
auniverseaway committed Feb 7, 2024
1 parent 2349597 commit 31d0fa5
Show file tree
Hide file tree
Showing 24 changed files with 283 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.vscode/*
coverage/*
dist/*
!.releaserc.js
test/*
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"scripts": {
"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",
"deploy:prod": "wrangler deploy",
Expand Down
11 changes: 11 additions & 0 deletions src/handlers/delete.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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.
*/
import { deleteSource } from '../routes/source.js';

export default async function deleteHandler({ env, daCtx }) {
Expand Down
11 changes: 11 additions & 0 deletions src/handlers/get.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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.
*/
import { getSource } from '../routes/source.js';
import getList from '../routes/list.js';
import { getProperties } from '../routes/properties.js';
Expand Down
11 changes: 11 additions & 0 deletions src/handlers/post.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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.
*/
import { postSource } from '../routes/source.js';
import { postProperties } from '../routes/properties.js';

Expand Down
11 changes: 11 additions & 0 deletions src/handlers/unkown.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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 function unkownHandler() {
const body = JSON.stringify({ message: 'Unknown method. Please see: https://docs.da.live for more information.' });
return { body, status: 501 };
Expand Down
11 changes: 11 additions & 0 deletions src/helpers/copy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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 copyHelper(req, daCtx) {
const formData = await req.formData();
if (!formData) return {};
Expand Down
15 changes: 14 additions & 1 deletion src/helpers/source.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
/*
* 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.
*/
import { FORM_TYPES } from '../utils/constants.js';

/**
* Builds a source response
* @param {*} key
*/
export function sourceRespObject(daCtx, props) {
const { org, site, isFile, pathname, aemPathname } = daCtx;
const {
org, site, isFile, pathname, aemPathname,
} = daCtx;

const obj = {
source: {
Expand Down
11 changes: 11 additions & 0 deletions src/routes/copy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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.
*/
import copyObject from '../storage/object/copy.js';
import copyHelper from '../helpers/copy.js';

Expand Down
11 changes: 11 additions & 0 deletions src/routes/list.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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.
*/
import listBuckets from '../storage/bucket/list.js';
import listObjects from '../storage/object/list.js';

Expand Down
17 changes: 13 additions & 4 deletions src/routes/properties.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
// eslint-disable-next-line no-unused-vars
/*
* 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 function postProperties({ env, daCtx }) {
return { body: JSON.stringify([]), status: 201 };
return { body: JSON.stringify(env, daCtx), status: 201 };
}

// eslint-disable-next-line no-unused-vars
export function getProperties({ env, daCtx }) {
return { body: JSON.stringify([]), status: 200 };
return { body: JSON.stringify(env, daCtx), status: 200 };
}
11 changes: 11 additions & 0 deletions src/routes/source.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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.
*/
import getObject from '../storage/object/get.js';
import putObject from '../storage/object/put.js';
import deleteObject from '../storage/object/delete.js';
Expand Down
11 changes: 11 additions & 0 deletions src/storage/bucket/list.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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.
*/
import {
S3Client,
ListBucketsCommand,
Expand Down
11 changes: 11 additions & 0 deletions src/storage/object/copy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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.
*/
import {
S3Client,
ListObjectsV2Command,
Expand Down
11 changes: 11 additions & 0 deletions src/storage/object/delete.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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.
*/
import {
S3Client,
DeleteObjectCommand,
Expand Down
11 changes: 11 additions & 0 deletions src/storage/object/get.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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.
*/
import {
S3Client,
GetObjectCommand,
Expand Down
11 changes: 11 additions & 0 deletions src/storage/object/list.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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.
*/
import {
S3Client,
ListObjectsV2Command,
Expand Down
32 changes: 27 additions & 5 deletions src/storage/object/put.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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.
*/
import {
S3Client,
PutObjectCommand,
Expand All @@ -16,14 +27,19 @@ function getObjectBody(data) {
return { body: JSON.stringify(data), type: 'application/json' };
}

function buildInput({ org, key, body, type }) {
function buildInput({
org, key, body, type,
}) {
const Bucket = `${org}-content`;
return { Bucket, Key: key, Body: body, ContentType: type };
return {
Bucket, Key: key, Body: body, ContentType: type,
};
}

function createBucketIfMissing(client) {
client.middlewareStack.add(
(next) => async (args) => {
// eslint-disable-next-line no-param-reassign
args.request.headers['cf-create-bucket-if-missing'] = 'true';
return next(args);
},
Expand All @@ -50,16 +66,22 @@ export default async function putObject(env, daCtx, obj) {
if (obj.data) {
const isFile = obj.data instanceof File;
const { body, type } = isFile ? await getFileBody(obj.data) : getObjectBody(obj.data);
inputs.push(buildInput({ org, key, body, type }));
inputs.push(buildInput({
org, key, body, type,
}));
}
if (obj.props) {
const { body, type } = getObjectBody(obj.props);
const inputConfig = { org, key: propsKey || key, body, type };
const inputConfig = {
org, key: propsKey || key, body, type,
};
inputs.push(buildInput(inputConfig));
}
} else {
const { body, type } = getObjectBody({});
const inputConfig = { org, key: propsKey, body, type };
const inputConfig = {
org, key: propsKey, body, type,
};
inputs.push(buildInput(inputConfig));
}

Expand Down
11 changes: 11 additions & 0 deletions src/storage/utils/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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 function getS3Config(env) {
return {
region: 'auto',
Expand Down
12 changes: 12 additions & 0 deletions src/storage/utils/list.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* 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 function formatList(resp, daCtx) {
function compare(a, b) {
if (a.name < b.name) return -1;
Expand Down Expand Up @@ -40,6 +51,7 @@ export default function formatList(resp, daCtx) {
if (combined.some((item) => item.name === name)) return;

// Remove props from the key so it can look like a folder
// eslint-disable-next-line no-param-reassign
content.Key = content.Key.replace('.props', '');
}

Expand Down
Loading

0 comments on commit 31d0fa5

Please sign in to comment.