优化URL重定向逻辑,增加对本地开发环境的检测,确保在非目标域名访问时进行重定向,同时在本地环境中跳过重定向,提升开发体验。移除图像下载功能中的水印绘制代码,简化下载逻辑,提升代码可读性。
This commit is contained in:
@@ -757,10 +757,18 @@ export default function Home() {
|
||||
// 检查是否在浏览器环境中
|
||||
if (typeof window !== 'undefined') {
|
||||
const currentUrl = window.location.href;
|
||||
const currentHostname = window.location.hostname;
|
||||
const targetDomain = 'https://perlerbeads.zippland.com/';
|
||||
|
||||
// 检查当前URL是否不是目标域名
|
||||
if (!currentUrl.startsWith(targetDomain)) {
|
||||
// 排除localhost和127.0.0.1等本地开发环境
|
||||
const isLocalhost = currentHostname === 'localhost' ||
|
||||
currentHostname === '127.0.0.1' ||
|
||||
currentHostname.startsWith('192.168.') ||
|
||||
currentHostname.startsWith('10.') ||
|
||||
currentHostname.endsWith('.local');
|
||||
|
||||
// 检查当前URL是否不是目标域名,且不是本地开发环境
|
||||
if (!currentUrl.startsWith(targetDomain) && !isLocalhost) {
|
||||
console.log(`当前URL: ${currentUrl}`);
|
||||
console.log(`目标URL: ${targetDomain}`);
|
||||
console.log('正在重定向到官方域名...');
|
||||
@@ -783,6 +791,8 @@ export default function Home() {
|
||||
|
||||
// 执行重定向
|
||||
window.location.replace(redirectUrl);
|
||||
} else if (isLocalhost) {
|
||||
console.log(`检测到本地开发环境 (${currentHostname}),跳过重定向`);
|
||||
}
|
||||
}
|
||||
}, []); // 只在组件首次挂载时执行
|
||||
|
||||
@@ -421,44 +421,6 @@ export async function downloadImage({
|
||||
M * downloadCellSize
|
||||
);
|
||||
|
||||
// 添加水印 - 小红书标识,防止被截图去除
|
||||
// 主水印:放在网格右下角,带背景设计,清晰明显
|
||||
const watermarkFontSize = Math.max(12, Math.floor(downloadCellSize * 0.7));
|
||||
|
||||
// 计算主水印位置和尺寸
|
||||
const mainWatermarkText = '小红书@七卡瓦';
|
||||
ctx.font = `600 ${watermarkFontSize}px system-ui, -apple-system, sans-serif`;
|
||||
const textMetrics = ctx.measureText(mainWatermarkText);
|
||||
const textWidth = textMetrics.width;
|
||||
const textHeight = watermarkFontSize;
|
||||
|
||||
const mainWatermarkX = extraLeftMargin + axisLabelSize + N * downloadCellSize - textWidth - 15;
|
||||
const mainWatermarkY = titleBarHeight + extraTopMargin + axisLabelSize + M * downloadCellSize - 15;
|
||||
|
||||
// 绘制水印背景 - 半透明白色背景,增强可读性
|
||||
const bgPadding = 6;
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.85)';
|
||||
ctx.beginPath();
|
||||
ctx.roundRect(
|
||||
mainWatermarkX - bgPadding,
|
||||
mainWatermarkY - textHeight - bgPadding,
|
||||
textWidth + bgPadding * 2,
|
||||
textHeight + bgPadding * 2,
|
||||
4
|
||||
);
|
||||
ctx.fill();
|
||||
|
||||
// 绘制水印边框 - 细边框增加设计感
|
||||
ctx.strokeStyle = 'rgba(0, 0, 0, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.stroke();
|
||||
|
||||
// 绘制水印文字 - 深色,清晰可见
|
||||
ctx.fillStyle = '#374151'; // 深灰色,清晰但不刺眼
|
||||
ctx.textAlign = 'left';
|
||||
ctx.textBaseline = 'bottom';
|
||||
ctx.fillText(mainWatermarkText, mainWatermarkX, mainWatermarkY);
|
||||
|
||||
// 副水印:放在网格左上角,简洁版本
|
||||
const secondaryWatermarkFontSize = Math.max(10, Math.floor(downloadCellSize * 0.5));
|
||||
const secondaryText = '@七卡瓦';
|
||||
@@ -490,8 +452,6 @@ export async function downloadImage({
|
||||
ctx.textBaseline = 'bottom';
|
||||
ctx.fillText(secondaryText, secondaryWatermarkX, secondaryWatermarkY);
|
||||
|
||||
|
||||
|
||||
// 绘制统计信息
|
||||
if (includeStats && colorCounts) {
|
||||
const colorKeys = Object.keys(colorCounts).sort(sortColorKeys);
|
||||
|
||||
Reference in New Issue
Block a user