2021-09-29 20:12:27 +08:00
|
|
|
|
// 压缩配置
|
|
|
|
|
|
Vue.component("http-compression-config-box", {
|
2021-10-07 16:47:14 +08:00
|
|
|
|
props: ["v-compression-config", "v-is-location", "v-is-group"],
|
2021-09-29 20:12:27 +08:00
|
|
|
|
mounted: function () {
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
sortLoad(function () {
|
|
|
|
|
|
that.initSortableTypes()
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
data: function () {
|
|
|
|
|
|
let config = this.vCompressionConfig
|
|
|
|
|
|
if (config == null) {
|
|
|
|
|
|
config = {
|
|
|
|
|
|
isPrior: false,
|
|
|
|
|
|
isOn: false,
|
|
|
|
|
|
useDefaultTypes: true,
|
2022-06-27 22:40:12 +08:00
|
|
|
|
types: ["brotli", "gzip", "zstd", "deflate"],
|
2021-09-29 20:12:27 +08:00
|
|
|
|
level: 5,
|
2021-10-18 16:49:19 +08:00
|
|
|
|
decompressData: false,
|
2021-09-29 20:12:27 +08:00
|
|
|
|
gzipRef: null,
|
|
|
|
|
|
deflateRef: null,
|
|
|
|
|
|
brotliRef: null,
|
|
|
|
|
|
minLength: {count: 0, "unit": "kb"},
|
|
|
|
|
|
maxLength: {count: 0, "unit": "kb"},
|
2022-11-08 09:18:13 +08:00
|
|
|
|
mimeTypes: ["text/*", "application/javascript", "application/json", "application/atom+xml", "application/rss+xml", "application/xhtml+xml", "font/*", "image/svg+xml"],
|
2021-09-29 20:12:27 +08:00
|
|
|
|
extensions: [".js", ".json", ".html", ".htm", ".xml", ".css", ".woff2", ".txt"],
|
2022-12-30 12:04:17 +08:00
|
|
|
|
exceptExtensions: [".apk", ".ipa"],
|
2022-12-30 11:43:47 +08:00
|
|
|
|
conds: null,
|
|
|
|
|
|
enablePartialContent: false
|
2021-09-29 20:12:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (config.types == null) {
|
|
|
|
|
|
config.types = []
|
|
|
|
|
|
}
|
|
|
|
|
|
if (config.mimeTypes == null) {
|
|
|
|
|
|
config.mimeTypes = []
|
|
|
|
|
|
}
|
|
|
|
|
|
if (config.extensions == null) {
|
|
|
|
|
|
config.extensions = []
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let allTypes = [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: "Gzip",
|
|
|
|
|
|
code: "gzip",
|
|
|
|
|
|
isOn: true
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: "Deflate",
|
|
|
|
|
|
code: "deflate",
|
|
|
|
|
|
isOn: true
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: "Brotli",
|
|
|
|
|
|
code: "brotli",
|
|
|
|
|
|
isOn: true
|
2022-06-27 22:40:12 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: "ZSTD",
|
|
|
|
|
|
code: "zstd",
|
|
|
|
|
|
isOn: true
|
2021-09-29 20:12:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
let configTypes = []
|
|
|
|
|
|
config.types.forEach(function (typeCode) {
|
|
|
|
|
|
allTypes.forEach(function (t) {
|
|
|
|
|
|
if (typeCode == t.code) {
|
|
|
|
|
|
t.isOn = true
|
|
|
|
|
|
configTypes.push(t)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
allTypes.forEach(function (t) {
|
|
|
|
|
|
if (!config.types.$contains(t.code)) {
|
|
|
|
|
|
t.isOn = false
|
|
|
|
|
|
configTypes.push(t)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
config: config,
|
|
|
|
|
|
moreOptionsVisible: false,
|
|
|
|
|
|
allTypes: configTypes
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
"config.level": function (v) {
|
|
|
|
|
|
let level = parseInt(v)
|
|
|
|
|
|
if (isNaN(level)) {
|
|
|
|
|
|
level = 1
|
|
|
|
|
|
} else if (level < 1) {
|
|
|
|
|
|
level = 1
|
|
|
|
|
|
} else if (level > 10) {
|
|
|
|
|
|
level = 10
|
|
|
|
|
|
}
|
|
|
|
|
|
this.config.level = level
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
isOn: function () {
|
2021-10-07 16:47:14 +08:00
|
|
|
|
return ((!this.vIsLocation && !this.vIsGroup) || this.config.isPrior) && this.config.isOn
|
2021-09-29 20:12:27 +08:00
|
|
|
|
},
|
|
|
|
|
|
changeExtensions: function (values) {
|
|
|
|
|
|
values.forEach(function (v, k) {
|
|
|
|
|
|
if (v.length > 0 && v[0] != ".") {
|
|
|
|
|
|
values[k] = "." + v
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
this.config.extensions = values
|
|
|
|
|
|
},
|
2022-12-30 12:04:17 +08:00
|
|
|
|
changeExceptExtensions: function (values) {
|
|
|
|
|
|
values.forEach(function (v, k) {
|
|
|
|
|
|
if (v.length > 0 && v[0] != ".") {
|
|
|
|
|
|
values[k] = "." + v
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
this.config.exceptExtensions = values
|
|
|
|
|
|
},
|
2021-09-29 20:12:27 +08:00
|
|
|
|
changeMimeTypes: function (values) {
|
|
|
|
|
|
this.config.mimeTypes = values
|
|
|
|
|
|
},
|
|
|
|
|
|
changeAdvancedVisible: function () {
|
|
|
|
|
|
this.moreOptionsVisible = !this.moreOptionsVisible
|
|
|
|
|
|
},
|
|
|
|
|
|
changeConds: function (conds) {
|
|
|
|
|
|
this.config.conds = conds
|
|
|
|
|
|
},
|
|
|
|
|
|
changeType: function () {
|
|
|
|
|
|
this.config.types = []
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
this.allTypes.forEach(function (v) {
|
|
|
|
|
|
if (v.isOn) {
|
|
|
|
|
|
that.config.types.push(v.code)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
initSortableTypes: function () {
|
|
|
|
|
|
let box = document.querySelector("#compression-types-box")
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
Sortable.create(box, {
|
|
|
|
|
|
draggable: ".checkbox",
|
|
|
|
|
|
handle: ".icon.handle",
|
|
|
|
|
|
onStart: function () {
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
onUpdate: function (event) {
|
|
|
|
|
|
let checkboxes = box.querySelectorAll(".checkbox")
|
|
|
|
|
|
let codes = []
|
|
|
|
|
|
checkboxes.forEach(function (checkbox) {
|
|
|
|
|
|
let code = checkbox.getAttribute("data-code")
|
|
|
|
|
|
codes.push(code)
|
|
|
|
|
|
})
|
|
|
|
|
|
that.config.types = codes
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
template: `<div>
|
|
|
|
|
|
<input type="hidden" name="compressionJSON" :value="JSON.stringify(config)"/>
|
|
|
|
|
|
<table class="ui table definition selectable">
|
2021-10-07 16:47:14 +08:00
|
|
|
|
<prior-checkbox :v-config="config" v-if="vIsLocation || vIsGroup"></prior-checkbox>
|
|
|
|
|
|
<tbody v-show="(!vIsLocation && !vIsGroup) || config.isPrior">
|
2021-09-29 20:12:27 +08:00
|
|
|
|
<tr>
|
2022-11-08 09:22:09 +08:00
|
|
|
|
<td class="title">启用内容压缩</td>
|
2021-09-29 20:12:27 +08:00
|
|
|
|
<td>
|
|
|
|
|
|
<div class="ui checkbox">
|
|
|
|
|
|
<input type="checkbox" value="1" v-model="config.isOn"/>
|
|
|
|
|
|
<label></label>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
<tbody v-show="isOn()">
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td>压缩级别</td>
|
|
|
|
|
|
<td>
|
|
|
|
|
|
<select class="ui dropdown auto-width" v-model="config.level">
|
|
|
|
|
|
<option v-for="i in 10" :value="i">{{i}}</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
<p class="comment">级别越高,压缩比例越大。</p>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td>支持的扩展名</td>
|
|
|
|
|
|
<td>
|
|
|
|
|
|
<values-box :values="config.extensions" @change="changeExtensions" placeholder="比如 .html"></values-box>
|
|
|
|
|
|
<p class="comment">含有这些扩展名的URL将会被压缩,不区分大小写。</p>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
2022-12-30 12:04:17 +08:00
|
|
|
|
<tr>
|
|
|
|
|
|
<td>例外扩展名</td>
|
|
|
|
|
|
<td>
|
|
|
|
|
|
<values-box :values="config.exceptExtensions" @change="changeExceptExtensions" placeholder="比如 .html"></values-box>
|
|
|
|
|
|
<p class="comment">含有这些扩展名的URL将<strong>不会</strong>被压缩,不区分大小写。</p>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
2021-09-29 20:12:27 +08:00
|
|
|
|
<tr>
|
|
|
|
|
|
<td>支持的MimeType</td>
|
|
|
|
|
|
<td>
|
|
|
|
|
|
<values-box :values="config.mimeTypes" @change="changeMimeTypes" placeholder="比如 text/*"></values-box>
|
|
|
|
|
|
<p class="comment">响应的Content-Type里包含这些MimeType的内容将会被压缩。</p>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
<more-options-tbody @change="changeAdvancedVisible" v-if="isOn()"></more-options-tbody>
|
|
|
|
|
|
<tbody v-show="isOn() && moreOptionsVisible">
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td>压缩算法</td>
|
|
|
|
|
|
<td>
|
|
|
|
|
|
<div class="ui checkbox">
|
|
|
|
|
|
<input type="checkbox" v-model="config.useDefaultTypes" id="compression-use-default"/>
|
2022-06-27 22:40:12 +08:00
|
|
|
|
<label v-if="config.useDefaultTypes" for="compression-use-default">使用默认顺序<span class="grey small">(brotli、gzip、 zstd、deflate)</span></label>
|
2021-09-29 20:12:27 +08:00
|
|
|
|
<label v-if="!config.useDefaultTypes" for="compression-use-default">使用默认顺序</label>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div v-show="!config.useDefaultTypes">
|
|
|
|
|
|
<div class="ui divider"></div>
|
|
|
|
|
|
<div id="compression-types-box">
|
|
|
|
|
|
<div class="ui checkbox" v-for="t in allTypes" style="margin-right: 2em" :data-code="t.code">
|
|
|
|
|
|
<input type="checkbox" v-model="t.isOn" :id="'compression-type-' + t.code" @change="changeType"/>
|
|
|
|
|
|
<label :for="'compression-type-' + t.code">{{t.name}} <i class="icon list small grey handle"></i></label>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2022-03-23 16:29:56 +08:00
|
|
|
|
<p class="comment" v-show="!config.useDefaultTypes">选择支持的压缩算法和优先顺序,拖动<i class="icon list small grey"></i>图表排序。</p>
|
2021-09-29 20:12:27 +08:00
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
2021-10-18 16:49:19 +08:00
|
|
|
|
<tr>
|
|
|
|
|
|
<td>支持已压缩内容</td>
|
|
|
|
|
|
<td>
|
|
|
|
|
|
<checkbox v-model="config.decompressData"></checkbox>
|
2022-03-23 16:33:20 +08:00
|
|
|
|
<p class="comment">支持对已压缩内容尝试重新使用新的算法压缩;不选中表示保留当前的压缩格式。</p>
|
2021-10-18 16:49:19 +08:00
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
2021-09-29 20:12:27 +08:00
|
|
|
|
<tr>
|
|
|
|
|
|
<td>内容最小长度</td>
|
2021-10-18 16:49:19 +08:00
|
|
|
|
<td>
|
|
|
|
|
|
<size-capacity-box :v-name="'minLength'" :v-value="config.minLength" :v-unit="'kb'"></size-capacity-box>
|
|
|
|
|
|
<p class="comment">0表示不限制,内容长度从文件尺寸或Content-Length中获取。</p>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td>内容最大长度</td>
|
|
|
|
|
|
<td>
|
|
|
|
|
|
<size-capacity-box :v-name="'maxLength'" :v-value="config.maxLength" :v-unit="'mb'"></size-capacity-box>
|
|
|
|
|
|
<p class="comment">0表示不限制,内容长度从文件尺寸或Content-Length中获取。</p>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
2022-12-30 11:43:47 +08:00
|
|
|
|
<tr>
|
|
|
|
|
|
<td>支持Partial<br/>Content</td>
|
|
|
|
|
|
<td>
|
|
|
|
|
|
<checkbox v-model="config.enablePartialContent"></checkbox>
|
|
|
|
|
|
<p class="comment">支持对分区内容(PartialContent)的压缩;除非客户端有特殊要求,一般不需要启用。</p>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
2021-10-18 16:49:19 +08:00
|
|
|
|
<tr>
|
|
|
|
|
|
<td>匹配条件</td>
|
|
|
|
|
|
<td>
|
|
|
|
|
|
<http-request-conds-box :v-conds="config.conds" @change="changeConds"></http-request-conds-box>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
2021-09-29 20:12:27 +08:00
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
<div class="margin"></div>
|
|
|
|
|
|
</div>`
|
|
|
|
|
|
})
|