Skip to content

Commit

Permalink
Fix severname history entries and their display
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihildt committed Feb 16, 2024
1 parent aac279c commit 67633cd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
18 changes: 9 additions & 9 deletions src/components/Location.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const currentOrAllWebsites = computed(() =>
const setProxy = (
country: string,
countryCode: string,
city: string,
hostname: string,
ipv4_address: string,
city?: string,
port?: number,
) => {
storeSocksProxyUsage({ country, countryCode, city, hostname, ipv4_address });
Expand All @@ -43,7 +43,7 @@ const setProxy = (
}
};
const clickSocksProxy = (
const clickServer = (
country: string,
countryCode: string,
city: string,
Expand All @@ -54,20 +54,20 @@ const clickSocksProxy = (
setProxy(country, countryCode, city, hostname, ipv4_address, port);
};
const clickCountryOrCity = (country: string, city?: string) => {
const { ipv4_address, port, hostname, countryCode } = getRandomSocksProxy({
const clickCountryOrCity = (selectedCountry: string, selectedCity?: string) => {
const { country, countryCode, city, hostname, ipv4_address, port } = getRandomSocksProxy({
socksProxies: proxiesList.value,
country,
city,
country: selectedCountry,
city: selectedCity,
});
setProxy(country, countryCode, hostname, ipv4_address, city, port);
setProxy(country, countryCode, city, hostname, ipv4_address, port);
};
const selectLocation = (connection: HistoryEntry) => {
const { country, countryCode, city, hostname, ipv4_address } = connection;
if (hostname) {
clickSocksProxy(country, countryCode, city!, hostname, ipv4_address!);
clickServer(country, countryCode, city, hostname, ipv4_address!);
} else {
clickCountryOrCity(country, city);
}
Expand Down Expand Up @@ -106,7 +106,7 @@ const selectLocation = (connection: HistoryEntry) => {
secondary
medium
@click="
clickSocksProxy(
clickServer(
country,
proxy.location.countryCode,
city,
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useProxyHistory/HistoryEntries.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type HistoryEntryDetails = {
country: string;
countryCode: string;
city?: string;
city: string;
hostname: string;
ipv4_address?: string;
};
Expand Down
17 changes: 12 additions & 5 deletions src/composables/useProxyHistory/useProxyHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ const { historyEntries } = useStore();
const mostUsed = ref<HistoryEntry[]>([]);
const mostRecent = ref<HistoryEntry[]>([]);

const storeSocksProxyUsage = ({ country, city, hostname, ipv4_address }: HistoryEntryDetails) => {
const storeSocksProxyUsage = ({
country,
countryCode,
city,
hostname,
ipv4_address,
}: HistoryEntryDetails) => {
const keys: string[] = [];
if (country) {
keys.push(country);
Expand All @@ -29,18 +35,19 @@ const storeSocksProxyUsage = ({ country, city, hostname, ipv4_address }: History

data.timestamp = Date.now();
data.count += 1;
data.city = city;
data.country = country;
data.countryCode = countryCode;
data.city = city;
data.hostname = hostname;
data.ipv4_address = ipv4_address;
historyEntries.value[key] = data;
};

const getLabel = (historyEntry: HistoryEntry) => {
const { country, city, hostname } = historyEntry;
const servername = hostname.split('.relays.mullvad.net');
const { country, countryCode, city, hostname } = historyEntry;
const servername = hostname.split('.relays.mullvad.net')[0];

return `${city ? city + ', ' + country : country} (${servername})`;
return `${city ? city + `, ${countryCode.toUpperCase()}` : country} (${servername})`;
};

watchEffect(() => {
Expand Down
11 changes: 10 additions & 1 deletion src/helpers/getRandomSocksProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ const getRandomSocksProxy = ({ socksProxies, country, city }: Props) => {
const index = Math.floor(Math.random() * proxies.length);
const { hostname, ipv4_address, port, location } = proxies[index];

return { hostname, ipv4_address, port, countryCode: location.countryCode };
const randomSocks = {
country: location.country,
city: location.city,
countryCode: location.countryCode,
hostname,
ipv4_address,
port,
};

return randomSocks;
};

export default getRandomSocksProxy;

0 comments on commit 67633cd

Please sign in to comment.