Skip to content

Commit

Permalink
feat: deploy to npm
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed May 17, 2024
1 parent f317cb8 commit a43103a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,18 @@ jobs:
registry-url: https://registry.npmjs.org/
cache: 'pnpm'
if: ${{ steps.release.outputs.release_created }}
- name: Install
- name: Install Dependencies
run: pnpm install
if: ${{ steps.release.outputs.release_created }}
- name: Build
run: pnpm build
if: ${{ steps.release.outputs.release_created }}
- name: Deploy to Production
- name: Publish to npm
run: npm publish --access=public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
if: ${{ steps.release.outputs.release_created }}
- name: Deploy to Cloudflare
uses: cloudflare/[email protected]
with:
apiToken: ${{ secrets.CF_TOKEN }}
Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "public-r2-bucket",
"name": "@web3-storage/public-r2-bucket",
"version": "1.1.0",
"description": "Cloudflare worker allowing read access (with byte range request support) to R2 buckets.",
"main": "index.js",
"main": "src/worker.js",
"type": "module",
"private": true,
"scripts": {
Expand All @@ -12,6 +12,9 @@
},
"author": "Alan Shaw",
"license": "Apache-2.0 OR MIT",
"files": [
"src"
],
"devDependencies": {
"@cloudflare/workers-types": "^4.20240512.0",
"buffer": "^6.0.3",
Expand All @@ -34,5 +37,10 @@
"bugs": {
"url": "https://github.com/nftstorage/dagcargo-bucket/issues"
},
"homepage": "https://github.com/nftstorage/dagcargo-bucket#readme"
"homepage": "https://github.com/nftstorage/dagcargo-bucket#readme",
"standard": {
"ignore": [
"*.ts"
]
}
}
9 changes: 9 additions & 0 deletions src/worker.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { R2Bucket } from '@cloudflare/workers-types'

export { R2Bucket }

export interface Environment {
BUCKET: R2Bucket
}

export declare function handler (request: Request, env: Environment): Promise<Response>
10 changes: 3 additions & 7 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ import {
import { HttpError, decodeRangeHeader, resolveRange } from '@web3-storage/gateway-lib/util'
import { MultipartByteRange } from 'multipart-byte-range'

/**
* @typedef {{ BUCKET: import('@cloudflare/workers-types').R2Bucket }} Environment
*/

/**
* @param {Request} request
* @param {Environment} env
* @param {import('./worker.js').Environment} env
*/
const handler = async (request, env) => {
export const handler = async (request, env) => {
const url = new URL(request.url)
const key = url.pathname.slice(1)

Expand Down Expand Up @@ -112,7 +108,7 @@ const handleMultipartRange = async (bucket, key, size, ranges, options) => {
}

export default {
/** @type {import('@web3-storage/gateway-lib').Handler<import('@web3-storage/gateway-lib').Context, Environment>} */
/** @type {import('@web3-storage/gateway-lib').Handler<import('@web3-storage/gateway-lib').Context, import('./worker.js').Environment>} */
fetch (request, env, ctx) {
console.log(request.method, request.url)
const middleware = composeMiddleware(
Expand Down

0 comments on commit a43103a

Please sign in to comment.