imlinhanchao/vsc-markdown-image

请求对S3上传文件增加CDN支持

Closed this issue · 4 comments

当前S3上传后会生成一个移除认证参数的直接访问S3 Bucket的URL。当Bucket是设置为公开时,在文档中使用这个路径没有问题。当Bucket是设置为私有时,在文档中使用这个路径将无法显示。

参见:https://github.com/imlinhanchao/vsc-markdown-image/blob/master/src/lib/s3.ts#L65

考虑到私有S3 Bucket用于公开站点时一般会搭配CDN一起使用,所以请求增加CDN支持。类似于Github CDN配置。

if (!this.config.s3.cdn) {
    return this.sanitizeURL(encodedURL);
}

const decodedURL = decodeURIComponent(encodedURL);
const urlObject = new URL(decodedURL);

return this.config.s3.cdn
    .replace(/\${bucket}/g, this.config.s3.bucket)
    .replace(/\${region}/g, this.config.s3.region)
    .replace(/\${pathname}/g, urlObject.pathname)
    .replace(/\${filepath}/g, savePath);

OK~ 晚上打包给你试试~

@imlinhanchao 感谢支持。

经测试,可以通过CDN显示私有S3 Bucket内容。

已发布