mirror of
https://github.com/hzrd149/blossom.git
synced 2025-12-09 07:08:50 +00:00
47 lines
2.2 KiB
Markdown
47 lines
2.2 KiB
Markdown
# BUD-04
|
|
|
|
## Mirroring blobs
|
|
|
|
`draft` `optional`
|
|
|
|
Defines the `/mirror` endpoint
|
|
|
|
## PUT /mirror - Mirror Blob
|
|
|
|
A server MAY expose a `PUT /mirror` endpoint to allow users to copy a blob from a URL instead of uploading it
|
|
|
|
Clients MUST pass the URL of the remote blob as a stringified JSON object in the request body
|
|
|
|
```jsonc
|
|
// request body...
|
|
{
|
|
"url": "https://cdn.satellite.earth/b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553.pdf"
|
|
}
|
|
```
|
|
|
|
Clients MAY set the `Authorization` header to an upload authorization event defined in [BUD-02](./02.md#upload-authorization-required). When using authorization, the event MUST be of type "upload".
|
|
|
|
The `/mirror` endpoint MUST download the blob from the specified URL and verify that there is at least one `x` tag in the authorization event matching the sha256 hash of the download blob
|
|
|
|
**Multiple `x` tags in the authorization event MUST NOT be interpreted as the user requesting to mirror multiple blobs.**
|
|
|
|
The endpoint MUST return a [Blob Descriptor](#blob-descriptor) and a `2xx` status code if the mirroring was successful
|
|
or a `4xx` status code and error message if it was not.
|
|
|
|
The destination server SHOULD use the `Content-Type` header returned from the origin server to infer the mime type of
|
|
the blob. If the `Content-Type` header is not present the destination server SHOULD attempt to detect the `Content-Type`
|
|
from the blob contents and file extension, falling back to `application/octet-stream` if it cannot determine the type.
|
|
|
|
Servers MAY use the `Content-Length` header to determine the size of the blob.
|
|
|
|
Servers MAY reject a mirror request for any reason and MUST respond with the appropriate HTTP `4xx` status code and an error message explaining the reason for the rejection.
|
|
|
|
## Example Flow
|
|
|
|
1. Client signs an `upload` authorization event and uploads blob to Server A
|
|
1. Server A returns a [Blob Descriptor](./02.md#blob-descriptor) with the `url`
|
|
1. Client sends the `url` to Server B `/mirror` using the original `upload` authorization event
|
|
1. Server B downloads the blob from Server A using the `url`
|
|
1. Server B verifies the downloaded blob hash matches the `x` tag in the authorization event
|
|
1. Server B returns a [Blob Descriptor](./02.md#blob-descriptor)
|