Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/single-bucket' into feat/sb…
Browse files Browse the repository at this point in the history
…-put-object
  • Loading branch information
bstopp committed Aug 14, 2024
2 parents 7e77798 + 52a9abe commit e1c5926
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"test": "c8 mocha --spec=test/**/*.test.js && mocha --spec=test/it/**/*.spec.js",
"test:unit": "c8 mocha --spec=test/**/*.test.js",
"test:it": "mocha --spec=test/it/**/*.spec.js",
"dev": "wrangler dev",
"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",
Expand Down
29 changes: 16 additions & 13 deletions src/routes/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,22 @@ import listOrgs from '../storage/org/list.js';
* @return {Promise<ListResponse>} the list
*/
export default async function getList({ env, daCtx }) {
let body;
if (!daCtx.org) {
body = await listOrgs(env, daCtx);
} else {
body = await listObjects(env, daCtx);
}
if (body && body.length) {
return {
body: JSON.stringify(body),
status: 200,
contentType: 'application/json',
};
} else {
return { body: '', status: 404 };
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',
};
}
9 changes: 9 additions & 0 deletions test/it/get.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ describe('GET HTTP Requests', () => {
});

describe('objects', async () => {
it('lists no content', async () => {
const req = new Request('https://admin.da.live/list/does-not-exist');
const resp = await worker.fetch(req, env);
assert.strictEqual(resp.status, 200);
const body = await resp.json();
assert.strictEqual(body.length, 0);
assert.deepStrictEqual(body, []);
});

it('lists content', async () => {
const req = new Request('https://admin.da.live/list/wknd');
const resp = await worker.fetch(req, env);
Expand Down
10 changes: 5 additions & 5 deletions test/routes/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ describe('list route', () => {
{ path: '/org/sheet', name: 'sheet', ext: 'json' }
];

it ('returns 404 for no objects', async () => {
it ('returns empty list for no objects', async () => {
const getList = await esmock(
'../../src/routes/list.js',
{
'../../src/storage/object/list.js': {
default: async () => []
default: async () => undefined
},
}
);
const resp = await getList({ env: {}, daCtx: {} })
assert.strictEqual(resp.body, '', 'Correct response.');
assert.strictEqual(resp.status, 404, 'Correct status.');
const resp = await getList({ env: {}, daCtx: { org: 'org' } })
assert.strictEqual(resp.body, '[]', 'Correct response.');
assert.strictEqual(resp.status, 200, 'Correct status.');
});

it('lists objects in a bucket', async () => {
Expand Down
15 changes: 10 additions & 5 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,30 @@ main = "src/index.js"
compatibility_date = "2023-10-30"

vars = { DA_COLLAB = "https://collab.da.live" }

services = [
{ binding = "dacollab", service = "da-collab" }
]

kv_namespaces = [
{ binding = "DA_AUTH", id = "d6217b7c63ef40889583ba5c080c3908" },
{ binding = "DA_CONFIG", id = "feb8618620bb4ca3a866f1c71adbe8ef" }
]
r2_buckets = [
{ binding = "DA_CONTENT", bucket_name = "da-content" }
]


r2_buckets = [
{ binding = "DA_CONTENT", bucket_name = "da-content" }
]

[env.stage]
vars = { ENVIRONMENT = "stage", DA_COLLAB = "https://collab.da.live" }

services = [
{ binding = "dacollab", service = "da-collab-stage" }
]

r2_buckets = [
{ binding = "DA_CONTENT", bucket_name = "da-content-stage" }
]
kv_namespaces = [
{ binding = "DA_AUTH", id = "21693f3b20f54fcbb850ddc8947335ba" },
{ binding = "DA_CONFIG", id = "c44cb8dc69f041dc87c5aaef41b97df9" }
Expand All @@ -40,11 +43,13 @@ kv_namespaces = [
{ binding = "DA_AUTH", id = "21693f3b20f54fcbb850ddc8947335ba" },
{ binding = "DA_CONFIG", id = "c44cb8dc69f041dc87c5aaef41b97df9" }
]

r2_buckets = [
{ binding = "DA_CONTENT", bucket_name = "da-content" }
]

services = [
{ binding = "dacollab", service = "da-collab-dev" }
]
r2_buckets = [
{ binding = "DA_CONTENT", bucket_name = "da-content-dev" }
]

0 comments on commit e1c5926

Please sign in to comment.