A very simple online image hosting service.
-
Clone this repository.
-
Create a GitHub Personal Access Token with access to repository contents. A classic token can use the
reposcope. -
Create a dedicated private repository to store the images.
-
Install dependencies with
npm install. -
Create the access-time KV namespace:
npx wrangler kv namespace create IMAGE_ACCESS
-
Copy the returned namespace ID into
wrangler.tomlby uncommenting and completing this block:[[kv_namespaces]] binding = "IMAGE_ACCESS" id = "YOUR_KV_NAMESPACE_ID"
-
Configure the GitHub credentials and target repository:
npx wrangler secret put GithubPAT npx wrangler secret put GithubOwner npx wrangler secret put GithubRepo
-
Build and deploy the Worker, its static assets, and the daily Cron Trigger:
npm run deploy
Cron Triggers use UTC and may take several minutes to propagate after deployment. To exercise the scheduled handler locally with wrangler dev, request http://localhost:8787/cdn-cgi/handler/scheduled.
Deleting a file normally leaves its content in Git history. This repository includes a second cleanup stage under target-repository/:
scripts/purge-deleted-image-history.shfinds root-level image files that are absent fromHEADand whose latest deletion commit is at least seven days old. It removes those paths from the branch's entire history withgit-filter-repo..github/workflows/purge-deleted-image-history.ymlruns the script every day at04:23 UTCand performs a lease-protected force-push only when history changed.
Deploy these two files in the dedicated target image repository, not only in this application repository. From a checkout of this project, copy them into a checkout of the target repository:
cp -R target-repository/.github /path/to/image-data/
mkdir -p /path/to/image-data/scripts
cp target-repository/scripts/purge-deleted-image-history.sh /path/to/image-data/scripts/
chmod +x /path/to/image-data/scripts/purge-deleted-image-history.shCommit and push the copied files in the target repository. Then:
- Open the target repository's Settings → Actions → General and set Workflow permissions to Read and write permissions.
- Ensure the default branch permits this workflow to force-push. Branch protection or rulesets that reject force-pushes must be adjusted for this dedicated repository.
- Keep the target repository dedicated to image storage, with one active branch and no tags that retain old image objects. The supplied workflow rewrites and pushes only the branch on which it runs.
- Run Purge deleted image history → Run workflow once to verify the setup.
The push uses --force-with-lease. If an upload changes the target branch while cleanup is running, the push fails safely instead of overwriting that upload; the next daily run can retry. History rewrites change commit IDs and invalidate old clones, so do not install this workflow in a general-purpose source repository. GitHub may also take time to compact unreachable server-side objects, so displayed repository size may not fall immediately.
This project is licensed under the terms of the GNU General Public License v3.0.