Skip to content

Commit

Permalink
Save temporary torrents to the torrent_cache folder (cross-seed#556)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmgoodnow authored Nov 28, 2023
1 parent 67af7a5 commit 29dd3a5
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/clients/QBittorrent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { fileFrom } from "fetch-blob/from.js";
import { FormData } from "formdata-polyfill/esm.min.js";
import { unlink, writeFile } from "fs/promises";
import fetch, { BodyInit, Response } from "node-fetch";
import { tmpdir } from "os";
import { join, posix } from "path";
import { InjectionResult } from "../constants.js";
import { appDir } from "../configuration.js";
import { InjectionResult, TORRENT_CACHE_FOLDER } from "../constants.js";
import { CrossSeedError } from "../errors.js";
import { Label, logger, logOnce } from "../logger.js";
import { Metafile } from "../parseTorrent.js";
Expand Down Expand Up @@ -265,14 +265,14 @@ export default class QBittorrent implements TorrentClient {
): Promise<InjectionResult> {
const { duplicateCategories, skipRecheck, dataCategory } =
getRuntimeConfig();
const filename = `${newTorrent.getFileSystemSafeName()}.cross-seed.torrent`;
const tempFilepath = join(appDir(), TORRENT_CACHE_FOLDER, filename);
try {
if (await this.isInfoHashInClient(newTorrent.infoHash)) {
return InjectionResult.ALREADY_EXISTS;
}
const buf = newTorrent.encode();
const filename = `${newTorrent.getFileSystemSafeName()}.cross-seed.torrent`;
const tempFilepath = join(tmpdir(), filename);
await writeFile(tempFilepath, buf, { mode: 0o644 });
await writeFile(tempFilepath, buf, { mode: 0o600 });
const { save_path, isComplete, autoTMM, category } = path
? {
save_path: path,
Expand Down Expand Up @@ -336,17 +336,17 @@ export default class QBittorrent implements TorrentClient {
);
}

unlink(tempFilepath).catch((error) => {
logger.debug(error);
});

return InjectionResult.SUCCESS;
} catch (e) {
logger.debug({
label: Label.QBITTORRENT,
message: `injection failed: ${e.message}`,
});
return InjectionResult.FAILURE;
} finally {
await unlink(tempFilepath).catch((error) => {
logger.debug(error);
});
}
}
}

0 comments on commit 29dd3a5

Please sign in to comment.