Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port and search anime issues are fixed. #34

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ backend/video/segments
downloads

*.exe
backend/lisa
backend/lisa

env/
11 changes: 8 additions & 3 deletions backend/LiSA.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from video.downloader.msg_system import MsgSystem
from threading import Thread
from sys import stdout
from sys import stdout, argv
import asyncio
from utils import DB
from config import ServerConfig, parse_config_json, update_environ, FileConfig
Expand All @@ -14,7 +14,9 @@

def run_api_server(port: int = 8000):
ServerConfig.API_SERVER_ADDRESS = f"http://localhost:{port}"
print(f"server started on port: {port} \n You can access API SERVER on {ServerConfig.API_SERVER_ADDRESS}")
print(
f"server started on port: {port} \n You can access API SERVER on {ServerConfig.API_SERVER_ADDRESS}"
)
start_api_server(port=port)


Expand All @@ -34,7 +36,10 @@ def run_api_server(port: int = 8000):
parse_config_json(FileConfig.CONFIG_JSON_PATH)
update_environ()

t1 = Thread(target=run_api_server, args=(6969, ))
# For your development cosmic, you don't need to change your testing port number
PORT = int(argv[1]) if (len(argv) >= 2 and argv[1]) else 6969

t1 = Thread(target=run_api_server, args=(PORT,))
t1.daemon = True
t1.start()

Expand Down
34 changes: 18 additions & 16 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ const createMainWindow = () => {
// executeOnWindow(isPageLoaded, handleLoad);

if (isDevMode) {
mainWindow.loadURL("http://localhost:3967");
const REACT_PORT = process.argv[2];
mainWindow.loadURL(`http://localhost:${REACT_PORT}`);

mainWindow.hide();

Expand Down Expand Up @@ -174,7 +175,8 @@ app.whenReady().then(async () => {
// shell: true,
// stdio: "inherit",
// });
var devProc = spawn("python backend/LiSA.py", {
const PYTHON_SERVER = process.argv[3];
var devProc = spawn(`python backend/LiSA.py ${PYTHON_SERVER}`, {
detached: true,
shell: true,
});
Expand Down Expand Up @@ -259,22 +261,22 @@ app.whenReady().then(async () => {

// // spawn(`powershell.exe -Command kill ${devProc.pid}`);

// devProc.kill("SIGHUP");
// devProc.kill();

// psTree(devProc.pid, function (err, children) {
// console.log(`asdasdasdasdasd`)
// console.log(err)
// console.log(children)
// devProc.spawn(
// "kill",
// ["-9"].concat(
// children.map(function (p) {
// console.log(`inside map child`)
// console.log(children)
// return p.PID;
// })
// )
// );
// console.log(`asdasdasdasdasd`)
// console.log(err)
// console.log(children)
// devProc.spawn(
// "kill",
// ["-9"].concat(
// children.map(function (p) {
// console.log(`inside map child`)
// console.log(children)
// return p.PID;
// })
// )
// );
// });

spawn("taskkill /IM LiSA.exe /F", {
Expand Down
12 changes: 9 additions & 3 deletions scripts/start.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { spawn, spawnSync } = require("child_process");
const { get } = require("axios");

const { getRandomPort } = require('../utilities/getRandomPort')

/**
* @namespace Starter
* @description - Scripts to start Electron, React, and Python.
Expand Down Expand Up @@ -30,9 +32,13 @@ class Starter {
// spawnSync('npx kill-port 3000', spawnOptions.hideLogs);

// Start & identify React & Electron processes
spawn("cross-env BROWSER=none react-scripts start", spawnOptions.showLogs);
spawn("electron .", spawnOptions.showLogs);

const { port: REACT_PORT = 3967 } = await getRandomPort();
const { port: PYTHON_SERVER = 6969 } = await getRandomPort();
// console.log(REACT_PORT, PYTHON_SERVER);

spawn(`cross-env BROWSER=none PORT=${REACT_PORT} REACT_APP_SERVER_URL=http://localhost:${PYTHON_SERVER} react-scripts start `, spawnOptions.showLogs);
spawn(`npx electron main ${REACT_PORT} ${PYTHON_SERVER}`, spawnOptions.showLogs);
// Kill processes on exit
const exitOnEvent = (event) => {
process.once(event, () => {
Expand All @@ -41,7 +47,7 @@ class Starter {
const expectedErrors = ["ECONNRESET", "ECONNREFUSED"];

// Send command to Flask server to quit and close
get(`http://localhost:3967/quit`).catch(
get(`http://localhost:${REACT_PORT}/quit`).catch(
(error) =>
!expectedErrors.includes(error.code) && console.log(error)
);
Expand Down
2 changes: 1 addition & 1 deletion src/actions/animeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const searchAnimeList = (query) => async (dispatch) => {
dispatch({ type: ANIME_SEARCH_REQUEST, payload: {} });


const { data } = await server.get(`/search?anime=${query}`);
const { data } = await server.get(`/search?type=anime&query=${query}`);
dispatch({ type: ANIME_SEARCH_SUCCESS, payload: data });
} catch (error) {
dispatch({ type: ANIME_SEARCH_FAIL, payload: error.response.data });
Expand Down
31 changes: 31 additions & 0 deletions utilities/getRandomPort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const net = require('net');

module.exports.getRandomPort = async (callback) => {
return new Promise((resolve, reject) => {
const server = net.createServer();

server.on('error', (err) => {
callback({ err });
resolve({ err })
});

server.on('listening', () => {
const port = server.address().port;
server.close(() => {
// console.log(port);
// callback({ port });
resolve({ port })
});
});

server.listen();
})
}

// getRandomPort((err, port) => {
// if (err) {
// console.error('Error finding available port:', err);
// } else {
// console.log('Available port:', port);
// }
// });