@alltiptop/geoip-3xui-rules
Version:
Middleware server to set routing rules by countries for XRAY
39 lines (38 loc) • 1.46 kB
JavaScript
import { XuiApi } from '3x-ui';
export const get3xui = async ({ panelAddress, username, password, inboundIds, debug = false, }) => {
try {
const api = new XuiApi(`https://${username}:${password}@${panelAddress.split('://')[1]}`);
const inbound = await api.getInbounds();
api.debug = debug;
api.stdTTL = 30;
const getUserTags = (subscriptionId) => {
const allClients = inbound
.filter((inbound) => inboundIds.includes(inbound.id))
.flatMap((inbound) => inbound.settings.clients);
const client = allClients.find((client) => client.subId === subscriptionId);
const comment = client?.comment || '';
// Regex: capture sequence after 'tags=' up to ;, newline, or another key=value segment
const tagRegex = /tags=([\s\S]*?)(?=(?:\s+\S+=)|;|\n|$)/g;
const out = [];
let match;
while ((match = tagRegex.exec(comment))) {
const segment = match[1];
segment
.split(',')
.map((s) => s.trim())
.filter(Boolean)
.forEach((t) => out.push(t));
}
return Array.from(new Set(out));
};
return {
getUserTags,
};
}
catch (error) {
console.error(error);
return {
getUserTags: () => [],
};
}
};