Skip to content

Commit 02a7fbe

Browse files
author
Alan Shaw
committedMay 15, 2024·
feat: initial commit
0 parents  commit 02a7fbe

10 files changed

+5212
-0
lines changed
 

‎.github/workflows/build.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Build
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
10+
jobs:
11+
test:
12+
name: Test
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
- name: Install
18+
uses: pnpm/action-setup@v2.2.3
19+
with:
20+
version: 8
21+
- name: Setup
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: 18
25+
registry-url: https://registry.npmjs.org/
26+
cache: 'pnpm'
27+
- name: Lint
28+
run: npm run lint
29+
- name: Test
30+
run: npm test

‎.github/workflows/release.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
name: Release
6+
jobs:
7+
release-staging:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
- uses: ./.github/actions/test
12+
- name: Deploy to Staging
13+
uses: cloudflare/wrangler-action@2.0.0
14+
with:
15+
apiToken: ${{secrets.CF_TOKEN }}
16+
environment: 'carpark-staging'
17+
release-production:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: google-github-actions/release-please-action@v3
21+
id: release
22+
with:
23+
release-type: node
24+
package-name: public-r2-bucket
25+
- uses: actions/checkout@v3
26+
- uses: ./.github/actions/test
27+
- name: Deploy to Production
28+
uses: cloudflare/wrangler-action@2.0.0
29+
with:
30+
apiToken: ${{ secrets.CF_TOKEN }}
31+
environment: 'carpark-production'
32+
if: ${{ steps.release.outputs.release_created }}
33+

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
coverage

‎LICENSE.md

+232
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
The contents of this repository are Copyright (c) corresponding authors and
2+
contributors, licensed under the `Permissive License Stack` meaning either of:
3+
4+
- Apache-2.0 Software License: https://www.apache.org/licenses/LICENSE-2.0
5+
([...4tr2kfsq](https://dweb.link/ipfs/bafkreiankqxazcae4onkp436wag2lj3ccso4nawxqkkfckd6cg4tr2kfsq))
6+
7+
- MIT Software License: https://opensource.org/licenses/MIT
8+
([...vljevcba](https://dweb.link/ipfs/bafkreiepofszg4gfe2gzuhojmksgemsub2h4uy2gewdnr35kswvljevcba))
9+
10+
You may not use the contents of this repository except in compliance
11+
with one of the listed Licenses. For an extended clarification of the
12+
intent behind the choice of Licensing please refer to
13+
https://protocol.ai/blog/announcing-the-permissive-license-stack/
14+
15+
Unless required by applicable law or agreed to in writing, software
16+
distributed under the terms listed in this notice is distributed on
17+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
18+
either express or implied. See each License for the specific language
19+
governing permissions and limitations under that License.
20+
21+
<!--- SPDX-License-Identifier: Apache-2.0 OR MIT -->
22+
23+
`SPDX-License-Identifier: Apache-2.0 OR MIT`
24+
25+
Verbatim copies of both licenses are included below:
26+
27+
<details><summary>Apache-2.0 Software License</summary>
28+
29+
```
30+
Apache License
31+
Version 2.0, January 2004
32+
http://www.apache.org/licenses/
33+
34+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
35+
36+
1. Definitions.
37+
38+
"License" shall mean the terms and conditions for use, reproduction,
39+
and distribution as defined by Sections 1 through 9 of this document.
40+
41+
"Licensor" shall mean the copyright owner or entity authorized by
42+
the copyright owner that is granting the License.
43+
44+
"Legal Entity" shall mean the union of the acting entity and all
45+
other entities that control, are controlled by, or are under common
46+
control with that entity. For the purposes of this definition,
47+
"control" means (i) the power, direct or indirect, to cause the
48+
direction or management of such entity, whether by contract or
49+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
50+
outstanding shares, or (iii) beneficial ownership of such entity.
51+
52+
"You" (or "Your") shall mean an individual or Legal Entity
53+
exercising permissions granted by this License.
54+
55+
"Source" form shall mean the preferred form for making modifications,
56+
including but not limited to software source code, documentation
57+
source, and configuration files.
58+
59+
"Object" form shall mean any form resulting from mechanical
60+
transformation or translation of a Source form, including but
61+
not limited to compiled object code, generated documentation,
62+
and conversions to other media types.
63+
64+
"Work" shall mean the work of authorship, whether in Source or
65+
Object form, made available under the License, as indicated by a
66+
copyright notice that is included in or attached to the work
67+
(an example is provided in the Appendix below).
68+
69+
"Derivative Works" shall mean any work, whether in Source or Object
70+
form, that is based on (or derived from) the Work and for which the
71+
editorial revisions, annotations, elaborations, or other modifications
72+
represent, as a whole, an original work of authorship. For the purposes
73+
of this License, Derivative Works shall not include works that remain
74+
separable from, or merely link (or bind by name) to the interfaces of,
75+
the Work and Derivative Works thereof.
76+
77+
"Contribution" shall mean any work of authorship, including
78+
the original version of the Work and any modifications or additions
79+
to that Work or Derivative Works thereof, that is intentionally
80+
submitted to Licensor for inclusion in the Work by the copyright owner
81+
or by an individual or Legal Entity authorized to submit on behalf of
82+
the copyright owner. For the purposes of this definition, "submitted"
83+
means any form of electronic, verbal, or written communication sent
84+
to the Licensor or its representatives, including but not limited to
85+
communication on electronic mailing lists, source code control systems,
86+
and issue tracking systems that are managed by, or on behalf of, the
87+
Licensor for the purpose of discussing and improving the Work, but
88+
excluding communication that is conspicuously marked or otherwise
89+
designated in writing by the copyright owner as "Not a Contribution."
90+
91+
"Contributor" shall mean Licensor and any individual or Legal Entity
92+
on behalf of whom a Contribution has been received by Licensor and
93+
subsequently incorporated within the Work.
94+
95+
2. Grant of Copyright License. Subject to the terms and conditions of
96+
this License, each Contributor hereby grants to You a perpetual,
97+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
98+
copyright license to reproduce, prepare Derivative Works of,
99+
publicly display, publicly perform, sublicense, and distribute the
100+
Work and such Derivative Works in Source or Object form.
101+
102+
3. Grant of Patent License. Subject to the terms and conditions of
103+
this License, each Contributor hereby grants to You a perpetual,
104+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
105+
(except as stated in this section) patent license to make, have made,
106+
use, offer to sell, sell, import, and otherwise transfer the Work,
107+
where such license applies only to those patent claims licensable
108+
by such Contributor that are necessarily infringed by their
109+
Contribution(s) alone or by combination of their Contribution(s)
110+
with the Work to which such Contribution(s) was submitted. If You
111+
institute patent litigation against any entity (including a
112+
cross-claim or counterclaim in a lawsuit) alleging that the Work
113+
or a Contribution incorporated within the Work constitutes direct
114+
or contributory patent infringement, then any patent licenses
115+
granted to You under this License for that Work shall terminate
116+
as of the date such litigation is filed.
117+
118+
4. Redistribution. You may reproduce and distribute copies of the
119+
Work or Derivative Works thereof in any medium, with or without
120+
modifications, and in Source or Object form, provided that You
121+
meet the following conditions:
122+
123+
(a) You must give any other recipients of the Work or
124+
Derivative Works a copy of this License; and
125+
126+
(b) You must cause any modified files to carry prominent notices
127+
stating that You changed the files; and
128+
129+
(c) You must retain, in the Source form of any Derivative Works
130+
that You distribute, all copyright, patent, trademark, and
131+
attribution notices from the Source form of the Work,
132+
excluding those notices that do not pertain to any part of
133+
the Derivative Works; and
134+
135+
(d) If the Work includes a "NOTICE" text file as part of its
136+
distribution, then any Derivative Works that You distribute must
137+
include a readable copy of the attribution notices contained
138+
within such NOTICE file, excluding those notices that do not
139+
pertain to any part of the Derivative Works, in at least one
140+
of the following places: within a NOTICE text file distributed
141+
as part of the Derivative Works; within the Source form or
142+
documentation, if provided along with the Derivative Works; or,
143+
within a display generated by the Derivative Works, if and
144+
wherever such third-party notices normally appear. The contents
145+
of the NOTICE file are for informational purposes only and
146+
do not modify the License. You may add Your own attribution
147+
notices within Derivative Works that You distribute, alongside
148+
or as an addendum to the NOTICE text from the Work, provided
149+
that such additional attribution notices cannot be construed
150+
as modifying the License.
151+
152+
You may add Your own copyright statement to Your modifications and
153+
may provide additional or different license terms and conditions
154+
for use, reproduction, or distribution of Your modifications, or
155+
for any such Derivative Works as a whole, provided Your use,
156+
reproduction, and distribution of the Work otherwise complies with
157+
the conditions stated in this License.
158+
159+
5. Submission of Contributions. Unless You explicitly state otherwise,
160+
any Contribution intentionally submitted for inclusion in the Work
161+
by You to the Licensor shall be under the terms and conditions of
162+
this License, without any additional terms or conditions.
163+
Notwithstanding the above, nothing herein shall supersede or modify
164+
the terms of any separate license agreement you may have executed
165+
with Licensor regarding such Contributions.
166+
167+
6. Trademarks. This License does not grant permission to use the trade
168+
names, trademarks, service marks, or product names of the Licensor,
169+
except as required for reasonable and customary use in describing the
170+
origin of the Work and reproducing the content of the NOTICE file.
171+
172+
7. Disclaimer of Warranty. Unless required by applicable law or
173+
agreed to in writing, Licensor provides the Work (and each
174+
Contributor provides its Contributions) on an "AS IS" BASIS,
175+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
176+
implied, including, without limitation, any warranties or conditions
177+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
178+
PARTICULAR PURPOSE. You are solely responsible for determining the
179+
appropriateness of using or redistributing the Work and assume any
180+
risks associated with Your exercise of permissions under this License.
181+
182+
8. Limitation of Liability. In no event and under no legal theory,
183+
whether in tort (including negligence), contract, or otherwise,
184+
unless required by applicable law (such as deliberate and grossly
185+
negligent acts) or agreed to in writing, shall any Contributor be
186+
liable to You for damages, including any direct, indirect, special,
187+
incidental, or consequential damages of any character arising as a
188+
result of this License or out of the use or inability to use the
189+
Work (including but not limited to damages for loss of goodwill,
190+
work stoppage, computer failure or malfunction, or any and all
191+
other commercial damages or losses), even if such Contributor
192+
has been advised of the possibility of such damages.
193+
194+
9. Accepting Warranty or Additional Liability. While redistributing
195+
the Work or Derivative Works thereof, You may choose to offer,
196+
and charge a fee for, acceptance of support, warranty, indemnity,
197+
or other liability obligations and/or rights consistent with this
198+
License. However, in accepting such obligations, You may act only
199+
on Your own behalf and on Your sole responsibility, not on behalf
200+
of any other Contributor, and only if You agree to indemnify,
201+
defend, and hold each Contributor harmless for any liability
202+
incurred by, or claims asserted against, such Contributor by reason
203+
of your accepting any such warranty or additional liability.
204+
205+
END OF TERMS AND CONDITIONS
206+
```
207+
208+
</details>
209+
210+
<details><summary>MIT Software License</summary>
211+
212+
```
213+
Permission is hereby granted, free of charge, to any person obtaining a copy
214+
of this software and associated documentation files (the "Software"), to deal
215+
in the Software without restriction, including without limitation the rights
216+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
217+
copies of the Software, and to permit persons to whom the Software is
218+
furnished to do so, subject to the following conditions:
219+
220+
The above copyright notice and this permission notice shall be included in
221+
all copies or substantial portions of the Software.
222+
223+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
224+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
225+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
226+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
227+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
228+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
229+
THE SOFTWARE.
230+
```
231+
232+
</details>

‎README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# public-r2-bucket
2+
3+
Cloudflare worker allowing read access (with byte range request support) to R2 buckets.
4+
5+
## Contributing
6+
7+
Feel free to join in. All welcome. [Open an issue](https://github.com/w3s-project/public-r2-bucket/issues)!
8+
9+
## License
10+
11+
Dual-licensed under [MIT / Apache 2.0](https://github.com/w3s-project/public-r2-bucket/blob/main/LICENSE.md)

‎package.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "public-r2-bucket",
3+
"version": "0.0.0",
4+
"description": "Cloudflare worker allowing read access (with byte range request support) to R2 buckets.",
5+
"main": "index.js",
6+
"type": "module",
7+
"private": true,
8+
"scripts": {
9+
"build": "esbuild src/worker.js --bundle --format=esm --outfile=dist/worker.mjs",
10+
"lint": "standard",
11+
"test": "npm run build && entail"
12+
},
13+
"author": "Alan Shaw",
14+
"license": "Apache-2.0 OR MIT",
15+
"devDependencies": {
16+
"@cloudflare/workers-types": "^4.20240512.0",
17+
"buffer": "^6.0.3",
18+
"byteranges": "^1.1.0",
19+
"entail": "^2.1.2",
20+
"esbuild": "^0.21.2",
21+
"miniflare": "^3.20240512.0",
22+
"standard": "^17.0.0",
23+
"uint8arrays": "^5.1.0"
24+
},
25+
"dependencies": {
26+
"@httpland/range-parser": "^1.2.0",
27+
"@web3-storage/gateway-lib": "^5.0.1",
28+
"multipart-byte-range": "^2.0.2"
29+
},
30+
"repository": {
31+
"type": "git",
32+
"url": "git+https://github.com/nftstorage/dagcargo-bucket.git"
33+
},
34+
"bugs": {
35+
"url": "https://github.com/nftstorage/dagcargo-bucket/issues"
36+
},
37+
"homepage": "https://github.com/nftstorage/dagcargo-bucket#readme"
38+
}

‎pnpm-lock.yaml

+4,631
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/worker.js

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/* eslint-env worker */
2+
import {
3+
withContext,
4+
withCorsHeaders,
5+
withErrorHandler,
6+
createWithHttpMethod,
7+
withCdnCache,
8+
withFixedLengthStream,
9+
composeMiddleware
10+
} from '@web3-storage/gateway-lib/middleware'
11+
import { HttpError, decodeRangeHeader, resolveRange } from '@web3-storage/gateway-lib/util'
12+
import { MultipartByteRange } from 'multipart-byte-range'
13+
14+
/**
15+
* @typedef {{ BUCKET: import('@cloudflare/workers-types').R2Bucket }} Environment
16+
*/
17+
18+
export default {
19+
/** @type {import('@web3-storage/gateway-lib').Handler<import('@web3-storage/gateway-lib').Context, Environment>} */
20+
fetch (request, env, ctx) {
21+
console.log(request.method, request.url)
22+
const middleware = composeMiddleware(
23+
withCdnCache,
24+
withContext,
25+
withCorsHeaders,
26+
withErrorHandler,
27+
createWithHttpMethod('GET', 'HEAD'),
28+
withFixedLengthStream
29+
)
30+
return middleware(handler)(request, env, ctx)
31+
}
32+
}
33+
34+
/**
35+
* @param {Request} request
36+
* @param {Environment} env
37+
*/
38+
async function handler (request, env) {
39+
const url = new URL(request.url)
40+
const key = url.pathname.slice(1)
41+
42+
const object = await env.BUCKET.head(key)
43+
if (!object) throw new HttpError('Object Not Found', { status: 404 })
44+
45+
const headers = new Headers()
46+
headers.set('Etag', object.httpEtag)
47+
48+
if (request.method === 'HEAD') {
49+
headers.set('Accept-Ranges', 'bytes')
50+
headers.set('Content-Length', object.size.toString())
51+
return new Response(undefined, { headers })
52+
}
53+
54+
/** @type {import('multipart-byte-range').Range[]} */
55+
let ranges = []
56+
if (request.headers.has('range')) {
57+
try {
58+
ranges = decodeRangeHeader(request.headers.get('range') ?? '')
59+
} catch (err) {
60+
throw new HttpError('invalid range', { cause: err, status: 400 })
61+
}
62+
}
63+
64+
headers.set('X-Content-Type-Options', 'nosniff')
65+
headers.set('Content-Type', 'application/octet-stream')
66+
headers.set('Etag', object.httpEtag)
67+
headers.set('Cache-Control', 'public, max-age=29030400, immutable')
68+
headers.set('Vary', 'Range')
69+
70+
if (ranges.length > 1) {
71+
return handleMultipartRange(env.BUCKET, key, object.size, ranges, { headers })
72+
} else if (ranges.length === 1) {
73+
return handleRange(env.BUCKET, key, object.size, ranges[0], { headers })
74+
}
75+
76+
// no range is effectively Range: bytes=0-
77+
return handleRange(env.BUCKET, key, object.size, [0], { headers })
78+
}
79+
80+
/**
81+
* @param {import('@cloudflare/workers-types').R2Bucket} bucket
82+
* @param {string} key
83+
* @param {number} size
84+
* @param {import('multipart-byte-range').Range} range
85+
* @param {{ headers?: Headers }} [options]
86+
*/
87+
const handleRange = async (bucket, key, size, range, options) => {
88+
const [first, last] = resolveRange(range, size)
89+
const contentLength = last - first + 1
90+
91+
const headers = new Headers(options?.headers)
92+
headers.set('Content-Length', String(contentLength))
93+
94+
if (size !== contentLength) {
95+
const contentRange = `bytes ${first}-${last}/${size}`
96+
headers.set('Content-Range', contentRange)
97+
}
98+
99+
const status = size === contentLength ? 200 : 206
100+
const object = await bucket.get(key, { range: { offset: first, length: contentLength } })
101+
if (!object || !object.body) throw new HttpError('Object Not Found', { status: 404 })
102+
103+
const source = /** @type {ReadableStream} */ (object.body)
104+
return new Response(source, { status, headers })
105+
}
106+
107+
/**
108+
* @param {import('@cloudflare/workers-types').R2Bucket} bucket
109+
* @param {string} key
110+
* @param {number} size
111+
* @param {import('multipart-byte-range').Range[]} ranges
112+
* @param {{ headers?: Headers }} [options]
113+
*/
114+
const handleMultipartRange = async (bucket, key, size, ranges, options) => {
115+
const source = new MultipartByteRange(ranges, async range => {
116+
const options = { range: { offset: range[0], length: range[1] - range[0] + 1 } }
117+
const object = await bucket.get(key, options)
118+
if (!object || !object.body) throw new HttpError('Object Not Found', { status: 404 })
119+
return /** @type {ReadableStream} */ (object.body)
120+
}, { totalSize: size })
121+
122+
const headers = new Headers(options?.headers)
123+
for (const [k, v] of Object.entries(source.headers)) {
124+
headers.set(k, v)
125+
}
126+
127+
return new Response(source, { status: 206, headers })
128+
}

‎test/worker.spec.js

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { Miniflare } from 'miniflare'
2+
import { equals } from 'uint8arrays'
3+
import { Buffer } from 'buffer'
4+
import * as ByteRanges from 'byteranges'
5+
6+
const mf = new Miniflare({
7+
modules: true,
8+
scriptPath: `${import.meta.dirname}/../dist/worker.mjs`,
9+
compatibilityDate: '2024-05-15',
10+
r2Buckets: ['BUCKET']
11+
})
12+
13+
export const test = {
14+
'should respond 404 when key not found': async (/** @type {import('entail').assert} */ assert) => {
15+
const res = await mf.dispatchFetch('http://localhost:8787/notfound')
16+
assert.equal(res.status, 404)
17+
},
18+
19+
'should GET a value for a key': async (/** @type {import('entail').assert} */ assert) => {
20+
const key = 'test' + Date.now()
21+
const value = new Uint8Array([12, 3])
22+
const bucket = await mf.getR2Bucket('BUCKET')
23+
await bucket.put(key, value)
24+
25+
const res = await mf.dispatchFetch(`http://localhost:8787/${key}`)
26+
assert.equal(res.status, 200)
27+
assert.ok(equals(new Uint8Array(await res.arrayBuffer()), value))
28+
},
29+
30+
'should HEAD a key': async (/** @type {import('entail').assert} */ assert) => {
31+
const key = 'test' + Date.now()
32+
const value = new Uint8Array([1, 3, 8])
33+
const bucket = await mf.getR2Bucket('BUCKET')
34+
await bucket.put(key, value)
35+
36+
const res = await mf.dispatchFetch(`http://localhost:8787/${key}`, { method: 'HEAD' })
37+
assert.equal(res.status, 200)
38+
assert.equal(res.headers.get('Accept-Ranges'), 'bytes')
39+
assert.equal(res.headers.get('Content-Length'), String(value.length))
40+
assert.equal(res.body, null)
41+
},
42+
43+
'should GET a byte range of a value for a key': async (/** @type {import('entail').assert} */ assert) => {
44+
const key = 'test' + Date.now()
45+
const value = new Uint8Array([1, 1, 3, 8])
46+
const range = [1, 3]
47+
const bucket = await mf.getR2Bucket('BUCKET')
48+
await bucket.put(key, value)
49+
50+
const res = await mf.dispatchFetch(`http://localhost:8787/${key}`, {
51+
headers: { Range: `bytes=${range[0]}-${range[1]}` }
52+
})
53+
assert.equal(res.status, 206)
54+
assert.equal(res.headers.get('Content-Range'), `bytes ${range[0]}-${range[1]}/${value.length}`)
55+
assert.ok(equals(new Uint8Array(await res.arrayBuffer()), value.slice(range[0], range[1] + 1)))
56+
},
57+
58+
'should GET a multipart byte range of a value for a key': async (/** @type {import('entail').assert} */ assert) => {
59+
const key = 'test' + Date.now()
60+
const value = new Uint8Array([1, 1, 3, 8, 1, 1, 3, 8])
61+
const ranges = [[1, 3], [6, 7]]
62+
const bucket = await mf.getR2Bucket('BUCKET')
63+
await bucket.put(key, value)
64+
65+
const res = await mf.dispatchFetch(`http://localhost:8787/${key}`, {
66+
headers: { Range: `bytes=${ranges.map(r => `${r[0]}-${r[1]}`).join(', ')}` }
67+
})
68+
assert.equal(res.status, 206)
69+
70+
const contentType = res.headers.get('Content-Type')
71+
assert.ok(contentType)
72+
73+
const boundary = contentType.replace('multipart/byteranges; boundary=', '')
74+
const body = Buffer.from(await res.arrayBuffer())
75+
76+
const parts = ByteRanges.parse(body, boundary)
77+
assert.equal(parts.length, ranges.length)
78+
79+
for (let i = 0; i < parts.length; i++) {
80+
assert.ok(equals(parts[i].octets, value.slice(ranges[i][0], ranges[i][1] + 1)))
81+
}
82+
}
83+
}

‎wrangler.toml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name = "public-bucket"
2+
main = "./dist/worker.mjs"
3+
compatibility_date = "2024-05-15"
4+
r2_buckets = [{ binding = "BUCKET", bucket_name = "carpark-dev-0" }]
5+
6+
[build]
7+
command = "npm run build"
8+
9+
[vars]
10+
DEBUG = "true"
11+
12+
# PROD!
13+
[env.carpark-production]
14+
account_id = "fffa4b4363a7e5250af8357087263b3a"
15+
r2_buckets = [{ binding = "BUCKET", bucket_name = "carpark-prod-0" }]
16+
17+
[env.carpark-production.vars]
18+
DEBUG = "false"
19+
20+
# STAGING!
21+
[env.carpark-staging]
22+
account_id = "fffa4b4363a7e5250af8357087263b3a"
23+
r2_buckets = [{ binding = "BUCKET", bucket_name = "carpark-staging-0" }]

0 commit comments

Comments
 (0)
Please sign in to comment.