Skip to content

Commit

Permalink
新增分流5
Browse files Browse the repository at this point in the history
  • Loading branch information
tonquer committed Aug 22, 2022
1 parent 9bb0810 commit dbca6a2
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
DatabaseDownload3 = "https://raw.bika.life/bika-robot/picacg-database/main/data3/"

UpdateVersion = "v1.3.9"
RealVersion = "v1.3.9"
RealVersion = "v1.3.9.1"
TimeVersion = "2022-8-14"

Waifu2xVersion = "1.1.4"
Expand Down Expand Up @@ -79,6 +79,9 @@

ImageServer3 = 'storage.wikawika.xyz' # 分流3 使用的图片服务器

ProxyApiDomain = "api.bika.life"
ProxyImgDomain = "img.bika.life"

ApiDomain = [
"picaapi.picacomic.com",
"post-api.wikawika.xyz"
Expand Down
29 changes: 29 additions & 0 deletions src/interface/ui_login_proxy_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,29 @@ def setupUi(self, LoginProxyWidget):

self.verticalLayout.addLayout(self.horizontalLayout_3)

self.horizontalLayout_13 = QHBoxLayout()
self.horizontalLayout_13.setObjectName(u"horizontalLayout_13")
self.radioButton_5 = QRadioButton(self.scrollAreaWidgetContents)
self.buttonGroup.addButton(self.radioButton_5)
self.radioButton_5.setObjectName(u"radioButton_5")

self.horizontalLayout_13.addWidget(self.radioButton_5)

self.label9 = QLabel(self.scrollAreaWidgetContents)
self.label9.setObjectName(u"label9")
self.label9.setAlignment(Qt.AlignCenter)

self.horizontalLayout_13.addWidget(self.label9)

self.label10 = QLabel(self.scrollAreaWidgetContents)
self.label10.setObjectName(u"label10")
self.label10.setAlignment(Qt.AlignCenter)

self.horizontalLayout_13.addWidget(self.label10)


self.verticalLayout.addLayout(self.horizontalLayout_13)

self.horizontalLayout_7 = QHBoxLayout()
self.horizontalLayout_7.setObjectName(u"horizontalLayout_7")
self.radioButton_4 = QRadioButton(self.scrollAreaWidgetContents)
Expand Down Expand Up @@ -335,6 +358,12 @@ def retranslateUi(self, LoginProxyWidget):
self.radioButton_3.setText(QCoreApplication.translate("LoginProxyWidget", u"\u5206\u6d413", None))
self.label5.setText("")
self.label6.setText("")
#if QT_CONFIG(tooltip)
self.radioButton_5.setToolTip(QCoreApplication.translate("LoginProxyWidget", u"\u5176\u4ed6\u5206\u6d41\u53ef\u4f7f\u7528\u65f6\uff0c\u8bf7\u4e0d\u8981\u4f7f\u7528\u8be5\u5206\u6d41", None))
#endif // QT_CONFIG(tooltip)
self.radioButton_5.setText(QCoreApplication.translate("LoginProxyWidget", u"\u5206\u6d415", None))
self.label9.setText("")
self.label10.setText("")
self.radioButton_4.setText(QCoreApplication.translate("LoginProxyWidget", u"CDN\u5206\u6d41", None))
self.label7.setText("")
self.label8.setText("")
Expand Down
11 changes: 10 additions & 1 deletion src/server/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@ def __init__(self, url, header=None, params=None, method="POST") -> None:
self.method = method
self.isParseRes = True
self.useImgProxy = True
self.isUseHttps = True
self.isUseHttps = bool(Setting.IsUseHttps.value)
self.proxyUrl = ""
if Setting.ProxySelectIndex.value == 5:
host = ToolUtil.GetUrlHost(url)
if host in config.ApiDomain:
self.proxyUrl = config.ProxyApiDomain
elif host in config.ImageDomain:
self.proxyUrl = config.ProxyImgDomain

if Setting.IsHttpProxy.value == 1:
self.proxy = {"http": Setting.HttpProxy.value, "https": Setting.HttpProxy.value}
elif Setting.IsHttpProxy.value == 3:
self.proxy = {}
else:
self.proxy = {"http": None, "https": None}


def __str__(self):
# if Setting.LogIndex.value == 0:
# return self.__class__.__name__
Expand Down
4 changes: 4 additions & 0 deletions src/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def __DealHeaders(self, request, token):
request.headers["authorization"] = self.token
if token:
request.headers["authorization"] = token

host = ToolUtil.GetUrlHost(request.url)
if self.imageServer and host in config.ImageDomain:
if not is_ipaddress(self.imageServer):
Expand All @@ -155,6 +156,9 @@ def __DealHeaders(self, request, token):
if not request.isUseHttps:
request.url = request.url.replace("https://", "http://")

if request.proxyUrl:
request.url = request.url.replace(host, request.proxyUrl+"/"+host)

# host = ToolUtil.GetUrlHost(request.url)
# if self.address and host in config.ApiDomain:
# request.headers["Host"] = host
Expand Down
6 changes: 3 additions & 3 deletions src/server/user_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ def __call__(self, backData):
now = time.time()
for chunk in r.iter_content(chunk_size=1024):
getSize += len(chunk)
# consume = time.time() - now
# if consume >= 5.0:
# break
consume = time.time() - now
if consume >= 3.0:
break
consume = time.time() - now
downloadSize = getSize / consume
speed = ToolUtil.GetDownloadSize(downloadSize)
Expand Down
42 changes: 32 additions & 10 deletions src/view/user/login_proxy_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self):
self.buttonGroup.setId(self.radioButton_2, 2)
self.buttonGroup.setId(self.radioButton_3, 3)
self.buttonGroup.setId(self.radioButton_4, 4)
self.buttonGroup.setId(self.radioButton_5, 5)
self.LoadSetting()
self.UpdateServer()
self.commandLinkButton.clicked.connect(self.OpenUrl)
Expand Down Expand Up @@ -53,6 +54,7 @@ def SetEnabled(self, enabled):
self.radioButton_2.setEnabled(enabled)
self.radioButton_3.setEnabled(enabled)
self.radioButton_4.setEnabled(enabled)
self.radioButton_5.setEnabled(enabled)
self.cdnIp.setEnabled(enabled)
self.httpsBox.setEnabled(enabled)

Expand All @@ -61,27 +63,34 @@ def SpeedTest(self):
self.speedPingNum = 0
self.speedTest = []

for i in range(1, 9):
for i in range(1, 11):
label = getattr(self, "label" + str(i))
label.setText("")

self.speedTest = [("", "", False, 1), ("", "", True, 2)]
self.speedTest = [("", "", False, False, 1), ("", "", True, False, 2)]
i = 3
self.speedTest.append((config.Address[0], config.ImageServer2, False, i))
self.speedTest.append((config.Address[0], config.ImageServer2, False, False, i))
i += 1
self.speedTest.append((config.Address[0], config.ImageServer2, True, i))
self.speedTest.append((config.Address[0], config.ImageServer2, True, False, i))
i += 1
self.speedTest.append((config.Address[1], config.ImageServer3, False, i))
self.speedTest.append((config.Address[1], config.ImageServer3, False, False, i))
i += 1
self.speedTest.append((config.Address[1], config.ImageServer3, True, i))
self.speedTest.append((config.Address[1], config.ImageServer3, True, False, i))
i += 1

PreferCDNIP = self.cdnIp.text()
if PreferCDNIP:
self.speedTest.append((PreferCDNIP, PreferCDNIP, False, i))
self.speedTest.append((PreferCDNIP, PreferCDNIP, False, False, i))
i += 1
self.speedTest.append((PreferCDNIP, PreferCDNIP, True, i))
self.speedTest.append((PreferCDNIP, PreferCDNIP, True, False, i))
i += 1
else:
i += 2

self.speedTest.append(("", "", False, True, i))
i += 1
self.speedTest.append(("", "", True, True, i))
i += 1

self.SetEnabled(False)
self.StartSpeedPing()
Expand All @@ -90,7 +99,7 @@ def StartSpeedPing(self):
if len(self.speedTest) <= self.speedPingNum:
self.StartSpeedTest()
return
address, imageProxy, isHttpProxy, i = self.speedTest[self.speedPingNum]
address, imageProxy, isHttpProxy, isProxyUrl, i = self.speedTest[self.speedPingNum]
httpProxy = self.httpLine.text()
if isHttpProxy and (self.buttonGroup_2.checkedId() == 0 or
(self.buttonGroup_2.checkedId() == 1 and not self.httpLine.text()) or
Expand All @@ -111,6 +120,11 @@ def StartSpeedPing(self):
else:
request.proxy = {"http": None, "https": None}

if isProxyUrl:
request.proxyUrl = config.ProxyApiDomain
else:
request.proxyUrl = ""

if isHttpProxy and self.buttonGroup_2.checkedId() == 2:
self.SetSock5Proxy(True)
else:
Expand Down Expand Up @@ -138,7 +152,7 @@ def StartSpeedTest(self):
self.SetEnabled(True)
return

address, imageProxy, isHttpProxy, i = self.speedTest[self.speedIndex]
address, imageProxy, isHttpProxy, isProxyUrl, i = self.speedTest[self.speedIndex]
httpProxy = self.httpLine.text()
if isHttpProxy and (self.buttonGroup_2.checkedId() == 0 or
(self.buttonGroup_2.checkedId() == 1 and not self.httpLine.text()) or
Expand All @@ -156,6 +170,11 @@ def StartSpeedTest(self):
else:
request.proxy = ""

if isProxyUrl:
request.proxyUrl = config.ProxyImgDomain
else:
request.proxyUrl = ""

if isHttpProxy and self.buttonGroup_2.checkedId() == 2:
self.SetSock5Proxy(True)
else:
Expand Down Expand Up @@ -203,6 +222,9 @@ def UpdateServer(self):
elif Setting.ProxySelectIndex.value == 3:
imageServer = config.ImageServer3
address = config.Address[1]
elif Setting.ProxySelectIndex.value == 5:
imageServer = ""
address = ""
else:
imageServer = Setting.PreferCDNIP.value
address = Setting.PreferCDNIP.value
Expand Down
39 changes: 38 additions & 1 deletion ui/component/ui_login_proxy_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,43 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QRadioButton" name="radioButton_5">
<property name="toolTip">
<string>其他分流可使用时,请不要使用该分流</string>
</property>
<property name="text">
<string>分流5</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QLabel" name="label9">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label10">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
Expand Down Expand Up @@ -431,7 +468,7 @@
<slot>OpenUrl()</slot>
</slots>
<buttongroups>
<buttongroup name="buttonGroup"/>
<buttongroup name="buttonGroup_2"/>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>

0 comments on commit dbca6a2

Please sign in to comment.