Skip to content

Commit

Permalink
fix: changes to code using suggestions from ai
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymous-org-za committed Aug 15, 2024
1 parent d72d5e9 commit 1a52d78
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ You can share your whole collection or select specific items you want to share.
2. Clone this repository and go to the directory
3. Create a copy of the `.env` file `cp .env .env.local` and fill in the details
4. Fill in required settings in `.env.local` (e.g. `PROXY=socks5h://127.0.0.1:9050` if tor is running on your host machine)
5. Get your Prisma database connection string from PlanetScale console and put that in your `.env.local` file
5. Get your Prisma database connection string from Filess console and put that in your `.env.local` file
6. Install the dependencies `npm i`
7. This is a Next.js project so either go with `npm run dev` or `npm run build && npm run start`
8. Head to `localhost:3000` and login
Expand Down
22 changes: 7 additions & 15 deletions src/services/torbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ export const getTorBoxUser = async (apiKey: string) => {
return userData.data.data
} catch (error) {
console.error('Error getting TorBox user data:', (error as any).message);
throw error;
throw new Error(`Failed to get TorBox user data: ${(error as any).message}`);
}
};

export const tbInstantCheck = async (apiKey: string, hashes: string[]) => {
let endpoint = `${config.torboxHostname}/torrents/checkcached?format=list&list_files=true`
for (const hash of hashes) {
endpoint += `&hash=${hash}`;
}
const params = new URLSearchParams({ format: 'list', list_files: 'true' });
hashes.forEach(hash => params.append('hash', hash));
let endpoint = `${config.torboxHostname}/torrents/checkcached`
try {
const response = await axios.get(endpoint, {
headers: {
Expand Down Expand Up @@ -80,7 +79,7 @@ export const createTorBoxTorrent = async (apiKey: string, hashes: string[]) => {
return allResponses
} catch (error) {
console.error("Error creating torrent in TorBox:", (error as any).message)
throw error
throw new Error(`Error creating torrent: ${responseData.detail}`);
}
};

Expand Down Expand Up @@ -117,16 +116,9 @@ export const getTorBoxTorrents = async (
"Authorization": `Bearer ${apiKey}`
}
});
return response.data.data;
return response.data?.data;
} catch (error) {
console.error('Error fetching your TorBox torrents:', (error as any).message);
throw error;
}
};

export const requestDownloadLink = async (
apiKey: string,
id: number
) => {

}
};
5 changes: 2 additions & 3 deletions src/utils/fetchTorrents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ export const fetchTorBox = async (
try {
const magnets = (await getTorBoxTorrents(tbKey)).map((magnetInfo) => {
let mediaType = 'other';
let info = undefined;
let info = {} as ParsedFilename;

const filenames = magnetInfo.files?.map((f) => f.short_name) ?? []
const torrentAndFiles = [magnetInfo.name, ...filenames];
const hasEpisodes = checkArithmeticSequenceInFilenames(filenames);

if (every(torrentAndFiles, (f) => !isVideo({ path: f }))) {
mediaType = 'other';
info = undefined;
info = {} as ParsedFilename;
} else if (
hasEpisodes ||
some(torrentAndFiles, (f) => /s\d\d\d?.?e\d\d\d?/i.test(f)) ||
Expand All @@ -239,7 +239,6 @@ export const fetchTorBox = async (
const date = new Date(magnetInfo.created_at);

if (magnetInfo.size === 0) magnetInfo.size = 1;
let idx = 0;
return {
// score: getReleaseTags(magnetInfo.filename, magnetInfo.size / ONE_GIGABYTE).score,
info,
Expand Down

0 comments on commit 1a52d78

Please sign in to comment.