Skip to content

Commit 216a3ac

Browse files
init. fix
1 parent ad65501 commit 216a3ac

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

backend/src/main/java/io/easystartup/suggestfeature/utils/WebPageExtractorUtil.java

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
import org.jsoup.nodes.Element;
99
import org.jsoup.select.Elements;
1010

11+
import java.io.BufferedReader;
1112
import java.io.IOException;
13+
import java.io.InputStreamReader;
14+
import java.net.HttpURLConnection;
1215
import java.net.MalformedURLException;
1316
import java.net.URL;
1417

@@ -50,6 +53,7 @@ private static WebPageData extractWebPageInfo(String url) throws IOException {
5053
doc = Jsoup.connect(url).userAgent(USER_AGENT).get();
5154
} catch (Exception e) {
5255
LOGGER.error("Error extracting web page info " + url, e);
56+
doc = Jsoup.parse(getHtmlContentManually(url), url);
5357
}
5458

5559
if (doc == null) {
@@ -131,10 +135,31 @@ private static String extractLogo(Document doc, String url) {
131135
}
132136

133137
// If not found, try to find a prominent image
134-
Elements images = doc.select("img[src~=(?i)\\.(png|jpe?g)]");
138+
// Find images with src containing svg, png, jpg, jpeg
139+
// or <object type="image/svg+xml" data="https://fdn.gsmarena.com/vv/assets12/i/logo.svg"><img src="https://fdn.gsmarena.com/vv/assets12/i/logo-fallback.gif" alt="GSMArena.com"></object>
140+
141+
try {
142+
for (Element element : doc.select("object[type=image/svg+xml]")) {
143+
if (element.hasAttr("data")) {
144+
String data = element.absUrl("data");
145+
if (data.contains("logo") && data.startsWith("http")) {
146+
return data;
147+
}
148+
}
149+
}
150+
} catch (Throwable ignore) {
151+
}
152+
153+
Elements images = doc.select("img[src~=(?i)\\.(svg|png|jpe?g)]");
135154
for (Element image : images) {
136155
if (image.hasAttr("alt") && image.attr("alt").toLowerCase().contains("logo")) {
137156
return image.absUrl("src");
157+
} else if (image.hasAttr("title") && image.attr("title").toLowerCase().contains("logo")) {
158+
return image.absUrl("src");
159+
} else if (image.hasAttr("class") && image.attr("class").toLowerCase().contains("logo")) {
160+
return image.absUrl("src");
161+
} else if (image.absUrl("src").contains("logo")) {
162+
return image.absUrl("src");
138163
}
139164
}
140165

@@ -170,4 +195,26 @@ public String getLogo() {
170195
return logo;
171196
}
172197
}
198+
199+
private static String getHtmlContentManually(String url) throws IOException {
200+
URL obj = new URL(url);
201+
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
202+
con.setRequestMethod("GET");
203+
con.setRequestProperty("User-Agent", USER_AGENT);
204+
205+
int responseCode = con.getResponseCode();
206+
if (responseCode == HttpURLConnection.HTTP_OK) {
207+
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
208+
String inputLine;
209+
StringBuilder response = new StringBuilder();
210+
while ((inputLine = in.readLine()) != null) {
211+
response.append(inputLine);
212+
}
213+
in.close();
214+
return response.toString();
215+
} else {
216+
LOGGER.error("Manual HTTP GET request failed." + url + " Response Code: " + responseCode);
217+
}
218+
return null;
219+
}
173220
}

frontend/src/app/create-org/page.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ const CreateOrgForm: React.FC = () => {
159159
<CardContent>
160160
<div className="grid gap-6">
161161
<div className="grid gap-2">
162-
<Label htmlFor="orgUrl">Your Organization Website URL (To auto populate logo and favicon)</Label>
162+
<Label htmlFor="orgUrl">
163+
Your Organization Website URL (To auto populate logo and favicon) <span className='text-muted-foreground'>(Optional)</span>
164+
165+
</Label>
163166
<div className="flex gap-2">
164167
<Input
165168
id="orgUrl"
@@ -176,7 +179,9 @@ const CreateOrgForm: React.FC = () => {
176179
{(favicon || logo) && (
177180
<div className="grid gap-4">
178181
<div>
179-
<Label className="block mb-2">Logo</Label>
182+
<Label className="block mb-2">
183+
Logo <span className='text-muted-foreground'>(Optional)</span>
184+
</Label>
180185
<div className='flex items-center space-x-4'>
181186
<div className="w-20 h-20">
182187
<ImageComponent src={logo} alt="Logo" className="w-full h-full" />
@@ -193,7 +198,9 @@ const CreateOrgForm: React.FC = () => {
193198
</div>
194199
</div>
195200
<div>
196-
<Label className="block mb-2">Favicon</Label>
201+
<Label className="block mb-2">
202+
Favicon <span className='text-muted-foreground'>(Optional)</span>
203+
</Label>
197204
<div className='flex items-center space-x-4'>
198205
<div className="w-20 h-20">
199206
<ImageComponent src={favicon} alt="Favicon" className="w-full h-full" />

0 commit comments

Comments
 (0)