mirror of
https://github.com/JOYCEQL/magic-resume.git
synced 2026-06-02 07:43:34 +02:00
fix: photo link http proxy
This commit is contained in:
@@ -3,6 +3,7 @@ import React, { useState, useRef, useEffect } from "react";
|
|||||||
import { motion } from "framer-motion";
|
import { motion } from "framer-motion";
|
||||||
import { Upload, X } from "lucide-react";
|
import { Upload, X } from "lucide-react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
|
import { toast } from "sonner";
|
||||||
import {
|
import {
|
||||||
Drawer,
|
Drawer,
|
||||||
DrawerContent,
|
DrawerContent,
|
||||||
@@ -118,16 +119,31 @@ const PhotoConfigDrawer: React.FC<Props> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUrlChange = (e: string) => {
|
const handleUrlChange = async (e: string) => {
|
||||||
const url = e;
|
const url = e;
|
||||||
setImageUrl(url);
|
try {
|
||||||
setPreviewUrl(url);
|
// images.weserv.nl proxy
|
||||||
updateBasicInfo({
|
const proxyUrl = `https://images.weserv.nl/?url=${encodeURIComponent(
|
||||||
photo: url,
|
url
|
||||||
});
|
)}`;
|
||||||
const blob = new Blob([url], { type: "image/png" });
|
|
||||||
const blobUrl = URL.createObjectURL(blob);
|
const img = new Image();
|
||||||
localStorage.setItem("photo", blobUrl);
|
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
img.onload = resolve;
|
||||||
|
img.onerror = reject;
|
||||||
|
img.src = proxyUrl;
|
||||||
|
});
|
||||||
|
|
||||||
|
setImageUrl(proxyUrl);
|
||||||
|
setPreviewUrl(proxyUrl);
|
||||||
|
updateBasicInfo({
|
||||||
|
photo: proxyUrl,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("图片加载失败:", error);
|
||||||
|
toast.error("图片链接无效或无法访问,请尝试使用其他图片链接");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDragOver = (e: React.DragEvent<HTMLDivElement>) => {
|
const handleDragOver = (e: React.DragEvent<HTMLDivElement>) => {
|
||||||
@@ -419,10 +435,10 @@ const PhotoConfigDrawer: React.FC<Props> = ({
|
|||||||
{radius === "none"
|
{radius === "none"
|
||||||
? "无"
|
? "无"
|
||||||
: radius === "medium"
|
: radius === "medium"
|
||||||
? "中等"
|
? "中等"
|
||||||
: radius === "full"
|
: radius === "full"
|
||||||
? "圆形"
|
? "圆形"
|
||||||
: "自定义"}
|
: "自定义"}
|
||||||
</Button>
|
</Button>
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user