From 6e23d2eb11ab1efc53d328d09a78c87b21596588 Mon Sep 17 00:00:00 2001 From: Tom Yang <20330249+tomyangsh@users.noreply.github.com> Date: Wed, 4 Sep 2024 12:27:16 -0400 Subject: [PATCH] feat(digitalcore): searchEntry --- resource/sites/digitalcore.club/config.json | 17 ++++- .../sites/digitalcore.club/getSearchResult.js | 73 +++++++++++++++++++ 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 resource/sites/digitalcore.club/getSearchResult.js diff --git a/resource/sites/digitalcore.club/config.json b/resource/sites/digitalcore.club/config.json index cfb2a9de3..3799467bc 100644 --- a/resource/sites/digitalcore.club/config.json +++ b/resource/sites/digitalcore.club/config.json @@ -129,5 +129,18 @@ } } } - } -} \ No newline at end of file + }, + "searchEntryConfig": { + "page": "/api/v1/torrents?searchText=$key$", + "resultType": "json", + "requestMethod": "GET", + "parseScriptFile": "getSearchResult.js", + "keepOriginKey": true + }, + "searchEntry": [ + { + "name": "全部", + "enabled": true + } + ] +} diff --git a/resource/sites/digitalcore.club/getSearchResult.js b/resource/sites/digitalcore.club/getSearchResult.js new file mode 100644 index 000000000..e420e3c76 --- /dev/null +++ b/resource/sites/digitalcore.club/getSearchResult.js @@ -0,0 +1,73 @@ +(function(options) { + class Parser { + constructor() { + this.haveData = false; + if (!options.page) { + options.status = ESearchResultParseStatus.needLogin; + return; + } + options.isLogged = true; + this.haveData = true; + } + + /** + * 获取搜索结果 + */ + + getResult() { + if (!this.haveData) { + return []; + } + let site = options.site; + let groups = options.page; + if (groups.length == 0) { + options.status = ESearchResultParseStatus.noTorrents; + return []; + } + let results = []; + try { + groups.forEach(group => { + let data = { + title: group.name, + link: `${site.url}/torrent/${group.id}/${group.name}`, + url: `${site.url}/api/v1/torrents/download/${group.id}`, + size: group.size, + time: Date(group.added), + seeders: group.seeders, + leechers: group.leechers, + completed: '--', + site: options.site, + tags: this.isFree(group.frileech), + entryName: options.entry.name, + category: null, + comments: group.comments, + }; + results.push(data); + }); + if (results.length == 0) { + options.status = ESearchResultParseStatus.noTorrents; + } + } catch (error) { + console.log(error); + options.status = ESearchResultParseStatus.parseError; + options.errorMsg = error.stack; + } + return results; + } + + isFree(frileech) { + let tags = []; + if (frileech == 1) { + tags.push({ + name: "Free", + color: "blue" + }); + } + + return tags; + } + } + + let parser = new Parser(options); + options.results = parser.getResult(); +})(options);