Skip to content

Commit

Permalink
Merge branch 'cross-seed:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kantjer01 authored Jul 20, 2023
2 parents 77e1157 + f0287ef commit 25e835d
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 21 deletions.
21 changes: 15 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
FROM node:16
# Build Stage
FROM node:18-alpine AS build-stage
WORKDIR /usr/src/cross-seed
RUN npm install -g npm@9
COPY package*.json ./
RUN npm ci
ENV CONFIG_DIR=/config
ENV DOCKER_ENV=true
RUN npm install -g npm@9 \
&& npm ci
COPY tsconfig.json tsconfig.json
COPY src src
RUN npm run build
RUN npm run build \
&& npm prune --production \
&& rm -rf src tsconfig.json

# Production Stage
FROM node:18-alpine
WORKDIR /usr/src/cross-seed
COPY --from=build-stage /usr/src/cross-seed .
RUN npm link
RUN apk add --no-cache curl
ENV CONFIG_DIR=/config
ENV DOCKER_ENV=true
EXPOSE 2468
WORKDIR /config
ENTRYPOINT ["cross-seed"]
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cross-seed",
"version": "5.3.2",
"version": "5.4.0",
"description": "Query Jackett for cross-seedable torrents",
"scripts": {
"test": "true",
Expand Down
7 changes: 7 additions & 0 deletions src/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ program
.description("Clear the cache of downloaded-and-rejected torrents")
.action(async () => {
await db("decision").del();
await db("indexer").update({
status: null,
retry_after: null,
search_cap: null,
tv_search_cap: null,
movie_search_cap: null,
});
await db.destroy();
});

Expand Down
59 changes: 47 additions & 12 deletions src/torznab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,55 @@ function assembleUrl(
return url.toString();
}

function fetchCaps(indexer: {
async function fetchCaps(indexer: {
id: number;
url: string;
apikey: string;
}): Promise<Caps> {
return fetch(assembleUrl(indexer.url, indexer.apikey, { t: "caps" }))
.then((r) => r.text())
.then(xml2js.parseStringPromise)
.then(parseTorznabCaps);
let response;
try {
response = await fetch(
assembleUrl(indexer.url, indexer.apikey, { t: "caps" })
);
} catch (e) {
const error = new Error(
`Indexer ${indexer.url} failed to respond, check verbose logs`
);
logger.error(error);
logger.debug(e);
throw error;
}

const responseText = await response.text();
if (!response.ok) {
const error = new Error(
`Indexer ${indexer.url} responded with code ${response.status} when fetching caps, check verbose logs`
);
logger.error(error);
logger.debug(
`Response body first 1000 characters: ${responseText.substring(
0,
1000
)}`
);
throw error;
}
try {
const parsedXml = await xml2js.parseStringPromise(responseText);
return parseTorznabCaps(parsedXml);
} catch (_) {
const error = new Error(
`Indexer ${indexer.url} responded with invalid XML when fetching caps, check verbose logs`
);
logger.error(error);
logger.debug(
`Response body first 1000 characters: ${responseText.substring(
0,
1000
)}`
);
throw error;
}
}

function collateOutcomes<Correlator, SuccessReturnType>(
Expand Down Expand Up @@ -334,16 +374,10 @@ async function updateCaps(
const outcomes = await Promise.allSettled<Caps>(
indexers.map((indexer) => fetchCaps(indexer))
);
const { fulfilled, rejected } = collateOutcomes<number, Caps>(
const { fulfilled } = collateOutcomes<number, Caps>(
indexers.map((i) => i.id),
outcomes
);
for (const [indexerId, reason] of rejected) {
logger.warn(
`Failed to reach ${indexers.find((i) => i.id === indexerId).url}`
);
logger.debug(reason);
}

for (const [indexerId, caps] of fulfilled) {
await db("indexer").where({ id: indexerId }).update({
Expand Down Expand Up @@ -379,6 +413,7 @@ export async function validateTorznabUrls() {
tv_search_cap: null,
movie_search_cap: null,
})
.orWhere({ search_cap: false, active: true })
.select({ id: "id", url: "url", apikey: "apikey" });
await updateCaps(enabledIndexersWithoutCaps);

Expand Down

0 comments on commit 25e835d

Please sign in to comment.