mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Websocket connection established
This commit is contained in:
1
Pipfile
1
Pipfile
@@ -29,6 +29,7 @@ django-widget-tweaks = "*"
|
||||
Pillow = "*"
|
||||
Django = "*"
|
||||
uWSGI = "*"
|
||||
pudb = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.8"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
from src.backend.lib.storage import Storage
|
||||
from src.backend.pyShelf_MakeCollections import MakeCollections
|
||||
|
||||
PRG_PATH = pathlib.Path.cwd()
|
||||
LIB_PATH = pathlib.Path.joinpath(PRG_PATH, "src", "backend", "lib")
|
||||
sys.path.insert(0, PRG_PATH)
|
||||
print("\n")
|
||||
MakeCollections(PRG_PATH)
|
||||
30
pyShelf.py
Normal file
30
pyShelf.py
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import websockets
|
||||
from pathlib import Path
|
||||
from src.backend.lib.config import Config
|
||||
|
||||
root = Path.cwd()
|
||||
config = Config(root)
|
||||
|
||||
|
||||
async def echo(websocket, path):
|
||||
async for message in websocket:
|
||||
if message == "import":
|
||||
print("message from Con1 >> {}".format(message))
|
||||
tx = "ack->{}".format(message)
|
||||
elif message == "Connection 2":
|
||||
print("message from Con2 >> {}".format(message))
|
||||
tx = "ack->{}".format(message)
|
||||
elif message == "ping":
|
||||
print("<<[{}]".format(message))
|
||||
tx = pong(message)
|
||||
await websocket.send(tx)
|
||||
|
||||
def pong(message):
|
||||
return "pong"
|
||||
|
||||
start_server = websockets.serve(echo, "127.0.0.1", 1337)
|
||||
|
||||
asyncio.get_event_loop().run_until_complete(start_server)
|
||||
asyncio.get_event_loop().run_forever()
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import websockets
|
||||
0
src/backend/tests/__init__.py
Executable file → Normal file
0
src/backend/tests/__init__.py
Executable file → Normal file
@@ -1,8 +1,8 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
from ..lib.config import Config
|
||||
from ..lib.library import Catalogue
|
||||
from .lib.config import Config
|
||||
from .lib.library import Catalogue
|
||||
|
||||
|
||||
class Test_Config(Config):
|
||||
|
||||
6
src/backend/tests/server_test.py
Normal file
6
src/backend/tests/server_test.py
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
from src.backend.lib.pyShelf import Server
|
||||
|
||||
def test_start():
|
||||
server = await Server().start()
|
||||
assert Server().start() is True
|
||||
@@ -32,7 +32,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = CONFIG.SECRET
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = TEMPLATE_DEBUG = False
|
||||
DEBUG = TEMPLATE_DEBUG = True
|
||||
if DEBUG is True:
|
||||
from pudb.remote import set_trace
|
||||
ALLOWED_HOSTS = CONFIG.allowed_hosts
|
||||
|
||||
12
src/interface/static/css/Pipfile
Normal file
12
src/interface/static/css/Pipfile
Normal file
@@ -0,0 +1,12 @@
|
||||
[[source]]
|
||||
name = "pypi"
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[packages]
|
||||
pytest = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.8"
|
||||
99
src/interface/static/css/Pipfile.lock
generated
Normal file
99
src/interface/static/css/Pipfile.lock
generated
Normal file
@@ -0,0 +1,99 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "976a2ca0f737f325f408ba96dbdd2082722d52709e42df5c38f7096e58a834da"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.8"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"attrs": {
|
||||
"hashes": [
|
||||
"sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c",
|
||||
"sha256:f7b7ce16570fe9965acd6d30101a28f62fb4a7f9e926b3bbc9b61f8b04247e72"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
|
||||
"version": "==19.3.0"
|
||||
},
|
||||
"iniconfig": {
|
||||
"hashes": [
|
||||
"sha256:80cf40c597eb564e86346103f609d74efce0f6b4d4f30ec8ce9e2c26411ba437",
|
||||
"sha256:e5f92f89355a67de0595932a6c6c02ab4afddc6fcdc0bfc5becd0d60884d3f69"
|
||||
],
|
||||
"version": "==1.0.1"
|
||||
},
|
||||
"more-itertools": {
|
||||
"hashes": [
|
||||
"sha256:68c70cc7167bdf5c7c9d8f6954a7837089c6a36bf565383919bb595efb8a17e5",
|
||||
"sha256:b78134b2063dd214000685165d81c154522c3ee0a1c0d4d113c80361c234c5a2"
|
||||
],
|
||||
"markers": "python_version >= '3.5'",
|
||||
"version": "==8.4.0"
|
||||
},
|
||||
"packaging": {
|
||||
"hashes": [
|
||||
"sha256:4357f74f47b9c12db93624a82154e9b120fa8293699949152b22065d556079f8",
|
||||
"sha256:998416ba6962ae7fbd6596850b80e17859a5753ba17c32284f67bfff33784181"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
|
||||
"version": "==20.4"
|
||||
},
|
||||
"pluggy": {
|
||||
"hashes": [
|
||||
"sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0",
|
||||
"sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
|
||||
"version": "==0.13.1"
|
||||
},
|
||||
"py": {
|
||||
"hashes": [
|
||||
"sha256:366389d1db726cd2fcfc79732e75410e5fe4d31db13692115529d34069a043c2",
|
||||
"sha256:9ca6883ce56b4e8da7e79ac18787889fa5206c79dcc67fb065376cd2fe03f342"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
|
||||
"version": "==1.9.0"
|
||||
},
|
||||
"pyparsing": {
|
||||
"hashes": [
|
||||
"sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1",
|
||||
"sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"
|
||||
],
|
||||
"markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2'",
|
||||
"version": "==2.4.7"
|
||||
},
|
||||
"pytest": {
|
||||
"hashes": [
|
||||
"sha256:85228d75db9f45e06e57ef9bf4429267f81ac7c0d742cc9ed63d09886a9fe6f4",
|
||||
"sha256:8b6007800c53fdacd5a5c192203f4e531eb2a1540ad9c752e052ec0f7143dbad"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==6.0.1"
|
||||
},
|
||||
"six": {
|
||||
"hashes": [
|
||||
"sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259",
|
||||
"sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'",
|
||||
"version": "==1.15.0"
|
||||
},
|
||||
"toml": {
|
||||
"hashes": [
|
||||
"sha256:926b612be1e5ce0634a2ca03470f95169cf16f939018233a670519cb4ac58b0f",
|
||||
"sha256:bda89d5935c2eac546d648028b9901107a595863cb36bae0c73ac804a9b4ce88"
|
||||
],
|
||||
"version": "==0.10.1"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
}
|
||||
@@ -6,19 +6,24 @@ $(document).ready(function(){
|
||||
};
|
||||
};
|
||||
/* Initialize ui variables */
|
||||
var outstream = []; // put customlog messages here
|
||||
var win_height = window.innerHeight; // Get the displays height
|
||||
var win_width = window.innerWidth; // Get the displays width
|
||||
var scr_height = window.outerHeight;
|
||||
var scr_width = window.outerWidth;
|
||||
var hdr_height = $('.app_hdr').height(); // Get our header height
|
||||
var ftr_height = $('.app_footer').height(); // Get our footer height
|
||||
var nav_width = $('.nav_l').width(); // Get the width of our nav items
|
||||
var cmp_height = window.screen.availHeight;
|
||||
var max_height = win_height - (hdr_height + ftr_height) - (scr_height - win_height); // Set our available height
|
||||
var u_string = "Username";
|
||||
var p_string = "Password";
|
||||
var s_string = "search by Title, Author, Tags, or Collections";
|
||||
let outstream = []; // put customlog messages here
|
||||
let win_height = window.innerHeight; // Get the displays height
|
||||
let win_width = window.innerWidth; // Get the displays width
|
||||
let scr_height = window.outerHeight;
|
||||
let scr_width = window.outerWidth;
|
||||
let hdr_height = $('.app_hdr').height(); // Get our header height
|
||||
let ftr_height = $('.app_footer').height(); // Get our footer height
|
||||
let nav_width = $('.nav_l').width(); // Get the width of our nav items
|
||||
let cmp_height = window.screen.availHeight;
|
||||
let max_height = win_height - (hdr_height + ftr_height) - (scr_height - win_height); // Set our available height
|
||||
const u_string = "Username";
|
||||
const p_string = "Password";
|
||||
const s_string = "search by Title, Author, Tags, or Collections";
|
||||
const popover = $('#pop_over_0')
|
||||
const navlink = $('.nav_link')
|
||||
const inputbox = $('input_box')
|
||||
const loginbtn = $('#btn_login')
|
||||
const server = ('ws://127.0.0.1:1337')
|
||||
customlog([cmp_height]);
|
||||
$(".search_submit").click(function(){
|
||||
var query = $('.nav_search').val();
|
||||
@@ -33,7 +38,7 @@ $(document).ready(function(){
|
||||
$(this).removeAttr("disabled");
|
||||
}
|
||||
});
|
||||
$('.nav_link').on('mouseover', function (e){
|
||||
$(navlink).on('mouseover', function (e){
|
||||
var popover_str = $(this).attr('alt');
|
||||
x = $(this).offset().left;
|
||||
y = $(this).offset().to;
|
||||
@@ -42,7 +47,7 @@ $(document).ready(function(){
|
||||
$('.popover').css('top', y);
|
||||
$('.popover').css('display','flex');
|
||||
});
|
||||
$('.nav_link').on('mouseout', function (e){
|
||||
$(navlink).on('mouseout', function (e){
|
||||
var popover_str = $(this).attr('alt');
|
||||
x = $(this).offset().left;
|
||||
y = $(this).offset().top;
|
||||
@@ -54,10 +59,10 @@ $(document).ready(function(){
|
||||
$('#btn_collections').on('click', function (e){
|
||||
$('.hidden.vert-nav.collections').toggle();
|
||||
});
|
||||
$('.input_box').on('click', function(){
|
||||
$(inputbox).on('click', function(){
|
||||
$(this).attr("value","");
|
||||
});
|
||||
$('.input_box').focusout(function(){
|
||||
$(inputbox).focusout(function(){
|
||||
if ($(this).hasClass('nav_search') && $(this).val() == "") {
|
||||
$(this).attr("value", s_string);
|
||||
}
|
||||
@@ -68,7 +73,7 @@ $(document).ready(function(){
|
||||
$(this).attr("value", p_string);
|
||||
}
|
||||
});
|
||||
$('#btn_login').on('click', function(){
|
||||
$(loginbtn).on('click', function(){
|
||||
$('#hdr_nav_login').toggle();
|
||||
})
|
||||
$('.favorite_action').on('click', function(){
|
||||
@@ -88,11 +93,11 @@ $(document).ready(function(){
|
||||
window.location.href="/flip_sort/"+$("#_order").val();
|
||||
});
|
||||
$('#search_string').html("<i> "+$('#_search').val().substr(0,15)+"</i>");
|
||||
$('#pop_over_0').dialog({ autoOpen: false });
|
||||
$('#pop_over_0').on('click', 'div.collection', function(){
|
||||
$(popover).dialog({ autoOpen: false });
|
||||
$(popover).on('click', 'div.collection', function(){
|
||||
window.location.href = '/show_collection/'+$(this).attr('data');
|
||||
});
|
||||
$('#btn_login').on('click', function() {
|
||||
$(loginbtn).on('click', function() {
|
||||
var isopen = $('#pop_over_0').dialog("isOpen");
|
||||
if (isopen) {
|
||||
$('#pop_over_0').dialog("close");
|
||||
@@ -167,36 +172,8 @@ $(document).ready(function(){
|
||||
});
|
||||
$(document).on('click', '.logout-btn', function(){window.location.href = '/logout'});
|
||||
$(document).on('click', '.import-btn', function(){
|
||||
$.ajax({
|
||||
type: "GET", url: "/live", data: {hook: 'import_books'},
|
||||
success: function (response) {
|
||||
// Set the dialog title
|
||||
$('#pop_over_0').dialog({
|
||||
title: "User Controls",
|
||||
maxHeight: (win_height - 100),
|
||||
minWidth: $("#horiz_nav_main").width(),
|
||||
hide: {effect: "blind", duration: 1000},
|
||||
show: {effect: "blind", duration: 1000},
|
||||
position: {
|
||||
my: "top", at: "bottom", of: $("#horiz_nav_main")
|
||||
}
|
||||
});
|
||||
// clear and create a new container
|
||||
$('#pop_over_0').html('<div id=usercp class="mx-auto">');
|
||||
// Populate the container from response.data
|
||||
$('#usercp').append('<div class="row" id="usercp-inner">');
|
||||
$('#usercp-inner').append(response.data);
|
||||
$('#usercp-inner').append('</div>');
|
||||
$('#usercp').append('</div>');
|
||||
// Close the container
|
||||
$('#pop_over').append('</div>');
|
||||
// Now open this dialog
|
||||
$('#pop_over_0').dialog("open");
|
||||
},
|
||||
error: function (response) {
|
||||
customlog(["Failure", response]);
|
||||
}
|
||||
});
|
||||
let socket = PyshelfSocket(server);
|
||||
ping(socket);
|
||||
});
|
||||
$('#coll_button').on('click', function(){
|
||||
var isopen = $('#pop_over_0').dialog("isOpen");
|
||||
@@ -279,6 +256,7 @@ $(document).ready(function(){
|
||||
resize_search();
|
||||
$(window).resize(resize_search(win_width));
|
||||
});
|
||||
|
||||
function resize_search(win_width){
|
||||
if (win_width <= 1025){
|
||||
$('.search_string').attr('size', 20);
|
||||
@@ -290,3 +268,28 @@ function resize_search(win_width){
|
||||
}
|
||||
}
|
||||
|
||||
function PyshelfSocket(address) {
|
||||
const connection = new WebSocket(address);
|
||||
connection.onconnect = function(e){
|
||||
ping(connection);
|
||||
};
|
||||
connection.onmessage = function(rcvd){
|
||||
sock_rx(rcvd)
|
||||
};
|
||||
return connection;
|
||||
}
|
||||
function sock_rx(rcvd) {
|
||||
if (rcvd.data == 'pong') { pong(rcvd.data) }
|
||||
else { console.log("<<[rx] :"+rcvd.data) }
|
||||
}
|
||||
function sock_status(sock) {
|
||||
let buffered = sock.connection.bufferedAmmount;
|
||||
let ready = sock.connection.readyState;
|
||||
return [buffered, ready];
|
||||
}
|
||||
function ping(sock) {
|
||||
sock.send('ping')
|
||||
}
|
||||
function pong(rcvd) {
|
||||
console.log("<<["+rcvd.data+"] "+rcvd.data)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ from base64 import b64decode, b64encode
|
||||
from pathlib import Path
|
||||
|
||||
from backend.lib.config import Config
|
||||
from backend.lib.hooks import ACatalogue
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import auth
|
||||
|
||||
Reference in New Issue
Block a user