Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(asset): add headers to StoreArgs #928

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading