diff --git a/core/config.go b/core/config.go index bc5c553..10cef44 100644 --- a/core/config.go +++ b/core/config.go @@ -66,7 +66,7 @@ func initConfig() *Config { TaskNumber: runtime.NumCPU() * 2, DownNumber: 3, UserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36", - UseHeaders: "User-Agent,Referer,Authorization,Cookie", + UseHeaders: "default", InsertTail: true, MimeMap: getDefaultMimeMap(), Rule: "*", diff --git a/core/downloader.go b/core/downloader.go index 8f73c6d..83e663d 100644 --- a/core/downloader.go +++ b/core/downloader.go @@ -82,8 +82,41 @@ func (fd *FileDownloader) buildClient() *http.Client { } } +var forbiddenDownloadHeaders = map[string]struct{}{ + "accept-encoding": {}, + "content-length": {}, + "host": {}, + "connection": {}, + "keep-alive": {}, + "proxy-connection": {}, + "transfer-encoding": {}, + + "sec-fetch-site": {}, + "sec-fetch-mode": {}, + "sec-fetch-dest": {}, + "sec-fetch-user": {}, + "sec-ch-ua": {}, + "sec-ch-ua-mobile": {}, + "sec-ch-ua-platform": {}, + + "if-none-match": {}, + "if-modified-since": {}, + + "x-forwarded-for": {}, + "x-real-ip": {}, +} + func (fd *FileDownloader) setHeaders(request *http.Request) { for key, value := range fd.Headers { + if globalConfig.UseHeaders == "default" { + lk := strings.ToLower(key) + if _, forbidden := forbiddenDownloadHeaders[lk]; forbidden { + continue + } + request.Header.Set(key, value) + continue + } + if strings.Contains(globalConfig.UseHeaders, key) { request.Header.Set(key, value) } diff --git a/frontend/src/components/Action.vue b/frontend/src/components/Action.vue index b89826d..63a19c4 100644 --- a/frontend/src/components/Action.vue +++ b/frontend/src/components/Action.vue @@ -23,7 +23,7 @@
-
+
{ result = result.filter(item => item.Description?.toLowerCase().includes(descriptionSearchValue.value.toLowerCase())) } + if (urlSearchValue.value) { + result = result.filter(item => item.Url?.toLowerCase().includes(urlSearchValue.value.toLowerCase())) + } + return result }) @@ -232,6 +236,7 @@ const classify = ref([ ]) const descriptionSearchValue = ref("") +const urlSearchValue = ref("") const rememberChoice = ref(false) const rememberChoiceTmp = ref(false) @@ -240,11 +245,49 @@ const columns = ref([ type: "selection", }, { - title: computed(() => { - return checkedRowKeysValue.value.length > 0 ? h(NGradientText, {type: "success"}, t("index.choice") + `(${checkedRowKeysValue.value.length})`) : t("index.domain") - }), + title: () => { + if (checkedRowKeysValue.value.length > 0) { + return h(NGradientText, {type: "success"}, t("index.choice") + `(${checkedRowKeysValue.value.length})`) + } + return h('div', {class: 'flex items-center'}, [ + t('index.domain'), + h(NPopover, { + style: "--wails-draggable:no-drag", + trigger: 'click', + placement: 'bottom', + showArrow: true, + }, { + trigger: () => h(NIcon, { + size: "18", + class: `ml-1 cursor-pointer ${urlSearchValue.value ? "text-green-600": "text-gray-500"}`, + onClick: (e: MouseEvent) => e.stopPropagation() + }, h(SearchOutline)), + default: () => h('div', {class: 'p-2 w-64'}, [ + h(NInput, { + value: urlSearchValue.value, + 'onUpdate:value': (val: string) => urlSearchValue.value = val, + placeholder: t('index.search_description'), + clearable: true + }, { + prefix: () => h(NIcon, {component: SearchOutline}) + }) + ]) + }) + ]) + }, key: "Domain", width: 90, + render: (row: appType.MediaInfo) => { + return h(NTooltip, { + trigger: 'hover', + placement: 'top' + }, { + trigger: () => h('span', { + class: 'cursor-default' + }, row.Domain), + default: () => row.Url + }) + } }, { title: computed(() => t("index.type")), @@ -590,7 +633,17 @@ const dataAction = (row: appType.MediaInfo, index: number, type: string) => { download(row, index) break case "cancel": - if (row.Status === "running") { + if (row.Status === "pending") { + const queueIndex = downloadQueue.value.findIndex(item => item.Id === row.Id) + if (queueIndex !== -1) { + downloadQueue.value.splice(queueIndex, 1) + } + updateItem(row.Id, item => { + item.Status = 'ready' + item.SavePath = '' + }) + cacheData() + } else if (row.Status === "running") { appApi.cancel({id: row.Id}).then((res) => { updateItem(row.Id, item => { item.Status = 'ready' @@ -696,7 +749,21 @@ const batchCancel = async () => { loading.value = true const cancelTasks: Promise[] = [] data.value.forEach((item, index) => { - if (checkedRowKeysValue.value.includes(item.Id) && item.Status === "running") { + if (!checkedRowKeysValue.value.includes(item.Id)) { + return + } + + if (item.Status === "pending") { + const queueIndex = downloadQueue.value.findIndex(qItem => qItem.Id === item.Id) + if (queueIndex !== -1) { + downloadQueue.value.splice(queueIndex, 1) + } + item.Status = 'ready' + item.SavePath = '' + return + } + + if (item.Status === "running") { if (activeDownloads > 0) { activeDownloads-- } diff --git a/wails.json b/wails.json index 1b1f435..3a28777 100644 --- a/wails.json +++ b/wails.json @@ -13,7 +13,7 @@ "info": { "companyName": "res-downloader", "productName": "res-downloader", - "productVersion": "3.1.2", + "productVersion": "3.1.3", "copyright": "Copyright © 2023", "comments": "This is a high-value high-performance and diverse resource downloader called res-downloader." }