Skip to content

Commit

Permalink
feat: update code format and style
Browse files Browse the repository at this point in the history
  • Loading branch information
mezotv committed Sep 15, 2024
1 parent b6baeed commit 7982a1e
Show file tree
Hide file tree
Showing 22 changed files with 2,513 additions and 1,317 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This .env file is used for testing.
# This file should be copied or renamed to .env in order to be used.
# Rename this file to .env to use it in your app!

R2_ACCOUNT_ID=your_account_id
R2_ACCESS_KEY_ID=your_access_key_id
Expand Down
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

17 changes: 0 additions & 17 deletions .eslintrc

This file was deleted.

2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# These are the default owners for the whole repo. They will be requested for review wehen someone opens a pull request.
* @mezotv
38 changes: 38 additions & 0 deletions .github/workflows/pr-lint-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Lint and Build

on:
pull_request:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: latest
- uses: actions/setup-node@v3
with:
node-version: "18.x"
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Run lint
run: pnpm lint

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: latest
- uses: actions/setup-node@v3
with:
node-version: "18.x"
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Run build
run: pnpm build
18 changes: 0 additions & 18 deletions .github/workflows/publish-package.yml

This file was deleted.

35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release to npm

on:
push:
branches:
- main
- prerelease

permissions:
contents: write
issues: write
pull-requests: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: latest
- uses: actions/setup-node@v3
with:
node-version: "20.x"
cache: "pnpm"
- run: pnpm install
- run: pnpm build
- run: pnpm audit signatures
- name: Release
env:
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm semantic-release


5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
node_modules
.env
/coverage
/lib
/tests
/tests-js
/dist
!.gitkeep
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/coverage
/src
/tests
/tests
.env
3 changes: 0 additions & 3 deletions .prettierignore

This file was deleted.

10 changes: 0 additions & 10 deletions .prettierrc

This file was deleted.

72 changes: 44 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# Cloudflare-R2

This is a wrapper of the AWS S3 client library, designed to provide a user-friendly and efficient way to interact with Cloudflare R2 API in Node.js

### Why make this library?

- As of the writing of this README, there is no official Node.js library for Cloudflare R2.
- Interacting with object storage APIs, especially Cloudflare R2, should be simple and straightforward.
This is a fork of the node-cloudflare-r2 wrapper by @f2face, designed to provide a user-friendly and efficient way to interact with Cloudflare R2 API in Node.js

> ⚠ This library is currently in development and is not yet ready for production use. It is subject to change and may contain bugs or other issues. Please use it at your own risk.
Expand All @@ -14,41 +9,49 @@ This is a wrapper of the AWS S3 client library, designed to provide a user-frien
#### npm

```bash
npm install node-cloudflare-r2
npm install @rivo-gg/cloudflare-r2
```

#### pnpm

```bash
pnpm install node-cloudflare-r2
pnpm add @rivo-gg/cloudflare-r2
```

#### yarn

```bash
yarn add @rivo-gg/cloudflare-r2
```

> It is highly recommended that you use a specific version number in your installation to anticipate any breaking changes that may occur in future releases. For example: \
> `npm install node-cloudflare-r2@0.2.0` \
> `npm install @rivo-gg/cloudflare-r2@0.0.1` \
> or \
> `pnpm install [email protected]` \
> `pnpm add @rivo-gg/[email protected]` \
> or \
> `yarn add @rivo-gg/[email protected]` \
> \
> Check the latest version number in the [release page](https://github.com/f2face/cloudflare-r2/releases).
> Check the latest version number in the [release page](https://github.com/rivo-gg/cloudflare-r2/releases).
## Examples

### Basic usage

```javascript
import { R2 } from 'node-cloudflare-r2';
import { R2 } from "@rivo-gg/cloudflare-r2";

// Initialize R2
const r2 = new R2({
accountId: '<YOUR_ACCOUNT_ID>',
accessKeyId: '<YOUR_R2_ACCESS_KEY_ID>',
secretAccessKey: '<YOUR_R2_SECRET_ACCESS_KEY>',
accountId: "<YOUR_ACCOUNT_ID>",
accessKeyId: "<YOUR_R2_ACCESS_KEY_ID>",
secretAccessKey: "<YOUR_R2_SECRET_ACCESS_KEY>",
});

// Initialize bucket instance
const bucket = r2.bucket('<BUCKET_NAME>');
const bucket = r2.bucket("<BUCKET_NAME>");

// [Optional] Provide the public URL(s) of your bucket, if its public access is allowed.
bucket.provideBucketPublicUrl('https://pub-xxxxxxxxxxxxxxxxxxxxxxxxx.r2.dev');
bucket.provideBucketPublicUrl("https://pub-xxxxxxxxxxxxxxxxxxxxxxxxx.r2.dev");

// Check if the bucket exists
console.log(await bucket.exists()); // true
Expand All @@ -57,7 +60,10 @@ console.log(await bucket.exists()); // true
### Upload local file (simple)

```javascript
const upload = await bucket.uploadFile('/path/to/file', 'destination_file_name.ext');
const upload = await bucket.uploadFile(
"/path/to/file",
"destination_file_name.ext"
);
console.log(upload);
/*
{
Expand All @@ -75,7 +81,10 @@ console.log(upload);

```javascript
// Generate signed link that expires after 3600 seconds.
const signedUrl = await bucket.getObjectSignedUrl('destination_file_name.ext', 3600);
const signedUrl = await bucket.getObjectSignedUrl(
"destination_file_name.ext",
3600
);
console.log(signedUrl);
/*
https://bucket-name.cloudflare-account-id.r2.cloudflarestorage.com/destination_file_name.ext?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=...&X-Amz-Date=...&X-Amz-Expires=60&X-Amz-Signature=...&X-Amz-SignedHeaders=host&x-id=GetObject
Expand All @@ -86,16 +95,16 @@ https://bucket-name.cloudflare-account-id.r2.cloudflarestorage.com/destination_f

```javascript
// Upload text content
const content = 'Lorem ipsum';
const uploadContent = await bucket.upload(content, 'lorem-ipsum.txt');
const content = "Lorem ipsum";
const uploadContent = await bucket.upload(content, "lorem-ipsum.txt");
```

```javascript
import { createReadStream } from 'fs';
import { createReadStream } from "fs";

// Upload from fs.createReadStream()
const stream = createReadStream('/path/to/file');
const uploadStream = await bucket.upload(stream, 'destination_file_name2.ext');
const stream = createReadStream("/path/to/file");
const uploadStream = await bucket.upload(stream, "destination_file_name2.ext");
```

### Upload stream (advanced)
Expand All @@ -104,8 +113,15 @@ This `bucket.uploadStream()` method allows uploading big file or piping stream o

```javascript
// Let's say, you want to record a live stream and pipe it directly to your bucket.
import { spawn } from 'child_process';

const streamlink = spawn('streamlink', ['--stdout', '<LIVE_STREAM_HLS_URL>', 'best']);
const uploadLiveStreamVideo = await bucket.uploadStream(streamlink.stdout, 'my_live_stream.ts');
import { spawn } from "child_process";

const streamlink = spawn("streamlink", [
"--stdout",
"<LIVE_STREAM_HLS_URL>",
"best",
]);
const uploadLiveStreamVideo = await bucket.uploadStream(
streamlink.stdout,
"my_live_stream.ts"
);
```
40 changes: 40 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.0/schema.json",
"files": {
"ignore": ["dist/**/*.*", "*.yml"],
"ignoreUnknown": true
},
"vcs": {
"clientKind": "git",
"defaultBranch": "main",
"enabled": true,
"useIgnoreFile": true
},
"formatter": {
"lineWidth": 120
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noCommaOperator": "off",
"noNamespace": "error",
"noNegationElse": "error",
"noNonNullAssertion": "off",
"useCollapsedElseIf": "error",
"useShorthandArrayType": "error",
"useShorthandAssign": "error"
},
"suspicious": {
"noApproximativeNumericConstant": "error",
"noConstEnum": "off",
"noExplicitAny": "off",
"noMisrefactoredShorthandAssign": "error"
}
}
},
"organizeImports": {
"enabled": true
}
}
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-undef */
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
preset: "ts-jest",
testEnvironment: "node",
};
Loading

0 comments on commit 7982a1e

Please sign in to comment.