Skip to content
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

[pull] master from SharzyL:master #15

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8e66bb9
chore: bump wrangler and fix package.json
SharzyL Mar 10, 2024
f56107b
feat: handling Content-Disposition
SharzyL Mar 10, 2024
ca1340f
doc: add Content-Disposition related, fix format
SharzyL Mar 10, 2024
a0692fa
test: update tests
SharzyL Mar 10, 2024
08fdc69
[major] bundle static files with js, discard config.json
SharzyL Mar 10, 2024
e905dcf
tests: cleanup
SharzyL Mar 10, 2024
16a8d5c
fix: disable expiration check
SharzyL Mar 10, 2024
4bff359
fix: removed ‘make deploy’ in deploy.yml workflow
SharzyL Mar 10, 2024
7c14e8a
fix[frontend]: unify handling of expiration
SharzyL Mar 10, 2024
4949348
fix: unify handling of suggestUrl, also update doc
SharzyL Mar 10, 2024
30047e8
fix: remove debugging things
SharzyL Mar 10, 2024
96c411e
feat: support cache-control headers
SharzyL Mar 11, 2024
1073dd1
feat: add favicon redirect
SharzyL Mar 11, 2024
653f8c0
feat: support block countries
SharzyL Mar 11, 2024
b3a9a3d
[breaking] feat: disallow slash in paste name
SharzyL Mar 11, 2024
9eaf3c8
[revert] remove blocking country feature
SharzyL Mar 11, 2024
f6cdfc3
chore: remove webpack.config.js
SharzyL Mar 14, 2024
48edbed
chore: reformat scripts/pb
SharzyL Mar 18, 2024
c494bb3
Fix getting paste's admin page
kLiHz Mar 25, 2024
8ad1b8f
Fix deprecated `set-output`
kLiHz Mar 25, 2024
899bcbe
Bump deprecated action versions
kLiHz Mar 25, 2024
c958ba1
refac[tests]: migrate to vitest test framework
SharzyL Apr 11, 2024
757d166
chore: code reformt and cleanup
SharzyL Apr 11, 2024
ff638c8
fix: check url is legal before redirect
SharzyL Apr 11, 2024
68d107c
fix: only print stack for unknown exception
SharzyL Apr 11, 2024
f6de922
feat: allow update passwd
SharzyL Apr 11, 2024
6ef872f
fix: add vFileShim to fix tests
SharzyL Apr 11, 2024
d2609b8
feat[ci]: run tests before deploy
SharzyL Apr 11, 2024
f64741b
tests: add tests for basic auth
SharzyL Apr 12, 2024
2a7b35d
feat: PUT/DELETE requests do not need basic auth
SharzyL Apr 12, 2024
d75ec2a
chore: remove unneeded deploy scripts
SharzyL Apr 12, 2024
660ae4d
refac: split source files
SharzyL Apr 12, 2024
3e2fb4a
feat: add coverage
SharzyL Apr 12, 2024
be3818c
doc: add doc for administration and development
SharzyL Apr 12, 2024
4e84769
fix: avoid inconsitency between lastModified and postedAt
SharzyL Apr 12, 2024
b87e59d
[Fix] import Buffer explicitly
6david9 Apr 13, 2024
4415c63
fix: use isLegalUrl for suggestUrl
SharzyL Apr 12, 2024
81b9d60
feat[ci]: add json-summary coverage type
SharzyL Apr 13, 2024
97365a8
feat[ci]: run tests and report coverage for PR
SharzyL Apr 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 12 additions & 26 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,29 @@ name: Deploy
on:
push:
branches:
- ci-test
- master
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'

jobs:
deploy:
name: deploy
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
- name: "Install Node"
uses: actions/setup-node@v4
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
node-version: "20"
cache: "yarn"

- name: "Setup"
run: yarn install

- name: setup
run: yarn
- name: "Test"
run: yarn test

- name: build
- name: "Deploy"
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
run: |
mkdir dist
make deploy

yarn deploy
61 changes: 61 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: PR tests
on:
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
branch:
- ${{ github.head_ref }}
- "master"

permissions:
contents: read

steps:
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}

- name: "Install Node"
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "yarn"

- name: "Install Deps"
run: yarn install

- name: "Test"
run: yarn coverage

- name: "Upload Coverage"
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.branch }}
path: coverage

report-coverage:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: "Download HEAD coverage artifacts"
uses: actions/download-artifact@v4
with:
name: coverage-${{ github.head_ref }}
path: coverage

- name: "Download master coverage artifacts"
uses: actions/download-artifact@v4
with:
name: coverage-master
path: coverage-master

- name: "Report Coverage"
uses: davelosert/vitest-coverage-report-action@v2
with:
json-summary-compare-path: coverage-master/coverage-summary.json
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ worker/
node_modules/
.cargo-ok

.idea
.idea
.wrangler
coverage
74 changes: 0 additions & 74 deletions Makefile

This file was deleted.

61 changes: 40 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,32 @@ This is a pastebin that can be deployed on Cloudflare workers. Try it on [shz.al

You are free to deploy the pastebin on your own domain if you host your domain on Cloudflare.

Requirements:
1. \*nix environment with bash and basic cli programs. If you are using Windows, try cygwin, WSL or something.
2. GNU make.
3. `node` and `yarn`.
1. Install `node` and `yarn`.

Create two KV namespaces on Cloudflare workers dashboard (one for production, one for test). Remember their IDs. If you do not need testing, simply create one.
2. Create a KV namespace on Cloudflare workers dashboard, remember its ID.

Clone the repository and enter the directory. Login to your Cloudflare account with `wrangler login`. Modify entries in `wrangler.toml` according to your own account information (`account_id`, routes, kv namespace ids are what you need to modify). The `env.preview` section can be safely removed if you do not need a testing deployment. Refer to [Cloudflare doc](https://developers.cloudflare.com/workers/cli-wrangler/configuration) on how to find out these parameters.
3. Clone the repository and enter the directory. Login to your Cloudflare account with `wrangler login`.

Modify the contents in `config.json` (which controls the generation of static pages): `BASE_URL` is the URL of your site (no trailing slash); `FAVICON` is the URL to the favicon you want to use on your site. If you need testing, also modify `config.preview.json`.
4. Modify entries in `wrangler.toml`. Its comments will tell you how.

Deploy and enjoy!
5. Deploy and enjoy!

```shell
$ yarn install
$ make deploy
$ yarn deploy
```

## Auth

If you want a private deployment (only you can upload paste, but everyone can read the paste), add the following entry to your `config.json` (other configurations also contained in the outmost brace):
If you want a private deployment (only you can upload paste, but everyone can read the paste), add the following entry to your `wrangler.toml`.

```json
{
"basicAuth": {
"enabled": true,
"passwd": {
"admin1": "this-is-passwd-1",
"admin2": "this-is-passwd-2"
}
}
}
```toml
[vars.BASIC_AUTH]
user1 = "passwd1"
user2 = "passwd2"
```

Now every access to PUT or POST request, and every access to the index page, requires an HTTP basic auth with the user-password pair listed above. For example:
Now every access to POST request, and every access to static pages, requires an HTTP basic auth with the user-password pair listed above. For example:

```shell
$ curl example-pb.com
Expand All @@ -86,3 +77,31 @@ $ curl -u admin1:this-is-passwd-1 -Fc=@/path/to/file example-pb.com
"isPrivate": false
}
```

## Administration
Delete a paste:
```console
$ yarn delete-paste <name-of-paste>
```

List pastes:
```console
$ yarn wrangler kv:key list --binding PB > kv_list.json
```

## Development

Run a local simulator:
```console
$ yarn dev
```

Run tests:
```console
$ yarn test
```

Run tests with coverage report:
```console
$ yarn coverage
```
5 changes: 0 additions & 5 deletions config.json

This file was deleted.

5 changes: 0 additions & 5 deletions config.preview.json

This file was deleted.

Loading