Skip to content

Commit

Permalink
Fix image URL parser
Browse files Browse the repository at this point in the history
  • Loading branch information
koyuawsmbrtn committed Sep 22, 2021
1 parent 32612bf commit 7dc26ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gemproxy",
"version": "2.0.0",
"version": "2.0.1",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
Expand Down
26 changes: 6 additions & 20 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,41 +76,27 @@ export default class App extends React.Component {
});
//Display inline-images
$('a[href*=".jpg"]').each(function() {
var cwd = "";
if (!$(this).attr("href").replace("//", "/").includes("gemini:/")) {
cwd = $("#addressbar").val().split("/");
cwd.pop();
cwd = cwd.join("/").replace("gemini://", "");
}
var styles = "";
if ($(this).html().includes("_right")) {
styles = "float:right;padding:5px;";
}
var imguri = config.backend+"api/v1/get/"+$(this).attr("href").replace("//", "/");
imguri = imguri.replaceAll("/gemini:/", "").replaceAll("//", "/").replaceAll(":/", "://");
if (!imguri.replaceAll(config.backend+"api/v1/get/", "").includes("/")) {
imguri = config.backend+"api/v1/get/"+cwd+"/"+imguri.replaceAll(config.backend+"api/v1/get/", "");
var imguri = new URL($(this).attr("href"), config.backend+"api/v1/get/"+$("#addressbar").val().replaceAll("gemini://", "").replaceAll("?", "$")).href;
if (!imguri.includes("/api/v1/get/")) {
imguri = imguri.replaceAll(config.backend, config.backend+"api/v1/get/");
}
$(this).html("<img src=\""+imguri+"\" style=\""+styles+"\" width=\"300\">");
$(this).attr("target", "_blank");
$(this).attr("href", imguri);
$(this).attr("style", "border:0;");
});
$('a[href*=".png"]').each(function() {
var cwd = "";
if (!$(this).attr("href").replace("//", "/").includes("gemini:/")) {
cwd = $("#addressbar").val().split("/");
cwd.pop();
cwd = cwd.join("/").replace("gemini://", "");
}
var styles = "";
if ($(this).html().includes("_right")) {
styles = "float:right;padding:5px;";
}
var imguri = config.backend+"api/v1/get/"+$(this).attr("href").replace("//", "/");
imguri = imguri.replaceAll("/gemini:/", "").replaceAll("//", "/").replaceAll(":/", "://");
if (!imguri.replaceAll(config.backend+"api/v1/get/", "").includes("/")) {
imguri = config.backend+"api/v1/get/"+cwd+"/"+imguri.replaceAll(config.backend+"api/v1/get/", "");
var imguri = new URL($(this).attr("href"), config.backend+"api/v1/get/"+$("#addressbar").val().replaceAll("gemini://", "").replaceAll("?", "$")).href;
if (!imguri.includes("/api/v1/get/")) {
imguri = imguri.replaceAll(config.backend, config.backend+"api/v1/get/");
}
$(this).html("<img src=\""+imguri+"\" style=\""+styles+"\" width=\"300\">");
$(this).attr("target", "_blank");
Expand Down

0 comments on commit 7dc26ee

Please sign in to comment.