This is a simple Directory Listing script for Cloudflare R2 and hosted on Cloudflare Workers. It is inspired by the Directory Listing of Gitea downloads site.
Clone this repository, install dependencies and edit the configs:
git clone https://github.com/cmj2002/r2-dir-list.git
cd r2-dir-list
npm install
mv src/config.ts.example src/config.ts
mv wrangler.toml.example wrangler.toml
You should edit:
bucketname
in src/config.ts
and wrangler.toml
to your bucket name.bucketdomain.example.com
in src/config.ts
and wrangler.toml
to your bucket domain. It must have been set as a custom domain of your Cloudflare R2 bucket.example.com
in wrangler.toml
's zone_name
to yours.name
, desp
, showPoweredBy
and legalInfo
in src/config.ts
to your own.You may want to search bucketdomain
, bucketname
and example.com
in your code to ensure you have edited all of them.
Then you can run wrangler deploy
to deploy it to your Cloudflare Workers.
https://datasets.caomingjun.com/
This is a production website of mine, which hosts some machine learning datasets used in my papers and codes to share with other reserchers. It is a Cloudflare R2 bucket with this worker in front of it.
It will only overwrite the response when all of the following conditions are met:
/
In such a case, it will generate a HTML page with the list of "subdirectories" and "files" under the current "directory" and return it. Otherwise, it will just return the response from R2. So putting this worker in front of your R2 bucket will not affect any normal access to your bucket.