Skip to content

Commit

Permalink
fix my shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain Blanc committed Oct 13, 2023
1 parent 39d9120 commit 58a6aa6
Show file tree
Hide file tree
Showing 15 changed files with 858 additions and 331 deletions.
855 changes: 853 additions & 2 deletions backend/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jfstat-server",
"version": "1.0.8",
"version": "2.0.0",
"private": true,
"dependencies": {
"@jellyfin/sdk": "^0.8.2",
Expand Down
4 changes: 0 additions & 4 deletions backend/routes/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const triggertype = require('../logging/triggertype');
const taskstate = require('../logging/taskstate');
const taskName = require('../logging/taskName');

const { sendUpdate } = require('../ws');

const router = Router();

Expand Down Expand Up @@ -259,7 +258,6 @@ router.get('/beginBackup', async (req, res) => {

if(last_execution[0].Result ===taskstate.RUNNING)
{
sendUpdate("TaskError","Error: Backup is already running");
res.send();
return;
}
Expand All @@ -272,7 +270,6 @@ router.get('/beginBackup', async (req, res) => {
await backup(refLog);
Logging.updateLog(uuid,refLog.logData,taskstate.SUCCESS);
res.send('Backup completed successfully');
sendUpdate("TaskComplete",{message:triggertype+" Backup Completed"});
} catch (error) {
console.error(error);
res.status(500).send('Backup failed');
Expand All @@ -292,7 +289,6 @@ router.get('/restore/:filename', async (req, res) => {
Logging.updateLog(uuid,refLog.logData,taskstate.SUCCESS);

res.send('Restore completed successfully');
sendUpdate("TaskComplete",{message:"Restore completed successfully"});
} catch (error) {
console.error(error);
res.status(500).send('Restore failed');
Expand Down
21 changes: 0 additions & 21 deletions backend/routes/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const https = require('https');
const moment = require('moment');
const { randomUUID } = require('crypto');

const { sendUpdate } = require('../ws');

const logging=require("./logging");
const taskName=require("../logging/taskName");
Expand Down Expand Up @@ -263,7 +262,6 @@ class sync {

async function syncUserData()
{
sendUpdate("SyncTask",{type:"Update",message:"Syncing User Data"});
const { rows } = await db.query('SELECT * FROM app_config where "ID"=1');

const _sync = new sync(rows[0].JF_HOST, rows[0].JF_API_KEY);
Expand Down Expand Up @@ -291,7 +289,6 @@ async function syncUserData()

async function syncLibraryFolders(data)
{
sendUpdate("SyncTask",{type:"Update",message:"Syncing Library Folders"});
const _sync = new sync();
const existingIds = await _sync.getExistingIDsforTable('jf_libraries');// get existing library Ids from the db

Expand All @@ -309,7 +306,6 @@ async function syncLibraryFolders(data)
//FINALY DELETE LIBRARY
const toDeleteIds = existingIds.filter((id) =>!data.some((row) => row.Id === id ));
if (toDeleteIds.length > 0) {
sendUpdate("SyncTask",{type:"Update",message:"Cleaning Up Old Library Data"});

const ItemsToDelete=await db.query(`SELECT "Id" FROM jf_library_items where "ParentId" in (${toDeleteIds.map(id => `'${id}'`).join(',')})`).then((res) => res.rows.map((row) => row.Id));
if (ItemsToDelete.length > 0) {
Expand All @@ -327,7 +323,6 @@ async function syncLibraryItems(data)
const existingLibraryIds = await _sync.getExistingIDsforTable('jf_libraries');// get existing library Ids from the db

syncTask.loggedData.push({ color: "lawngreen", Message: "Syncing... 1/4" });
sendUpdate("SyncTask",{type:"Update",message:"Beginning Library Item Sync (1/4)"});
syncTask.loggedData.push({color: "yellow",Message: "Beginning Library Item Sync",});

data=data.filter((row) => existingLibraryIds.includes(row.ParentId));
Expand Down Expand Up @@ -358,7 +353,6 @@ async function syncShowItems(data)
{

syncTask.loggedData.push({ color: "lawngreen", Message: "Syncing... 2/4" });
sendUpdate("SyncTask",{type:"Update",message:"Beginning Show Item Sync (2/4)"});
syncTask.loggedData.push({color: "yellow", Message: "Beginning Seasons and Episode sync",});

const { rows: shows } = await db.query(`SELECT * FROM public.jf_library_items where "Type"='Series'`);
Expand Down Expand Up @@ -466,7 +460,6 @@ async function syncShowItems(data)
async function syncItemInfo()
{
syncTask.loggedData.push({ color: "lawngreen", Message: "Syncing... 3/4" });
sendUpdate("SyncTask",{type:"Update",message:"Beginning Item Info Sync (3/4)"});
syncTask.loggedData.push({color: "yellow", Message: "Beginning File Info Sync",});

const { rows: config } = await db.query('SELECT * FROM app_config where "ID"=1');
Expand Down Expand Up @@ -500,7 +493,6 @@ async function syncItemInfo()
//loop for each Movie
for (const Item of Items) {
current_item++;
sendUpdate("SyncTask",{type:"Update",message:`Syncing Item Info ${((current_item/all_items)*100).toFixed(2)}%`});
const data = await _sync.getItemInfo(Item.Id,userid);

const existingItemInfo = await db.query(`SELECT * FROM public.jf_item_info where "Id" = '${Item.Id}'`).then((res) => res.rows.map((row) => row.Id));
Expand Down Expand Up @@ -541,7 +533,6 @@ async function syncItemInfo()
//loop for each Episode
for (const Episode of Episodes) {
current_episode++;
sendUpdate("SyncTask",{type:"Update",message:`Syncing Episode Info ${((current_episode/all_episodes)*100).toFixed(2)}%`});
const data = await _sync.getItemInfo(Episode.EpisodeId,userid);


Expand Down Expand Up @@ -585,13 +576,11 @@ async function syncItemInfo()
syncTask.loggedData.push({color: "dodgerblue",Message: (insertEpisodeInfoCount > 0 ? insertEpisodeInfoCount:0) + " Episodes Info inserted. "+updateEpisodeInfoCount +" Episodes Info Updated"});
syncTask.loggedData.push({color: "orange",Message: deleteEpisodeInfoCount + " Episodes Info Removed.",});
syncTask.loggedData.push({ color: "yellow", Message: "Info Sync Complete" });
sendUpdate("SyncTask",{type:"Update",message:"Info Sync Complete"});
}

async function removeOrphanedData()
{
syncTask.loggedData.push({ color: "lawngreen", Message: "Syncing... 4/4" });
sendUpdate("SyncTask",{type:"Update",message:"Cleaning up FileInfo/Episode/Season Records (4/4)"});
syncTask.loggedData.push({color: "yellow", Message: "Removing Orphaned FileInfo/Episode/Season Records",});

await db.query('CALL jd_remove_orphaned_data()');
Expand Down Expand Up @@ -745,7 +734,6 @@ async function fullSync(triggertype)
syncTask={loggedData:[],uuid:uuid};
try
{
sendUpdate("SyncTask",{type:"Start",message:triggertype+" Sync Started"});
logging.insertLog(uuid,triggertype,taskName.sync);
const { rows } = await db.query('SELECT * FROM app_config where "ID"=1');
if (rows[0]?.JF_HOST === null || rows[0]?.JF_API_KEY === null) {
Expand All @@ -762,7 +750,6 @@ async function fullSync(triggertype)
{
syncTask.loggedData.push({ Message: "Error: No Libararies found to sync." });
logging.updateLog(syncTask.uuid,syncTask.loggedData,taskstate.FAILED);
sendUpdate("SyncTask",{type:"Success",message:triggertype+" Sync Completed"});
return;
}

Expand All @@ -775,15 +762,12 @@ async function fullSync(triggertype)
//for each item in library run get item using that id as the ParentId (This gets the children of the parent id)
for (let i = 0; i < filtered_libraries.length; i++) {
const item = filtered_libraries[i];
sendUpdate("SyncTask",{type:"Update",message:"Fetching Data for Library : "+item.Name + ` (${(i+1)}/${filtered_libraries.length})`});
let libraryItems = await _sync.getItems('parentId',item.Id);
sendUpdate("SyncTask",{type:"Update",message:"Mapping Data for Library : "+item.Name});
const libraryItemsWithParent = libraryItems.map((items) => ({
...items,
...{ ParentId: item.Id },
}));
data.push(...libraryItemsWithParent);
sendUpdate("SyncTask",{type:"Update",message:"Data Fetched for Library : "+item.Name});

}
const library_items=data.filter((item) => ['Movie','Audio','Series'].includes(item.Type));
Expand Down Expand Up @@ -811,14 +795,12 @@ async function fullSync(triggertype)

logging.updateLog(syncTask.uuid,syncTask.loggedData,taskstate.SUCCESS);

sendUpdate("SyncTask",{type:"Success",message:triggertype+" Sync Completed"});


}catch(error)
{
syncTask.loggedData.push({color: "red",Message: getErrorLineNumber(error)+ ": Error: "+error,});
logging.updateLog(syncTask.uuid,syncTask.loggedData,taskstate.FAILED);
sendUpdate("SyncTask",{type:"Error",message:triggertype+" Sync Halted with Errors"});
}


Expand Down Expand Up @@ -847,7 +829,6 @@ router.get("/beingSync", async (req, res) => {

if(last_execution[0].Result ===taskstate.RUNNING)
{
sendUpdate("TaskError","Error: Sync is already running");
res.send();
return;
}
Expand Down Expand Up @@ -941,7 +922,6 @@ router.get("/syncPlaybackPluginData", async (req, res) => {
try
{
logging.insertLog(uuid,triggertype.Manual,taskName.import);
sendUpdate("PlaybackSyncTask",{type:"Start",message:"Playback Plugin Sync Started"});

const { rows } = await db.query('SELECT * FROM app_config where "ID"=1');
if (rows[0]?.JF_HOST === null || rows[0]?.JF_API_KEY === null) {
Expand All @@ -955,7 +935,6 @@ router.get("/syncPlaybackPluginData", async (req, res) => {
await syncPlaybackPluginData();

logging.updateLog(PlaybacksyncTask.uuid,PlaybacksyncTask.loggedData,taskstate.SUCCESS);
sendUpdate("PlaybackSyncTask",{type:"Success",message:"Playback Plugin Sync Completed"});
res.send("syncPlaybackPluginData Complete");
}catch(error)
{
Expand Down
3 changes: 0 additions & 3 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const dbInstance = require("./db");
const path = require("path");

const http = require('http');
const {setupWebSocketServer} = require('./ws');



Expand All @@ -41,8 +40,6 @@ app.use(express.json()); // middleware to parse JSON request bodies


const server = http.createServer(app);
setupWebSocketServer(server);
app.use(cors());
app.use(express.static(path.join(__dirname, 'static')));

// JWT middleware
Expand Down
27 changes: 0 additions & 27 deletions backend/ws.js

This file was deleted.

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": "jfstat",
"version": "1.0.13",
"version": "2.0.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.10.6",
Expand Down
33 changes: 0 additions & 33 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Routes, Route } from "react-router-dom";
import axios from 'axios';


import socket from './socket';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

Expand Down Expand Up @@ -53,37 +52,6 @@ function App() {
{task:'TaskError',ref:React.useRef(null)},
];

useEffect(() => {

wsListeners.forEach((listener) => {

socket.on(listener.task, (message) => {

if(message && message.type==="Start")
{
listener.ref.current = toast.info(message?.message||message, { autoClose: 15000 });
}else if(message && message.type==="Update")
{
toast.update( listener.ref.current, {render: (message?.message||message) , type: toast.TYPE.INFO, autoClose: 15000 });
}else if(message && message.type==="Error")
{
toast.update( listener.ref.current, {render: (message?.message||message) , type: toast.TYPE.ERROR, autoClose: 5000 });
}else if(message && message.type==="Success")
{
toast.update( listener.ref.current, {render: (message?.message||message) , type: toast.TYPE.SUCCESS, autoClose: 5000 });
}

});
});

return () => {
wsListeners.forEach((listener) => {
socket.off(listener.task);
});

};
});

useEffect(() => {


Expand Down Expand Up @@ -185,7 +153,6 @@ if (config && setupState===2 && token!==null){
</Routes>
</main>
</div>
<ToastContainer theme="dark" position="bottom-right" limit={5} pauseOnFocusLoss={false} hideProgressBar/>
</div>

);
Expand Down
8 changes: 1 addition & 7 deletions src/pages/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ export default function SettingsAbout() {
const token = localStorage.getItem('token');
const [data, setData] = useState();



if(!data)
{
return <Loading/>;
}


return (
Expand All @@ -32,7 +26,7 @@ export default function SettingsAbout() {
Github:
</Col>
<Col>
<a href="https://github.com/opspotes/Jellystat" target="_blank" rel="noreferrer" > https://github.com/CyferShepard/Jellystat</a>
<a href="https://github.com/opspotes/Jellystat" target="_blank" rel="noreferrer" > https://github.com/opspotes/Jellystat</a>
</Col>
</Row>
</Card.Body>
Expand Down
2 changes: 0 additions & 2 deletions src/pages/components/general/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import LogoutBoxLineIcon from "remixicon-react/LogoutBoxLineIcon";
import logo_dark from '../../images/icon-b-512.png';
import "../../css/navbar.css";
import React from "react";
import VersionCard from "./version-card";

export default function Navbar() {
const handleLogout = () => {
Expand Down Expand Up @@ -49,7 +48,6 @@ export default function Navbar() {


</div>
<VersionCard/>

</BootstrapNavbar>
);
Expand Down
Loading

0 comments on commit 58a6aa6

Please sign in to comment.