fix: showing multiple download options

This commit is contained in:
Chubby Granny Chaser
2024-08-18 01:39:50 +01:00
parent c218070463
commit 42ea35441c
17 changed files with 118 additions and 98 deletions

View File

@@ -6,12 +6,12 @@ import {
GameShopCache,
Repack,
UserPreferences,
UserAuth,
} from "@main/entity";
import type { BetterSqlite3ConnectionOptions } from "typeorm/driver/better-sqlite3/BetterSqlite3ConnectionOptions";
import { databasePath } from "./constants";
import migrations from "./migrations";
import { UserAuth } from "./entity/user-auth";
export const createDataSource = (
options: Partial<BetterSqlite3ConnectionOptions>

View File

@@ -16,11 +16,14 @@ export class Repack {
@Column("text", { unique: true })
title: string;
@Column("text", { unique: true })
/**
* @deprecated Use uris instead
*/
@Column("text", { unique: true, nullable: true })
magnet: string;
/**
* @deprecated
* @deprecated Direct scraping capability has been removed
*/
@Column("int", { nullable: true })
page: number;
@@ -37,6 +40,9 @@ export class Repack {
@ManyToOne(() => DownloadSource, { nullable: true, onDelete: "CASCADE" })
downloadSource: DownloadSource;
@Column("text")
uris: string;
@CreateDateColumn()
createdAt: Date;

View File

@@ -1,16 +1,11 @@
import { downloadSourceRepository } from "@main/repository";
import { registerEvent } from "../register-event";
const getDownloadSources = async (_event: Electron.IpcMainInvokeEvent) => {
return downloadSourceRepository
.createQueryBuilder("downloadSource")
.leftJoin("downloadSource.repacks", "repacks")
.orderBy("downloadSource.createdAt", "DESC")
.loadRelationCountAndMap(
"downloadSource.repackCount",
"downloadSource.repacks"
)
.getMany();
};
const getDownloadSources = async (_event: Electron.IpcMainInvokeEvent) =>
downloadSourceRepository.find({
order: {
createdAt: "DESC",
},
});
registerEvent("getDownloadSources", getDownloadSources);

View File

@@ -18,7 +18,8 @@ const startGameDownload = async (
_event: Electron.IpcMainInvokeEvent,
payload: StartGameDownloadPayload
) => {
const { repackId, objectID, title, shop, downloadPath, downloader } = payload;
const { repackId, objectID, title, shop, downloadPath, downloader, uri } =
payload;
const [game, repack] = await Promise.all([
gameRepository.findOne({
@@ -54,7 +55,7 @@ const startGameDownload = async (
bytesDownloaded: 0,
downloadPath,
downloader,
uri: repack.magnet,
uri,
isDeleted: false,
}
);
@@ -76,7 +77,7 @@ const startGameDownload = async (
shop,
status: "active",
downloadPath,
uri: repack.magnet,
uri,
})
.then((result) => {
if (iconUrl) {

View File

@@ -17,7 +17,7 @@ export const insertDownloadsFromSource = async (
const repacks: QueryDeepPartialEntity<Repack>[] = downloads.map(
(download) => ({
title: download.title,
magnet: download.uris[0],
uris: JSON.stringify(download.uris),
fileSize: download.fileSize,
repacker: downloadSource.name,
uploadDate: download.uploadDate,

View File

@@ -77,54 +77,54 @@ export class HydraApi {
baseURL: import.meta.env.MAIN_VITE_API_URL,
});
this.instance.interceptors.request.use(
(request) => {
logger.log(" ---- REQUEST -----");
logger.log(request.method, request.url, request.params, request.data);
return request;
},
(error) => {
logger.error("request error", error);
return Promise.reject(error);
}
);
// this.instance.interceptors.request.use(
// (request) => {
// logger.log(" ---- REQUEST -----");
// logger.log(request.method, request.url, request.params, request.data);
// return request;
// },
// (error) => {
// logger.error("request error", error);
// return Promise.reject(error);
// }
// );
this.instance.interceptors.response.use(
(response) => {
logger.log(" ---- RESPONSE -----");
logger.log(
response.status,
response.config.method,
response.config.url,
response.data
);
return response;
},
(error) => {
logger.error(" ---- RESPONSE ERROR -----");
// this.instance.interceptors.response.use(
// (response) => {
// logger.log(" ---- RESPONSE -----");
// logger.log(
// response.status,
// response.config.method,
// response.config.url,
// response.data
// );
// return response;
// },
// (error) => {
// logger.error(" ---- RESPONSE ERROR -----");
const { config } = error;
// const { config } = error;
logger.error(
config.method,
config.baseURL,
config.url,
config.headers,
config.data
);
// logger.error(
// config.method,
// config.baseURL,
// config.url,
// config.headers,
// config.data
// );
if (error.response) {
logger.error("Response", error.response.status, error.response.data);
} else if (error.request) {
logger.error("Request", error.request);
} else {
logger.error("Error", error.message);
}
// if (error.response) {
// logger.error("Response", error.response.status, error.response.data);
// } else if (error.request) {
// logger.error("Request", error.request);
// } else {
// logger.error("Error", error.message);
// }
logger.error(" ----- END RESPONSE ERROR -------");
return Promise.reject(error);
}
);
// logger.error(" ----- END RESPONSE ERROR -------");
// return Promise.reject(error);
// }
// );
const userAuth = await userAuthRepository.findOne({
where: { id: 1 },

View File

@@ -8,11 +8,18 @@ export class RepacksManager {
private static repacksIndex = new flexSearch.Index();
public static async updateRepacks() {
this.repacks = await repackRepository.find({
order: {
createdAt: "DESC",
},
});
this.repacks = await repackRepository
.find({
order: {
createdAt: "DESC",
},
})
.then((repacks) =>
repacks.map((repack) => ({
...repack,
uris: JSON.parse(repack.uris),
}))
);
for (let i = 0; i < this.repacks.length; i++) {
this.repacksIndex.remove(i);

View File

@@ -64,6 +64,8 @@ export class WindowManager {
this.loadURL();
this.mainWindow.removeMenu();
WindowManager.mainWindow?.webContents.openDevTools();
this.mainWindow.on("ready-to-show", () => {
if (!app.isPackaged) WindowManager.mainWindow?.webContents.openDevTools();
WindowManager.mainWindow?.show();