-
Notifications
You must be signed in to change notification settings - Fork 9
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 - Delete object #67
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a427945
Change to single bucket and R2 Bindings
bstopp 3d82152
Remove version logic & test. Add integration tests.
bstopp 03354cd
Fix lint.
bstopp 849fbbf
More tests and some clean up.
bstopp 556b936
Fix API change for move.
bstopp 70e580a
Intermediate error on comparing timestamp?
bstopp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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 assert from 'node:assert' | ||
import { destroyMiniflare, getMiniflare } from '../mocks/miniflare.js'; | ||
import worker from '../../src/index.js'; | ||
|
||
describe('DELETE HTTP Requests', () => { | ||
let mf; | ||
let env; | ||
beforeEach(async () => { | ||
mf = await getMiniflare(); | ||
env = await mf.getBindings(); | ||
}); | ||
afterEach(async () => { | ||
await destroyMiniflare(mf); | ||
}); | ||
|
||
describe ('/source', async () => { | ||
it('handles non-existing file', async () => { | ||
const req = new Request('https://admin.da.live/source/wknd/does-not-exist', { method: 'DELETE' }); | ||
const resp = await worker.fetch(req, env); | ||
assert.strictEqual(resp.status, 204); | ||
}); | ||
|
||
it('handles existing file', async () => { | ||
const req = new Request('https://admin.da.live/source/wknd/index.html', { method: 'DELETE' }); | ||
const resp = await worker.fetch(req, env); | ||
assert.strictEqual(resp.status, 204); | ||
const obj = await env.DA_CONTENT.get('wknd/index.html'); | ||
assert.ifError(obj); | ||
}); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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 assert from 'node:assert'; | ||
import { destroyMiniflare, getMiniflare } from '../../mocks/miniflare.js'; | ||
import listObjects from '../../../src/storage/object/list.js'; | ||
import deleteObjects from '../../../src/storage/object/delete.js'; | ||
|
||
describe('delete object(s)', () => { | ||
let mf; | ||
let env; | ||
beforeEach(async () => { | ||
mf = await getMiniflare(); | ||
env = await mf.getBindings(); | ||
}); | ||
afterEach(async () => { | ||
await destroyMiniflare(mf); | ||
}); | ||
|
||
it('handles no object', async () => { | ||
const daCtx = { users: [{email: '[email protected]'}], org: 'geometrixx', key: 'does-not-exist.html' }; | ||
const resp = await deleteObjects(env, daCtx); | ||
assert.strictEqual(resp.status, 204); | ||
}); | ||
|
||
it('deletes a single object', async () => { | ||
const daCtx = { users: [{email: '[email protected]'}], org: 'geometrixx', key: 'outdoors/index.html' }; | ||
|
||
await env.DA_CONTENT.put('geometrixx/shapes.props', '{"key":"value"}'); | ||
await env.DA_CONTENT.put('geometrixx/we-retail.props', '{"key":"value"}'); | ||
await env.DA_CONTENT.put('geometrixx/outdoors/index.html', 'Hello'); | ||
|
||
const resp = await deleteObjects(env, daCtx); | ||
assert.strictEqual(resp.status, 204); | ||
const head = await env.DA_CONTENT.head('geometrixx/outdoors/index.html'); | ||
assert.ifError(head); | ||
}); | ||
|
||
it('deletes a folder', async () => { | ||
await env.DA_CONTENT.put('geometrixx/outdoors/index.html', 'Hello!'); | ||
await env.DA_CONTENT.put('geometrixx/outdoors/logo.jpg', '1234'); | ||
await env.DA_CONTENT.put('geometrixx/outdoors/hero.jpg', '1234'); | ||
await env.DA_CONTENT.put('geometrixx/outdoors/coats/coats.props', '{"key": "value"}'); | ||
await env.DA_CONTENT.put('geometrixx/outdoors/pants/pants.props', '{"key": "value"}'); | ||
await env.DA_CONTENT.put('geometrixx/outdoors/hats/hats.props', '{"key": "value"}'); | ||
|
||
const daCtx = { users: [{email: '[email protected]'}], org: 'geometrixx', key: 'outdoors' }; | ||
const resp = await deleteObjects(env, daCtx); | ||
assert.strictEqual(resp.status, 204); | ||
const list = await env.DA_CONTENT.list({ prefix: 'geometrixx/outdoors' }); | ||
assert.strictEqual(list.objects.length, 0); | ||
}); | ||
|
||
it('deletes a folder (truncated list === true)', async function() { | ||
this.timeout(10000); | ||
await env.DA_CONTENT.put('geometrixx/outdoors/index.html', 'Hello!'); | ||
for (let i = 0; i < 1000; i++) { | ||
await env.DA_CONTENT.put(`geometrixx/outdoors/${i}/${i}.html`, 'Content'); | ||
} | ||
|
||
const daCtx = { users: [{email: '[email protected]'}], org: 'geometrixx', key: 'outdoors' }; | ||
const resp = await deleteObjects(env, daCtx); | ||
assert.strictEqual(resp.status, 204); | ||
const list = await env.DA_CONTENT.list({ prefix: 'geometrixx/outdoors' }); | ||
assert.strictEqual(list.objects.length, 0); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC this line here is to save a version of the file before deletion, so that it could be restored if the delete was accidental. I think it would be good to keep that.
/cc @karlpauls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, there was a discussion about this (OOB). The problem was it didn't consider directories correctly. IMO it would make sense to keep it unless it causes big performance concerns but it would need to be only done for files and you'd have to evaluate the impact for large trees I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was discussed on Slack w/ @auniverseaway , and the decision was to remove it.