Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Object storage is a shared port: packages' R2 and S3 adapters move to crates/blobstore | 1 | //! Where packages' files are kept: the `BlobStore` port (crates/blobstore), |
| 2 | //! with R2 behind it on Cloudflare and any S3-compatible storage (MinIO in | |
| 3 | //! the compose file) when self-hosted. BLOB_STORE chooses: `r2` (the | |
| 4 | //! default) or `s3`. | |
| 5 | //! | |
| 6 | //! Files are content-addressed: a blob stored whole is at | |
| 7 | //! `blobs/sha256/<hex>`, and one that came in parts at the key its upload | |
| 8 | //! started with, which the `blobs` table records. Large uploads go up as | |
| 9 | //! multipart parts of one size, as R2 requires (every part but the last | |
| 10 | //! the same size), however the client cut its chunks. | |
| 11 | ||
| 12 | use worker::{Env, Result}; | |
| 13 | ||
| 14 | #[cfg(test)] | |
| 15 | pub use g1t_blobstore::Got; | |
| 16 | pub use g1t_blobstore::{BlobStore, Part, Store, var}; | |
| 17 | ||
| 18 | /// The `BLOBS` bucket; R2's S3 endpoint signs downloads when | |
| 19 | /// R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY, R2_ACCOUNT_ID and R2_BUCKET are | |
| 20 | /// set. Self-hosted: S3_BUCKET, and S3_PUBLIC_ENDPOINT for signed downloads. | |
| 21 | const CONFIG: g1t_blobstore::Config = g1t_blobstore::Config { | |
| 22 | kind: "BLOB_STORE", | |
| 23 | binding: "BLOBS", | |
| 24 | r2_signer: Some(["R2_ACCESS_KEY_ID", "R2_SECRET_ACCESS_KEY", "R2_ACCOUNT_ID", "R2_BUCKET"]), | |
| 25 | s3_bucket: "S3_BUCKET", | |
| 26 | s3_public_endpoint: Some("S3_PUBLIC_ENDPOINT"), | |
| 27 | }; | |
| 28 | ||
| 29 | /// The store this installation keeps packages' files in. | |
| 30 | pub fn from_env(env: &Env) -> Result<Store> { | |
| 31 | Store::from_env(env, &CONFIG) | |
| 32 | } |