Skip to content

Commit

Permalink
feat(digitalcore): searchEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
tomyangsh authored and fzlins committed Sep 4, 2024
1 parent 04606a4 commit 6e23d2e
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
17 changes: 15 additions & 2 deletions resource/sites/digitalcore.club/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,18 @@
}
}
}
}
}
},
"searchEntryConfig": {
"page": "/api/v1/torrents?searchText=$key$",
"resultType": "json",
"requestMethod": "GET",
"parseScriptFile": "getSearchResult.js",
"keepOriginKey": true
},
"searchEntry": [
{
"name": "全部",
"enabled": true
}
]
}
73 changes: 73 additions & 0 deletions resource/sites/digitalcore.club/getSearchResult.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 6e23d2e

Please sign in to comment.