Skip to content
This repository has been archived by the owner on May 20, 2022. It is now read-only.

Commit

Permalink
Minor bug changes
Browse files Browse the repository at this point in the history
  • Loading branch information
izu-co committed Jun 12, 2021
1 parent 03ba6a1 commit cf99c71
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 28 deletions.
4 changes: 2 additions & 2 deletions backend/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ chok.watch(argv['Video Directory'], {
console.log('[INFO] Finished indexing!');

db.exec('CREATE TABLE IF NOT EXISTS properties (name STRING, val TEXT)');
db.exec('CREATE TABLE IF NOT EXISTS users (UUID TEXT PRIMARY KEY, username TEXT, password TEXT, perm TEXT, active BOOLEAN) WITHOUT ROWID');
db.exec('CREATE TABLE IF NOT EXISTS users (UUID TEXT PRIMARY KEY, username TEXT, password TEXT, perm TEXT, active INT) WITHOUT ROWID');
db.exec('CREATE TABLE IF NOT EXISTS status (UUID Text, path TEXT, data DOUBLE)');
db.exec('CREATE TABLE IF NOT EXISTS intros (path TEXT PRIMARY KEY, startTime INT, endTime INT)');
db.exec('CREATE TABLE IF NOT EXISTS settings (UUID TEXT PRIMARY KEY, volume INT)');
Expand Down Expand Up @@ -116,7 +116,7 @@ if (!fileExists) {
let prep = db.prepare('INSERT INTO settings VALUES (?, ?)');
prep.run('default', 30);
prep = db.prepare('INSERT INTO users VALUES (?, ?, ?, ?, ?)');
prep.run('f084bdb1-7fb7-4e45-bace-e7719974e135', 'Admin', 'pass', 'Admin', 'true');
prep.run('f084bdb1-7fb7-4e45-bace-e7719974e135', 'Admin', 'pass', 'Admin', 1);
}
}

Expand Down
4 changes: 2 additions & 2 deletions backend/userManagment/changeActiveState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Response } from '../../interfaces';
import { getUserFromToken } from '../UserMangement';
import { db } from '../..';

function changeActiveState (state:boolean, uuid:string, token:string, ip:string): Response {
function changeActiveState (state:1|0, uuid:string, token:string, ip:string): Response {
const user = getUserFromToken(token, ip);
if (!user['status'])
return user;
Expand All @@ -13,7 +13,7 @@ function changeActiveState (state:boolean, uuid:string, token:string, ip:string)
if (tochange === undefined)
return {'status' : false, 'reason': 'UUID User not found'};

db.prepare('UPDATE users SET active=? WHERE UUID=?').run(state ? 'true' : 'false', uuid);
db.prepare('UPDATE users SET active=? WHERE UUID=?').run(state, uuid);
return { status: true };
}

Expand Down
10 changes: 5 additions & 5 deletions html/js/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,21 @@ fetchBackend(url.toString(), {

container.appendChild(userContainer);

});}, false, false);
});}, true, false);

document.getElementById('submit').addEventListener('click', function() {
const username = (<HTMLInputElement> document.getElementById('Name')).value;
const pass = (<HTMLInputElement> document.getElementById('Pass')).value;
const passCon = (<HTMLInputElement> document.getElementById('ConPass')).value;
const perm = (<HTMLSelectElement> document.getElementById('perm')).options[(<HTMLSelectElement> document.getElementById('perm')).selectedIndex].value;
if (username === '')
alert('Please enter a username!');
return alert('Please enter a username!');
else if (pass === '')
alert('Please enter a password!');
return alert('Please enter a password!');
else if (passCon === '')
alert('Please confirm the password!');
return alert('Please confirm the password!');
else if (pass !== passCon)
alert('The passwords are not the same!');
return alert('The passwords are not the same!');
fetchBackend('/api/addUser/', {
headers: {
'content-type' : 'application/json; charset=UTF-8'
Expand Down
27 changes: 15 additions & 12 deletions html/js/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const next = <HTMLButtonElement> document.getElementById('next');
const controls = document.getElementById('controls');
const info = document.getElementById('info');


let mouseDown = false;
let skiped = false;
let timer: NodeJS.Timeout;
Expand All @@ -34,6 +33,16 @@ document.body.onmouseup = function() {
mouseDown = false;
};

fetchBackend('/api/checkToken/', {
headers: {
'content-type' : 'application/json; charset=UTF-8'
},
body: JSON.stringify({
'token' : loadCookie('token')
}),
method: 'POST'
}, undefined, true, false);

const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);

Expand Down Expand Up @@ -75,16 +84,6 @@ if (!video.canPlayType(getVideoType(urlParams.get('path').split('.').pop()))) {
video.src = '/video/' + urlParams.get('path');
}

fetchBackend('/api/checkToken/', {
headers: {
'content-type' : 'application/json; charset=UTF-8'
},
body: JSON.stringify({
'token' : loadCookie('token')
}),
method: 'POST'
}, undefined, true, false);

const fileDataURL = new URL(window.location.origin + '/api/FileData/');
fileDataURL.search = new URLSearchParams({
'token' : loadCookie('token'),
Expand Down Expand Up @@ -121,7 +120,11 @@ function loadData(res: SkipData) {
if (res.next) {
next.style.opacity = '1';
next.addEventListener('click', function() {
document.location.href = document.location.href.split('?')[0] + '?path=' + res['next'];
const nextURL = new URL(document.location.href)
nextURL.search = new URLSearchParams({
path: res.next
}).toString()
document.location.href = nextURL.toString()
});
} else
next.disabled = true;
Expand Down
1 change: 0 additions & 1 deletion html/player/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<link href="https://fonts.googleapis.com/css2?family=Rubik:wght@300&display=swap" rel="stylesheet">
<title>VideoPlayer</title>
<link rel="stylesheet" href="/style/generalStyle.css" type="text/css">
<script type="text/javascript" src="/js/generalFunctions.js"></script>
<link href="https://kit-free.fontawesome.com/releases/latest/css/free.min.css" media="all" rel="stylesheet">
<script src="//www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"></script>
<link rel="stylesheet" type="text/css" href="/style/player.css">
Expand Down
1 change: 0 additions & 1 deletion html/server/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html>
<head>
<link rel="stylesheet" href="/style/generalStyle.css" type="text/css">
<script type="text/javascript" src="/js/generalFunctions.js"></script>
<link rel="stylesheet" type="text/css" href="/style/server.css">
<title>Settings</title>
</head>
Expand Down
1 change: 0 additions & 1 deletion html/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html>
<head>
<link rel="stylesheet" href="/style/generalStyle.css" type="text/css">
<script type="text/javascript" src="/js/generalFunctions.js"></script>
<link rel="stylesheet" type="text/css" href="/style/settings.css">
<title>Settings</title>
</head>
Expand Down
1 change: 0 additions & 1 deletion html/videoSelector/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<title>Serv_ Player</title>
<link href="https://kit-free.fontawesome.com/releases/latest/css/free.min.css" media="all" rel="stylesheet">
<link rel="stylesheet" href="/style/generalStyle.css" type="text/css">
<script type="text/javascript" src="/js/generalFunctions.js"></script>
<link rel="stylesheet" type="text/css" href="/style/videoSelector.css">
<link rel="stylesheet" type="text/css" href="/style/videoSelectorFooter.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "videoplayer",
"version": "3.2.0",
"version": "3.2.1",
"description": "A Video Player",
"main": "index.js",
"databaseVersion": 2,
Expand Down Expand Up @@ -51,7 +51,7 @@
"eslint": "npx eslint . --fix",
"build": "node build.js",
"prestart": "node build.js --test",
"start": "cd build && node index.js --vd ../test/videos",
"start": "cd build && node index.js",
"pretest": "npm run prestart",
"test": "npx mocha --require ts-node/register test/run.ts --exit --timeout 10000 --no-warnings"
},
Expand Down
2 changes: 2 additions & 0 deletions routes/backend/changeActive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ router.route('/' + routeName + '/')

function postRouteHandler(req:express.Request, res:express.Response) {
if (res.locals.user['perm'] === 'Admin') {
if (typeof req.body.state === "boolean")
req.body.state = req.body.state ? 1 : 0
const response = loginBackend.changeActiveState(req.body.state, req.body.uuid, req.body.token, req.header('x-forwarded-for') || req.socket.remoteAddress);
res.send(response);
} else
Expand Down
8 changes: 7 additions & 1 deletion test/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ getAllFiles('test').forEach(f => {

//TODO check settings file

const oldSettings = fs.readFileSync('settings.json')

describe('File Tests', () => {
it('Node_modules installed', () => {
expect(fs.existsSync('build/node_modules')).to.be.true;
Expand Down Expand Up @@ -144,7 +146,7 @@ describe('Test requests', () => {
it('Check changed active state', async () => {
return await requester.get('getUsers/').query({ token: token }).send()
.then(data => {
return [expect(data.status).to.be.equal(200), expect(data.body.status).to.be.true, expect(data.body.data.find(a => a.username === 'Testi').active).to.equal('false')];
return [expect(data.status).to.be.equal(200), expect(data.body.status).to.be.true, expect(data.body.data.find(a => a.username === 'Testi').active).to.equal(0)];
});
});

Expand Down Expand Up @@ -326,6 +328,10 @@ describe('Test requests', () => {
});
});
});

after(() => {
fs.writeFileSync('settings.json', oldSettings)
})
});


Expand Down

0 comments on commit cf99c71

Please sign in to comment.