-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(web): enable cdn remote image in preview
- Loading branch information
Showing
8 changed files
with
95 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { imgCdn, imgViewSrc } from '../constants' | ||
import { storage } from './index' | ||
|
||
/** | ||
* 将图片的远程 url 替换为本地图片 | ||
* 格式:域名-文件名 | ||
*/ | ||
export function replaceImg(img: string) { | ||
if (!img) | ||
return imgViewSrc | ||
|
||
if (img.includes('data:image') || img.startsWith(imgCdn)) | ||
return img | ||
|
||
const useCdn = storage<boolean>('useCdn', false) | ||
|
||
if (useCdn) { | ||
const { pathname } = new URL(img) | ||
return `https://cdn.ipfsscan.io/weibo${pathname}` | ||
} | ||
|
||
const name = img.split('/').pop()?.replace(/\?.+/, '') // 同时去除 params | ||
const prefix = img.match(/^(?:https?:\/\/)?([^:\/\n]+)/im)?.[1] // 域名 | ||
|
||
if (!prefix || !name) | ||
return img | ||
return `/assets/img/${prefix}-${name}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.