mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-16 05:36:36 +08:00
实现请求连接数等限制/容量组件增加EB支持
This commit is contained in:
@@ -2723,6 +2723,105 @@ Vue.component("http-cache-ref-box", {
|
||||
</tbody>`
|
||||
})
|
||||
|
||||
// 请求限制
|
||||
Vue.component("http-request-limit-config-box", {
|
||||
props: ["v-request-limit-config"],
|
||||
data: function () {
|
||||
let config = this.vRequestLimitConfig
|
||||
if (config == null) {
|
||||
config = {
|
||||
isPrior: false,
|
||||
isOn: false,
|
||||
maxConns: 0,
|
||||
maxConnsPerIP: 0,
|
||||
maxBodySize: {
|
||||
count: -1,
|
||||
unit: "kb"
|
||||
},
|
||||
outBandwidthPerConn: {
|
||||
count: -1,
|
||||
unit: "kb"
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
config: config,
|
||||
maxConns: config.maxConns,
|
||||
maxConnsPerIP: config.maxConnsPerIP
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
maxConns: function (v) {
|
||||
let conns = parseInt(v, 10)
|
||||
if (isNaN(conns)) {
|
||||
this.config.maxConns = 0
|
||||
return
|
||||
}
|
||||
if (conns < 0) {
|
||||
this.config.maxConns = 0
|
||||
} else {
|
||||
this.config.maxConns = conns
|
||||
}
|
||||
},
|
||||
maxConnsPerIP: function (v) {
|
||||
let conns = parseInt(v, 10)
|
||||
if (isNaN(conns)) {
|
||||
this.config.maxConnsPerIP = 0
|
||||
return
|
||||
}
|
||||
if (conns < 0) {
|
||||
this.config.maxConnsPerIP = 0
|
||||
} else {
|
||||
this.config.maxConnsPerIP = conns
|
||||
}
|
||||
}
|
||||
},
|
||||
template: `<div>
|
||||
<input type="hidden" name="requestLimitJSON" :value="JSON.stringify(config)"/>
|
||||
<table class="ui table selectable definition">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="title">是否启用</td>
|
||||
<td>
|
||||
<checkbox v-model="config.isOn"></checkbox>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tbody v-show="config.isOn">
|
||||
<tr>
|
||||
<td>最大并发连接数</td>
|
||||
<td>
|
||||
<input type="text" maxlength="6" v-model="maxConns"/>
|
||||
<p class="comment">为0表示不限制。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>单IP最大并发连接数</td>
|
||||
<td>
|
||||
<input type="text" maxlength="6" v-model="maxConnsPerIP"/>
|
||||
<p class="comment">为0表示不限制。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>单连接带宽限制</td>
|
||||
<td>
|
||||
<size-capacity-box :v-value="config.outBandwidthPerConn" :v-supported-units="['byte', 'kb', 'mb']"></size-capacity-box>
|
||||
<p class="comment">客户端单个请求每秒可以读取的下行流量。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>单请求最大尺寸</td>
|
||||
<td>
|
||||
<size-capacity-box :v-value="config.maxBodySize" :v-supported-units="['byte', 'kb', 'mb', 'gb']"></size-capacity-box>
|
||||
<p class="comment">单个请求能发送的最大内容尺寸。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="margin"></div>
|
||||
</div>`
|
||||
})
|
||||
|
||||
// 浏览条件列表
|
||||
Vue.component("http-request-conds-view", {
|
||||
props: ["v-conds"],
|
||||
@@ -5976,7 +6075,7 @@ Vue.component("http-pages-and-shutdown-box", {
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="comment">开启临时关闭页面时,所有请求的响应都会显示此页面。可用于临时升级网站使用。</p>
|
||||
<p class="comment">开启临时关闭页面时,所有请求都会直接显示此页面。可用于临时升级网站或者禁止用户访问某个网页。</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -6428,6 +6527,7 @@ Vue.component("http-expires-time-config-box", {
|
||||
<td>强制缓存时间</td>
|
||||
<td>
|
||||
<time-duration-box :v-value="expiresTime.duration" @change="notifyChange"></time-duration-box>
|
||||
<p class="comment">从客户端访问的时间开始要缓存的时长。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -11108,7 +11208,7 @@ Vue.component("source-code-box", {
|
||||
})
|
||||
|
||||
Vue.component("size-capacity-box", {
|
||||
props: ["v-name", "v-value", "v-count", "v-unit", "size", "maxlength"],
|
||||
props: ["v-name", "v-value", "v-count", "v-unit", "size", "maxlength", "v-supported-units"],
|
||||
data: function () {
|
||||
let v = this.vValue
|
||||
if (v == null) {
|
||||
@@ -11131,11 +11231,17 @@ Vue.component("size-capacity-box", {
|
||||
vMaxlength = 10
|
||||
}
|
||||
|
||||
let supportedUnits = this.vSupportedUnits
|
||||
if (supportedUnits == null) {
|
||||
supportedUnits = []
|
||||
}
|
||||
|
||||
return {
|
||||
capacity: v,
|
||||
countString: (v.count >= 0) ? v.count.toString() : "",
|
||||
vSize: vSize,
|
||||
vMaxlength: vMaxlength
|
||||
vMaxlength: vMaxlength,
|
||||
supportedUnits: supportedUnits
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@@ -11165,12 +11271,13 @@ Vue.component("size-capacity-box", {
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<select class="ui dropdown" v-model="capacity.unit" @change="change">
|
||||
<option value="byte">字节</option>
|
||||
<option value="kb">KB</option>
|
||||
<option value="mb">MB</option>
|
||||
<option value="gb">GB</option>
|
||||
<option value="tb">TB</option>
|
||||
<option value="pb">PB</option>
|
||||
<option value="byte" v-if="supportedUnits.length == 0 || supportedUnits.$contains('byte')">字节</option>
|
||||
<option value="kb" v-if="supportedUnits.length == 0 || supportedUnits.$contains('kb')">KB</option>
|
||||
<option value="mb" v-if="supportedUnits.length == 0 || supportedUnits.$contains('mb')">MB</option>
|
||||
<option value="gb" v-if="supportedUnits.length == 0 || supportedUnits.$contains('gb')">GB</option>
|
||||
<option value="tb" v-if="supportedUnits.length == 0 || supportedUnits.$contains('tb')">TB</option>
|
||||
<option value="pb" v-if="supportedUnits.length == 0 || supportedUnits.$contains('pb')">PB</option>
|
||||
<option value="eb" v-if="supportedUnits.length == 0 || supportedUnits.$contains('eb')">EB</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>`
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Vue.component("size-capacity-box", {
|
||||
props: ["v-name", "v-value", "v-count", "v-unit", "size", "maxlength"],
|
||||
props: ["v-name", "v-value", "v-count", "v-unit", "size", "maxlength", "v-supported-units"],
|
||||
data: function () {
|
||||
let v = this.vValue
|
||||
if (v == null) {
|
||||
@@ -22,11 +22,17 @@ Vue.component("size-capacity-box", {
|
||||
vMaxlength = 10
|
||||
}
|
||||
|
||||
let supportedUnits = this.vSupportedUnits
|
||||
if (supportedUnits == null) {
|
||||
supportedUnits = []
|
||||
}
|
||||
|
||||
return {
|
||||
capacity: v,
|
||||
countString: (v.count >= 0) ? v.count.toString() : "",
|
||||
vSize: vSize,
|
||||
vMaxlength: vMaxlength
|
||||
vMaxlength: vMaxlength,
|
||||
supportedUnits: supportedUnits
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@@ -56,12 +62,13 @@ Vue.component("size-capacity-box", {
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<select class="ui dropdown" v-model="capacity.unit" @change="change">
|
||||
<option value="byte">字节</option>
|
||||
<option value="kb">KB</option>
|
||||
<option value="mb">MB</option>
|
||||
<option value="gb">GB</option>
|
||||
<option value="tb">TB</option>
|
||||
<option value="pb">PB</option>
|
||||
<option value="byte" v-if="supportedUnits.length == 0 || supportedUnits.$contains('byte')">字节</option>
|
||||
<option value="kb" v-if="supportedUnits.length == 0 || supportedUnits.$contains('kb')">KB</option>
|
||||
<option value="mb" v-if="supportedUnits.length == 0 || supportedUnits.$contains('mb')">MB</option>
|
||||
<option value="gb" v-if="supportedUnits.length == 0 || supportedUnits.$contains('gb')">GB</option>
|
||||
<option value="tb" v-if="supportedUnits.length == 0 || supportedUnits.$contains('tb')">TB</option>
|
||||
<option value="pb" v-if="supportedUnits.length == 0 || supportedUnits.$contains('pb')">PB</option>
|
||||
<option value="eb" v-if="supportedUnits.length == 0 || supportedUnits.$contains('eb')">EB</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>`
|
||||
|
||||
@@ -153,7 +153,7 @@ Vue.component("http-pages-and-shutdown-box", {
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="comment">开启临时关闭页面时,所有请求的响应都会显示此页面。可用于临时升级网站使用。</p>
|
||||
<p class="comment">开启临时关闭页面时,所有请求都会直接显示此页面。可用于临时升级网站或者禁止用户访问某个网页。</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
// 请求限制
|
||||
Vue.component("http-request-limit-config-box", {
|
||||
props: ["v-request-limit-config"],
|
||||
data: function () {
|
||||
let config = this.vRequestLimitConfig
|
||||
if (config == null) {
|
||||
config = {
|
||||
isPrior: false,
|
||||
isOn: false,
|
||||
maxConns: 0,
|
||||
maxConnsPerIP: 0,
|
||||
maxBodySize: {
|
||||
count: -1,
|
||||
unit: "kb"
|
||||
},
|
||||
outBandwidthPerConn: {
|
||||
count: -1,
|
||||
unit: "kb"
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
config: config,
|
||||
maxConns: config.maxConns,
|
||||
maxConnsPerIP: config.maxConnsPerIP
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
maxConns: function (v) {
|
||||
let conns = parseInt(v, 10)
|
||||
if (isNaN(conns)) {
|
||||
this.config.maxConns = 0
|
||||
return
|
||||
}
|
||||
if (conns < 0) {
|
||||
this.config.maxConns = 0
|
||||
} else {
|
||||
this.config.maxConns = conns
|
||||
}
|
||||
},
|
||||
maxConnsPerIP: function (v) {
|
||||
let conns = parseInt(v, 10)
|
||||
if (isNaN(conns)) {
|
||||
this.config.maxConnsPerIP = 0
|
||||
return
|
||||
}
|
||||
if (conns < 0) {
|
||||
this.config.maxConnsPerIP = 0
|
||||
} else {
|
||||
this.config.maxConnsPerIP = conns
|
||||
}
|
||||
}
|
||||
},
|
||||
template: `<div>
|
||||
<input type="hidden" name="requestLimitJSON" :value="JSON.stringify(config)"/>
|
||||
<table class="ui table selectable definition">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="title">是否启用</td>
|
||||
<td>
|
||||
<checkbox v-model="config.isOn"></checkbox>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tbody v-show="config.isOn">
|
||||
<tr>
|
||||
<td>最大并发连接数</td>
|
||||
<td>
|
||||
<input type="text" maxlength="6" v-model="maxConns"/>
|
||||
<p class="comment">为0表示不限制。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>单IP最大并发连接数</td>
|
||||
<td>
|
||||
<input type="text" maxlength="6" v-model="maxConnsPerIP"/>
|
||||
<p class="comment">为0表示不限制。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>单连接带宽限制</td>
|
||||
<td>
|
||||
<size-capacity-box :v-value="config.outBandwidthPerConn" :v-supported-units="['byte', 'kb', 'mb']"></size-capacity-box>
|
||||
<p class="comment">客户端单个请求每秒可以读取的下行流量。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>单请求最大尺寸</td>
|
||||
<td>
|
||||
<size-capacity-box :v-value="config.maxBodySize" :v-supported-units="['byte', 'kb', 'mb', 'gb']"></size-capacity-box>
|
||||
<p class="comment">单个请求能发送的最大内容尺寸。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="margin"></div>
|
||||
</div>`
|
||||
})
|
||||
@@ -116,22 +116,25 @@ window.teaweb = {
|
||||
|
||||
formatBytes: function (bytes) {
|
||||
bytes = Math.ceil(bytes);
|
||||
if (bytes < 1024) {
|
||||
if (bytes < Math.pow(1024, 1)) {
|
||||
return bytes + "B";
|
||||
}
|
||||
if (bytes < 1024 * 1024) {
|
||||
return (Math.round(bytes * 100 / 1024) / 100) + "K";
|
||||
if (bytes < Math.pow(1024, 2)) {
|
||||
return (Math.round(bytes * 100 / Math.pow(1024, 1)) / 100) + "KB";
|
||||
}
|
||||
if (bytes < 1024 * 1024 * 1024) {
|
||||
return (Math.round(bytes * 100 / 1024 / 1024) / 100) + "M";
|
||||
if (bytes < Math.pow(1024, 3)) {
|
||||
return (Math.round(bytes * 100 / Math.pow(1024, 2)) / 100) + "MB";
|
||||
}
|
||||
if (bytes < 1024 * 1024 * 1024 * 1024) {
|
||||
return (Math.round(bytes * 100 / 1024 / 1024 / 1024) / 100) + "G";
|
||||
if (bytes < Math.pow(1024, 4)) {
|
||||
return (Math.round(bytes * 100 / Math.pow(1024, 3)) / 100) + "GB";
|
||||
}
|
||||
if (bytes < 1024 * 1024 * 1024 * 1024 * 1024) {
|
||||
return (Math.round(bytes * 100 / 1024 / 1024 / 1024 / 1024) / 100) + "T";
|
||||
if (bytes < Math.pow(1024, 5)) {
|
||||
return (Math.round(bytes * 100 / Math.pow(1024, 4)) / 100) + "TB";
|
||||
}
|
||||
return (Math.round(bytes * 100 / 1024 / 1024 / 1024 / 1024 / 1024) / 100) + "P";
|
||||
if (bytes < Math.pow(1024, 6)) {
|
||||
return (Math.round(bytes * 100 / Math.pow(1024, 5)) / 100) + "PB";
|
||||
}
|
||||
return (Math.round(bytes * 100 / Math.pow(1024, 6)) / 100) + "EB";
|
||||
},
|
||||
formatNumber: function (x) {
|
||||
if (x == null) {
|
||||
@@ -178,18 +181,24 @@ window.teaweb = {
|
||||
let max = Math.max.apply(this, stats.map(countFunc))
|
||||
let divider = 1
|
||||
let unit = ""
|
||||
if (max >= 1024 * 1024 * 1024 * 1024) {
|
||||
unit = "T"
|
||||
divider = 1024 * 1024 * 1024 * 1024
|
||||
} else if (max >= 1024 * 1024 * 1024) {
|
||||
unit = "G"
|
||||
divider = 1024 * 1024 * 1024
|
||||
} else if (max >= 1024 * 1024) {
|
||||
unit = "M"
|
||||
divider = 1024 * 1024
|
||||
} else if (max >= 1024) {
|
||||
unit = "K"
|
||||
divider = 1024
|
||||
if (max >= Math.pow(1024, 6)) {
|
||||
unit = "EB"
|
||||
divider = Math.pow(1024, 6)
|
||||
} else if (max >= Math.pow(1024, 5)) {
|
||||
unit = "PB"
|
||||
divider = Math.pow(1024, 5)
|
||||
} else if (max >= Math.pow(1024, 4)) {
|
||||
unit = "TB"
|
||||
divider = Math.pow(1024, 4)
|
||||
} else if (max >= Math.pow(1024, 3)) {
|
||||
unit = "GB"
|
||||
divider = Math.pow(1024, 3)
|
||||
} else if (max >= Math.pow(1024, 2)) {
|
||||
unit = "MB"
|
||||
divider = Math.pow(1024, 2)
|
||||
} else if (max >= Math.pow(1024, 1)) {
|
||||
unit = "KB"
|
||||
divider = Math.pow(1024, 1)
|
||||
}
|
||||
return {
|
||||
unit: unit,
|
||||
|
||||
Reference in New Issue
Block a user