Skip to content

Commit c776c71

Browse files
committed
Fix bugs of virtual site
1 parent dd808a5 commit c776c71

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

src/app/components/SiteManage/SiteManageModify/SiteManageHostFormItem.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { defineComponent, ref } from "vue"
1414
import { cvt2SiteKey, cvt2OptionValue, EXIST_MSG, MERGED_MSG, VIRTUAL_MSG, labelOf } from "../common"
1515
import { ALL_HOSTS, MERGED_HOST } from "@util/constant/remain-host"
1616
import siteService from "@service/site-service"
17-
import { isValidVirtualHost } from "@util/pattern"
17+
import { isValidVirtualHost, judgeVirtualFast } from "@util/pattern"
1818

1919
type _OptionInfo = {
2020
siteKey: timer.site.SiteKey
@@ -52,7 +52,12 @@ async function handleRemoteSearch(query: string, searching: Ref<boolean>, search
5252
const existIdx = originalOptions.findIndex(o => o.siteKey?.host === query)
5353
if (existIdx === -1) {
5454
// Not exist host, insert site into the first
55-
result.push({ siteKey: { host: query, virtual: isValidVirtualHost(query) }, hasAlias: false })
55+
const isVirtual = judgeVirtualFast(query)
56+
if (isVirtual) {
57+
isValidVirtualHost(query) && result.push({ siteKey: { host: query, virtual: true }, hasAlias: false })
58+
} else {
59+
result.push({ siteKey: { host: query, virtual: false }, hasAlias: false })
60+
}
5661
result.push(...originalOptions)
5762
} else {
5863
result.push(originalOptions[existIdx])

src/util/pattern.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright (c) 2021 Hengyang Zhang
3-
*
3+
*
44
* This software is released under the MIT License.
55
* https://opensource.org/licenses/MIT
66
*/
@@ -9,8 +9,8 @@ import { SUFFIX_HOST_MAP } from "./constant/remain-host"
99

1010
/**
1111
* Test whether the url belongs to the browser
12-
*
13-
* @param url
12+
*
13+
* @param url
1414
*/
1515
export function isBrowserUrl(url: string) {
1616
return /^chrome.*?:\/\/.*$/.test(url)
@@ -30,8 +30,8 @@ const isNotValidPort = (portStr: string) => {
3030

3131
/**
3232
* Test whether the host is ip or ip and port
33-
*
34-
* @param host
33+
*
34+
* @param host
3535
*/
3636
export function isIpAndPort(host: string) {
3737
host = host.trim()
@@ -49,8 +49,8 @@ export function isIpAndPort(host: string) {
4949

5050
/**
5151
* Test whether the host is a valid host
52-
*
53-
* @param host
52+
*
53+
* @param host
5454
*/
5555
export function isValidHost(host: string) {
5656
if (!host) return false
@@ -70,7 +70,7 @@ export function isValidHost(host: string) {
7070

7171
/**
7272
* Test whether the host is a valid virtual host
73-
*
73+
*
7474
* github.com/ = false
7575
* github.com = false
7676
* github.com/sheepzh = true
@@ -80,25 +80,26 @@ export function isValidHost(host: string) {
8080
* github.com/sheepzh? = false
8181
* github.com/sheepzh?a=1 = false
8282
* http://github.com/123 = false
83-
*
83+
*
8484
* @since 1.6.0
8585
*/
8686
export function isValidVirtualHost(host: string) {
87+
console.log(host)
8788
if (!host) return false
8889
if (host.includes('?') || host.includes('=') || host.includes(":")) return false
8990
// Can't ends with /
9091
if (host.endsWith('/')) return false
91-
const segs = host.split('/')
92+
const segments = host.split('/')
9293
// Can't be normal host
93-
if (segs.length === 1) return false
94-
if (!isValidHost(segs[0])) return false
94+
if (segments.length === 1) return false
95+
if (!isValidHost(segments[0])) return false
9596
return true
9697
}
9798

9899
/**
99-
* Judge virtual host fastly
100-
*
101-
* @param host
100+
* Judge virtual host fast
101+
*
102+
* @param host
102103
* @returns T/F
103104
*/
104105
export function judgeVirtualFast(host: string): boolean {
@@ -156,14 +157,14 @@ export function extractFileHost(url: string): string {
156157
}
157158

158159
/**
159-
* Judge whether homepage
160+
* Judge whether homepage
160161
* e.g.
161162
* 1. https://baidu.com/ = true
162163
* 2. http://baidu.com = true
163164
* 3. www.baidu.com = true
164165
* 4. https://baidu.com/a = false
165166
* 5. http://qq.com?a=1 = false
166-
*
167+
*
167168
* @since 0.5.0
168169
*/
169170
export function isHomepage(url: string) {

0 commit comments

Comments
 (0)