Skip to content

Commit

Permalink
feat: proxy chain direction
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephyruso committed Jan 6, 2025
1 parent 321df18 commit a385c7a
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 15 deletions.
30 changes: 21 additions & 9 deletions src/components/connections/ConnectionCard.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { disconnectByIdAPI } from '@/api'
import { useConnections } from '@/composables/connections'
import { CONNECTIONS_TABLE_ACCESSOR_KEY } from '@/config'
import { CONNECTIONS_TABLE_ACCESSOR_KEY, PROXY_CHAIN_DIRECTION } from '@/config'
import {
fromNow,
getDestinationFromConnection,
getIPLabelFromMap,
getProcessFromConnection,
prettyBytesHelper,
} from '@/helper'
import { connectionCardLines } from '@/store/settings'
import { connectionCardLines, proxyChainDirection } from '@/store/settings'
import type { Connection } from '@/types'
import {
ArrowDownCircleIcon,
ArrowDownIcon,
ArrowLeftCircleIcon,
ArrowRightCircleIcon,
ArrowUpCircleIcon,
ArrowUpIcon,
Expand All @@ -32,6 +33,23 @@ export default defineComponent<{
name: 'ConnectionCard',
setup(props) {
const { handlerInfo } = useConnections()
const getChains = (chains: string[]) => {
const render =
proxyChainDirection.value === PROXY_CHAIN_DIRECTION.NORMAL
? [last(chains), first(chains)]
: [first(chains), last(chains)]
return (
<>
{render[0]}
{proxyChainDirection.value === PROXY_CHAIN_DIRECTION.NORMAL ? (
<ArrowRightCircleIcon class="h-4 w-4"></ArrowRightCircleIcon>
) : (
<ArrowLeftCircleIcon class="h-4 w-4"></ArrowLeftCircleIcon>
)}
{render[1]}
</>
)
}

return () => {
const componentMap: Record<CONNECTIONS_TABLE_ACCESSOR_KEY, JSX.Element> = {
Expand Down Expand Up @@ -65,13 +83,7 @@ export default defineComponent<{
),
[CONNECTIONS_TABLE_ACCESSOR_KEY.Chains]: (
<span class="flex w-80 grow items-center gap-1 break-all">
{last(props.conn.chains)}
{last(props.conn.chains) !== first(props.conn.chains) && (
<>
<ArrowRightCircleIcon class="h-4 w-4" />
{first(props.conn.chains)}
</>
)}
{getChains(props.conn.chains)}
</span>
),
[CONNECTIONS_TABLE_ACCESSOR_KEY.Download]: (
Expand Down
19 changes: 14 additions & 5 deletions src/components/connections/ConnectionTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
<script setup lang="ts">
import { disconnectByIdAPI } from '@/api'
import { useConnections } from '@/composables/connections'
import { CONNECTIONS_TABLE_ACCESSOR_KEY, TABLE_SIZE } from '@/config'
import { CONNECTIONS_TABLE_ACCESSOR_KEY, PROXY_CHAIN_DIRECTION, TABLE_SIZE } from '@/config'
import {
fromNow,
getDestinationFromConnection,
Expand All @@ -129,10 +129,11 @@ import {
prettyBytesHelper,
} from '@/helper'
import { renderConnections } from '@/store/connections'
import { connectionTableColumns, tableSize } from '@/store/settings'
import { connectionTableColumns, proxyChainDirection, tableSize } from '@/store/settings'
import type { Connection } from '@/types'
import {
ArrowDownCircleIcon,
ArrowLeftCircleIcon,
ArrowRightCircleIcon,
ArrowUpCircleIcon,
InformationCircleIcon,
Expand Down Expand Up @@ -239,13 +240,21 @@ const columns: ColumnDef<Connection>[] = [
accessorFn: (original) => original.chains.join(','),
cell: ({ row }) => {
const chains: VNode[] = []
const modifyChain =
proxyChainDirection.value === PROXY_CHAIN_DIRECTION.NORMAL
? chains.unshift.bind(chains)
: chains.push.bind(chains)
const icon =
proxyChainDirection.value === PROXY_CHAIN_DIRECTION.NORMAL
? ArrowRightCircleIcon
: ArrowLeftCircleIcon
row.original.chains.forEach((chain, index) => {
chains.unshift(h('span', chain))
modifyChain(h('span', chain))
if (index < row.original.chains.length - 1) {
chains.unshift(
h(ArrowRightCircleIcon, {
modifyChain(
h(icon, {
class: 'h-4 w-4',
}),
)
Expand Down
19 changes: 18 additions & 1 deletion src/components/settings/ConnectionsSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
{{ $t('connections') }}
</div>
<div class="card-body">
<div class="flex items-center gap-2">
{{ $t('proxyChainDirection') }}:
<select
class="select select-bordered select-sm w-24"
v-model="proxyChainDirection"
>
<option
v-for="opt in Object.values(PROXY_CHAIN_DIRECTION)"
:key="opt"
:value="opt"
>
{{ $t(opt) }}
</option>
</select>
</div>
<div class="flex items-center gap-2">
{{ $t('connectionStyle') }}:
{{ $t('table') }}
Expand All @@ -26,6 +41,8 @@
<script setup lang="ts">
import ConnectionCardSettings from '@/components/settings/ConnectionCardSettings.vue'
import SourceIPLabels from '@/components/settings/SourceIPLabels.vue'
import { PROXY_CHAIN_DIRECTION } from '@/config'
import { proxyChainDirection, useConnectionCard } from '@/store/settings'
import TableSettings from '@/components/settings/TableSettings.vue'
import { useConnectionCard } from '@/store/settings'
</script>
5 changes: 5 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,8 @@ export enum PROXY_CARD_SIZE {
SMALL = 'small',
LARGE = 'large',
}

export enum PROXY_CHAIN_DIRECTION {
NORMAL = 'normal',
REVERSE = 'reverse',
}
2 changes: 2 additions & 0 deletions src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ const en = {
iconSize: 'Icon Size',
iconMarginRight: 'Icon Margin Right',
allowLan: 'Allow Lan',
proxyChainDirection: 'Proxy Chain Direction',
reverse: 'Reverse',
}

export type LANG_MESSAGE = typeof en
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ const ru: LANG_MESSAGE = {
iconSize: 'Размер иконки',
iconMarginRight: 'Отступ правой иконки',
allowLan: 'Разрешить локальную сеть',
proxyChainDirection: 'Направление цепочки прокси',
reverse: 'Обратное',
}

export default ru
2 changes: 2 additions & 0 deletions src/i18n/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ const zh: LANG_MESSAGE = {
iconSize: '图标尺寸',
iconMarginRight: '图标间距',
allowLan: '允许局域网',
proxyChainDirection: '代理链方向',
reverse: '反向',
}

export default zh
5 changes: 5 additions & 0 deletions src/store/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
FONTS,
LANG,
PROXY_CARD_SIZE,
PROXY_CHAIN_DIRECTION,
PROXY_PREVIEW_TYPE,
PROXY_SORT_TYPE,
TABLE_SIZE,
Expand Down Expand Up @@ -73,6 +74,10 @@ export const iconMarginRight = useStorage('config/icon-margin-right', 4)

// connections
export const useConnectionCard = useStorage('config/use-connecticon-card', window.innerWidth < 640)
export const proxyChainDirection = useStorage(
'config/proxy-chain-direction',
PROXY_CHAIN_DIRECTION.NORMAL,
)
export const tableSize = useStorage<TABLE_SIZE>('config/connecticon-table-size', TABLE_SIZE.SMALL)
export const connectionTableColumns = useStorage<CONNECTIONS_TABLE_ACCESSOR_KEY[]>(
'config/connection-table-columns',
Expand Down

0 comments on commit a385c7a

Please sign in to comment.