(object: ImmutableObject)
| 77 | } |
| 78 | |
| 79 | export const putObject = async (object: ImmutableObject): Promise<void> => { |
| 80 | if ( |
| 81 | await objectMatches( |
| 82 | object.key, |
| 83 | object.size, |
| 84 | object.sha256, |
| 85 | object.contentType, |
| 86 | ) |
| 87 | ) |
| 88 | return; |
| 89 | if (!object.read) { |
| 90 | throw new Error(`Missing required R2 object ${object.key}`); |
| 91 | } |
| 92 | |
| 93 | const body = await object.read(); |
| 94 | if (body.byteLength !== object.size || sha256(body) !== object.sha256) { |
| 95 | throw new Error(`Object body does not match ${object.key}`); |
| 96 | } |
| 97 | |
| 98 | try { |
| 99 | await client.send( |
| 100 | new PutObjectCommand({ |
| 101 | Bucket: BUCKET, |
| 102 | Key: object.key, |
| 103 | Body: body, |
| 104 | ContentType: object.contentType, |
| 105 | Metadata: { sha256: object.sha256 }, |
| 106 | }), |
| 107 | ); |
| 108 | } catch (error) { |
| 109 | throw new Error(`Unable to upload ${object.key}`, { cause: error }); |
| 110 | } |
| 111 | }; |
| 112 | |
| 113 | export const putSourcePreview = async ( |
| 114 | ctx: FontContext, |
no test coverage detected