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 a1e887f
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 6 deletions.
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
22 changes: 21 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 @@ -27,5 +42,10 @@
import ConnectionCardSettings from '@/components/settings/ConnectionCardSettings.vue'
import SourceIPLabels from '@/components/settings/SourceIPLabels.vue'
import TableSettings from '@/components/settings/TableSettings.vue'
import { useConnectionCard } from '@/store/settings'
import { PROXY_CHAIN_DIRECTION } from '@/config'
import {
proxyChainDirection,
useConnectionCard,
} from '@/store/settings' /* PartiallyEnd: #3632/scriptSetup.vue */
import { proxyChainDirection, 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 a1e887f

Please sign in to comment.