Files
kevisual-oss/src/util/extract-standard-headers.ts
abearxiong 6411e42b3a chore(build): 优化依赖和配置文件管理
- .gitignore 中新增 .env 文件忽略规则并保留示例文件
- package.json 中新增 src 文件夹纳入发布文件范围
- 升级 devDependencies 中部分包版本并新增 AWS SDK 和 es-toolkit 等依赖
- 移除 lodash 改用 es-toolkit 的 omit 函数以减小包体积
- 使用 dotenv 的解构导入替换默认导入,规范配置加载方式
- util 模块导出新增 extract-standard-headers 功能模块接口
2026-01-08 00:45:48 +08:00

45 lines
1.5 KiB
TypeScript

export const standardHeaderKeys = ['content-type', 'cache-control', 'content-disposition', 'content-encoding', 'content-language', 'expires'];
export type StandardHeaders = {
ContentType?: string;
CacheControl?: string;
ContentDisposition?: string;
ContentEncoding?: string;
ContentLanguage?: string;
Expires?: Date;
};
/**
* 从元数据中提取标准头部和自定义元数据
* @param metaData 原始元数据
* @returns 标准头部和自定义元数据
*/
export function extractStandardHeaders(metaData: Record<string, string>): {
standardHeaders: StandardHeaders;
customMetadata: Record<string, string>;
} {
const standardHeaders: StandardHeaders = {};
const customMetadata: Record<string, string> = {};
for (const [key, value] of Object.entries(metaData)) {
const lowerKey = key.toLowerCase();
if (lowerKey === 'content-type') {
standardHeaders.ContentType = value;
} else if (lowerKey === 'cache-control') {
standardHeaders.CacheControl = value;
} else if (lowerKey === 'content-disposition') {
standardHeaders.ContentDisposition = value;
} else if (lowerKey === 'content-encoding') {
standardHeaders.ContentEncoding = value;
} else if (lowerKey === 'content-language') {
standardHeaders.ContentLanguage = value;
} else if (lowerKey === 'expires') {
standardHeaders.Expires = new Date(value);
} else {
customMetadata[key] = value;
}
}
return { standardHeaders, customMetadata };
}