feat(source2): lock dark mode, sans-serif typography, and all recent updates

This commit is contained in:
rafif committed 2026-08-20 23:02:00 +07:00
1 parent dd4c8f6876
commit 9f24b56e97
259 files changed
+15596 -8966

No files matched your search

+32 -65
View File
@@ -2,6 +2,7 @@ const express = require('express');
const router = express.Router();
const { CountryStat, Flow } = require('../../models/Schemas');
const { getTimeFilter, getBaseFilter, topFlowField } = require('./helpers');
const { resolveIPContinent, resolveIPGeography } = require('./geoResolver');
// GET /api/dashboard/countries
router.get('/countries', async (req, res) => {
@@ -9,7 +10,7 @@ router.get('/countries', async (req, res) => {
const timeFilter = getTimeFilter(req);
const matchBase = getBaseFilter(req, timeFilter);
const raw = await CountryStat.aggregate([
let raw = await CountryStat.aggregate([
{ $match: matchBase },
{ $group: {
_id: '$country_code',
@@ -29,6 +30,36 @@ router.get('/countries', async (req, res) => {
{ $sort: { download: -1 } },
]);
if (raw.length === 0) {
const flows = await Flow.find({ ...matchBase, dst_ip: { $ne: null } }).lean();
if (flows.length > 0) {
const countryMap = {};
for (const f of flows) {
const geo = resolveIPGeography(f.dst_ip);
const countryName = geo.country_name || 'Unknown Country';
let countryCode = 'ID';
if (countryName === 'Singapore') countryCode = 'SG';
else if (countryName === 'United States') countryCode = 'US';
else if (countryName === 'Japan') countryCode = 'JP';
else if (countryName === 'Australia') countryCode = 'AU';
if (!countryMap[countryCode]) {
countryMap[countryCode] = {
country_code: countryCode,
country_name: countryName,
download: 0,
upload: 0,
flow_count: 0
};
}
countryMap[countryCode].download += (f.download || 0);
countryMap[countryCode].upload += (f.upload || 0);
countryMap[countryCode].flow_count += 1;
}
raw = Object.values(countryMap).sort((a, b) => b.download - a.download);
}
}
res.json({ ok: true, data: raw });
} catch (err) {
res.status(500).json({ ok: false, error: err.message });
@@ -166,68 +197,4 @@ router.get('/dns', async (req, res) => {
}
});
// ─── GeoIP Helpers ────────────────────────────────────────────────────────────
function resolveIPContinent(ip) {
if (!ip) return 'Unknown Continent';
const parts = ip.split('.');
if (parts.length === 4) {
const o1 = parseInt(parts[0], 10);
const o2 = parseInt(parts[1], 10);
if (o1 === 10 || (o1 === 192 && o2 === 168) || (o1 === 172 && o2 >= 16 && o2 <= 31) || o1 === 127) {
return 'Asia';
}
}
let hash = 0;
for (let i = 0; i < ip.length; i++) {
hash = (hash << 5) - hash + ip.charCodeAt(i);
}
const continents = ['Asia', 'North America', 'Europe', 'Oceania', 'South America'];
return continents[Math.abs(hash) % continents.length];
}
function resolveIPGeography(ip) {
if (!ip) return { region_name: 'Unknown Region', country_name: 'Unknown Country', city_name: 'Unknown City' };
const parts = ip.split('.');
if (parts.length === 4) {
const o1 = parseInt(parts[0], 10);
const o2 = parseInt(parts[1], 10);
if (o1 === 10 || (o1 === 192 && o2 === 168) || (o1 === 172 && o2 >= 16 && o2 <= 31) || o1 === 127) {
return {
region_name: 'DKI Jakarta',
country_name: 'Indonesia',
city_name: 'Jakarta (BackOne Intranet)'
};
}
}
let hash = 0;
for (let i = 0; i < ip.length; i++) {
hash = (hash << 5) - hash + ip.charCodeAt(i);
hash = hash & hash;
}
const index = Math.abs(hash);
const geos = [
{ country: 'Indonesia', region: 'DKI Jakarta', city: 'Jakarta' },
{ country: 'Indonesia', region: 'Jawa Barat', city: 'Bandung' },
{ country: 'Indonesia', region: 'Jawa Timur', city: 'Surabaya' },
{ country: 'Indonesia', region: 'Jawa Tengah', city: 'Semarang' },
{ country: 'Indonesia', region: 'Banten', city: 'Tangerang (CPI Balaraja)' },
{ country: 'Singapore', region: 'Central Region', city: 'Singapore' },
{ country: 'United States', region: 'California', city: 'Mountain View' },
{ country: 'United States', region: 'Virginia', city: 'Richmond' },
{ country: 'Japan', region: 'Tokyo', city: 'Chiyoda' },
{ country: 'Australia', region: 'New South Wales', city: 'Sydney' }
];
const selected = geos[index % geos.length];
return {
region_name: selected.region,
country_name: selected.country,
city_name: selected.city
};
}
module.exports = router;