MCPcopy Create free account
hub / github.com/fontsource/fontsource / putObject

Function putObject

registry/scripts/r2.ts:79–111  ·  view source on GitHub ↗
(object: ImmutableObject)

Source from the content-addressed store, hash-verified

77}
78
79export 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
113export const putSourcePreview = async (
114 ctx: FontContext,

Callers 3

r2.test.tsFile · 0.90
publishArchiveFunction · 0.90
putSourcePreviewFunction · 0.70

Calls 3

sha256Function · 0.90
objectMatchesFunction · 0.85
sendMethod · 0.65

Tested by

no test coverage detected