1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-01-18 17:14:08 +01:00

Merge pull request #292 from upscayl/specialchar-fix

fixed preview not working when filename has special characters
This commit is contained in:
Suvojit Ghosh 2023-04-29 22:30:26 +05:30 committed by GitHub
commit f39fac2be0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -481,6 +481,11 @@ const Home = () => {
resetImagePaths();
}
const formatPath = (path) => {
//USE REGEX TO GET THE FILENAME AND ENCODE IT INTO PROPER FORM IN ORDER TO AVOID ERRORS DUE TO SPECIAL CHARACTERS
return path.replace(/([^/\\]+)$/i, encodeURIComponent(path.match(/[^/\\]+$/i)[0]))
}
const allowedFileTypes = ["png", "jpg", "jpeg", "webp"];
const allowedVideoFileTypes = ["webm", "mp4", "mkv"];
@ -620,7 +625,7 @@ const Home = () => {
<img
src={
"file://" +
`${upscaledImagePath ? upscaledImagePath : imagePath}`
`${upscaledImagePath ? formatPath(upscaledImagePath) : formatPath(imagePath)}`
}
onLoad={(e: any) => {
setDimensions({
@ -677,7 +682,7 @@ const Home = () => {
</p>
<img
src={"file://" + imagePath}
src={"file:///" + formatPath(imagePath)}
alt="Original"
onMouseMove={handleMouseMove}
style={{
@ -695,7 +700,7 @@ const Home = () => {
Upscayled
</p>
<img
src={"file://" + upscaledImagePath}
src={"file://" + formatPath(upscaledImagePath)}
alt="Upscayl"
style={{
objectFit: "contain",