Skip to content

Commit b7419ea

Browse files
committed
Made metas optional
1 parent d34bdc6 commit b7419ea

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

backend/src/main/java/de/interaapps/pastefy/Pastefy.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ protected void setupConfig() {
103103
.map("PASTEFY_LIST_PASTES", "pastefy.listpastes")
104104
.map("PASTEFY_PUBLIC_STATS", "pastefy.publicstats")
105105
.map("PASTEFY_PUBLIC_PASTES", "pastefy.publicpastes")
106+
.map("PASTEFY_META_TAGS", "pastefy.metatags")
106107

107108
.map("AI_ANTHROPIC_TOKEN", "ai.antrophic.token")
108109

backend/src/main/java/de/interaapps/pastefy/controller/pastes/PasteMetaController.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import de.interaapps.pastefy.controller.HttpController;
55
import de.interaapps.pastefy.model.database.Paste;
66
import org.apache.commons.text.StringEscapeUtils;
7+
import org.javawebstack.http.router.Exchange;
78
import org.javawebstack.http.router.router.annotation.params.Path;
89
import org.javawebstack.http.router.router.annotation.verbs.Get;
910
import org.javawebstack.orm.Repo;
@@ -41,9 +42,12 @@ public class PasteMetaController extends HttpController {
4142
}
4243

4344
@Get("/{paste}")
44-
public String pasteTags(@Path("paste") String pasteId) {
45+
public String pasteTags(Exchange exchange, @Path("paste") String pasteId) {
46+
if (Pastefy.getInstance().getConfig().get("pastefy.metatags", "false").equalsIgnoreCase("true")) return null;
4547
if (html == null || pasteId.length() != 8) return null;
4648

49+
if (!isSocialMediaBot(exchange.header("User-Agent"))) return null;
50+
4751
Paste paste = Paste.get(pasteId);
4852

4953
if (paste == null || paste.isPrivate() || paste.isEncrypted()) return null;
@@ -80,4 +84,27 @@ private String tagsToHTML(Map<String, String> map){
8084
});
8185
return out.toString();
8286
}
87+
88+
public static boolean isSocialMediaBot(String userAgent) {
89+
if (userAgent == null) return false;
90+
91+
String[] socialMediaBots = {
92+
"Twitterbot", // Twitter
93+
"facebookexternalhit", // Facebook
94+
"Instagram", // Instagram
95+
"Googlebot", // Google
96+
"LinkedInBot", // LinkedIn
97+
"Pinterest", // Pinterest
98+
"Slackbot", // Slack
99+
"WhatsApp" // WhatsApp
100+
};
101+
102+
// Check if userAgent contains any social media bot signature
103+
for (String bot : socialMediaBots) {
104+
if (userAgent.contains(bot)) {
105+
return true; // Bot found
106+
}
107+
}
108+
return false; // No bot found
109+
}
83110
}

0 commit comments

Comments
 (0)