Skip to content

Commit

Permalink
feat(asset): add headers to StoreArgs (#928)
Browse files Browse the repository at this point in the history
* add headers to StoreArgs

* fix
  • Loading branch information
chenyan-dfinity authored Sep 13, 2024
1 parent cad8bde commit 6310461
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/assets/src/canisters/assets_idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ export const idlFactory = ({ IDL }) => {
const ClearArguments = IDL.Record({});
const BatchId = IDL.Nat;
const Key = IDL.Text;
const HeaderField = IDL.Tuple(IDL.Text, IDL.Text);
const CreateAssetArguments = IDL.Record({
key: Key,
content_type: IDL.Text,
headers: IDL.Opt(IDL.Vec(HeaderField)),
});
const UnsetAssetContentArguments = IDL.Record({
key: Key,
Expand All @@ -25,7 +27,6 @@ export const idlFactory = ({ IDL }) => {
SetAssetContent: SetAssetContentArguments,
Clear: ClearArguments,
});
const HeaderField = IDL.Tuple(IDL.Text, IDL.Text);
const HttpRequest = IDL.Record({
url: IDL.Text,
method: IDL.Text,
Expand Down
1 change: 1 addition & 0 deletions packages/assets/src/canisters/assets_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type ClearArguments = Record<string, never>;
export interface CreateAssetArguments {
key: Key;
content_type: string;
headers: [] | [Array<HeaderField>];
}

export interface DeleteAssetArguments {
Expand Down
8 changes: 7 additions & 1 deletion packages/assets/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ export interface StoreConfig {
* @default File/Blob object type or type from file name extension
*/
contentType?: string;
/**
* Custom headers to be sent with the asset
* @default []
*/
headers?: Array<[string, string]>;
/**
* Content encoding
* @default 'identity'
Expand Down Expand Up @@ -330,9 +335,10 @@ class AssetManagerBatch {
}),
);
await readable.close();
const headers: [] | [[string,string][]] = config?.headers ? [config.headers] : [];
return [
{
CreateAsset: { key, content_type: config?.contentType ?? readable.contentType },
CreateAsset: { key, content_type: config?.contentType ?? readable.contentType, headers },
},
{
SetAssetContent: {
Expand Down

0 comments on commit 6310461

Please sign in to comment.