fix CI, clean up java

This commit is contained in:
Egor 2026-01-16 00:04:30 -08:00
parent 7e57556da7
commit e633d6f29c
4 changed files with 10 additions and 149 deletions

View file

@ -1,29 +0,0 @@
package io.heckel.ntfy.util;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
/**
* This class represents an emoji.
*
* This class was originally written by Vincent DURMONT (vdurmont@gmail.com) as part of
* https://github.com/vdurmont/emoji-java, but has since been heavily stripped and modified.
*/
public class Emoji {
private final List<String> aliases;
private final String unicode;
protected Emoji(List<String> aliases, byte... bytes) {
this.aliases = Collections.unmodifiableList(aliases);
this.unicode = new String(bytes, StandardCharsets.UTF_8);
}
public List<String> getAliases() {
return this.aliases;
}
public String getUnicode() {
return this.unicode;
}
}

View file

@ -1,70 +0,0 @@
package io.heckel.ntfy.util;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
/**
* Loads the emojis from a JSON database.
*
* This was originally written to load
* https://github.com/vdurmont/emoji-java/blob/master/src/main/resources/emojis.json
*
* But now uses
* https://github.com/github/gemoji/blob/master/db/emoji.json
*
* This class was originally written by Vincent DURMONT (vdurmont@gmail.com) as part of
* https://github.com/vdurmont/emoji-java, but has since been heavily stripped and modified.
*/
public class EmojiLoader {
public static List<Emoji> loadEmojis(InputStream stream) throws IOException, JSONException {
JSONArray emojisJSON = new JSONArray(inputStreamToString(stream));
List<Emoji> emojis = new ArrayList<Emoji>(emojisJSON.length());
for (int i = 0; i < emojisJSON.length(); i++) {
Emoji emoji = buildEmojiFromJSON(emojisJSON.getJSONObject(i));
if (emoji != null) {
emojis.add(emoji);
}
}
return emojis;
}
private static String inputStreamToString(
InputStream stream
) throws IOException {
StringBuilder sb = new StringBuilder();
InputStreamReader isr = new InputStreamReader(stream, StandardCharsets.UTF_8);
BufferedReader br = new BufferedReader(isr);
String read;
while((read = br.readLine()) != null) {
sb.append(read);
}
br.close();
return sb.toString();
}
protected static Emoji buildEmojiFromJSON(
JSONObject json
) throws JSONException {
if (!json.has("emoji")) {
return null;
}
byte[] bytes = json.getString("emoji").getBytes(StandardCharsets.UTF_8);
List<String> aliases = jsonArrayToStringList(json.getJSONArray("aliases"));
return new Emoji(aliases, bytes);
}
private static List<String> jsonArrayToStringList(JSONArray array) throws JSONException {
List<String> strings = new ArrayList<String>(array.length());
for (int i = 0; i < array.length(); i++) {
strings.add(array.getString(i));
}
return strings;
}
}

View file

@ -1,46 +0,0 @@
package io.heckel.ntfy.util;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Holds the loaded emojis and provides search functions.
*
* This class was originally written by Vincent DURMONT (vdurmont@gmail.com) as part of
* https://github.com/vdurmont/emoji-java, but has since been heavily stripped and modified.
*/
public class EmojiManager {
private static final String PATH = "/emoji.json"; // https://github.com/github/gemoji/blob/master/db/emoji.json
private static final Map<String, Emoji> EMOJIS_BY_ALIAS = new HashMap<String, Emoji>();
static {
try {
InputStream stream = EmojiLoader.class.getResourceAsStream(PATH);
List<Emoji> emojis = EmojiLoader.loadEmojis(stream);
for (Emoji emoji : emojis) {
for (String alias : emoji.getAliases()) {
EMOJIS_BY_ALIAS.put(alias, emoji);
}
}
stream.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static Emoji getForAlias(String alias) {
if (alias == null || alias.isEmpty()) {
return null;
}
return EMOJIS_BY_ALIAS.get(trimAlias(alias));
}
private static String trimAlias(String alias) {
int len = alias.length();
return alias.substring(
alias.charAt(0) == ':' ? 1 : 0,
alias.charAt(len - 1) == ':' ? len - 1 : len);
}
}

View file

@ -1,5 +1,5 @@
import Imap from 'imap';
import chalk from 'chalk';
import Imap from 'imap';
const PROTON_BRIDGE_HOST = process.env.PROTON_BRIDGE_HOST || 'protonmail-bridge';
const PROTON_BRIDGE_PORT = Number.parseInt(process.env.PROTON_BRIDGE_PORT || '143', 10);
@ -14,15 +14,21 @@ const VERBOSE = process.env.VERBOSE === 'true';
const log = (...args: unknown[]) => VERBOSE && console.log(...args);
if (!BRIDGE_IMAP_USERNAME || !BRIDGE_IMAP_PASSWORD) {
console.error(chalk.red('Missing required env vars: BRIDGE_IMAP_USERNAME and BRIDGE_IMAP_PASSWORD'));
console.error(
chalk.yellow('Run: docker run --rm -it -v proton-bridge-data:/root shenxn/protonmail-bridge init'),
chalk.red('Missing required env vars: BRIDGE_IMAP_USERNAME and BRIDGE_IMAP_PASSWORD'),
);
console.error(
chalk.yellow(
'Run: docker run --rm -it -v proton-bridge-data:/root shenxn/protonmail-bridge init',
),
);
console.error(chalk.yellow('Then use `login` and `info` commands to get IMAP credentials'));
process.exit(1);
}
console.log(chalk.blue(`🔗 Connecting to Proton Bridge at ${PROTON_BRIDGE_HOST}:${PROTON_BRIDGE_PORT}`));
console.log(
chalk.blue(`🔗 Connecting to Proton Bridge at ${PROTON_BRIDGE_HOST}:${PROTON_BRIDGE_PORT}`),
);
console.log(chalk.blue(`📨 Monitoring mailbox: ${BRIDGE_IMAP_USERNAME}`));
console.log(chalk.blue(`🔔 Sending notifications to: ${SUP_SERVER_URL}/notify/${SUP_TOPIC}`));