initial commit
This commit is contained in:
parent
5a114c546f
commit
5e2fc16cc3
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*__pycache
|
||||||
|
.vscode
|
7
notification.py
Normal file → Executable file
7
notification.py
Normal file → Executable file
@ -34,11 +34,8 @@ class Notification:
|
|||||||
:param content str:
|
:param content str:
|
||||||
This is a multi-line body of text. Each line is a paragraph, server
|
This is a multi-line body of text. Each line is a paragraph, server
|
||||||
implementations are free to word wrap them as they see fit.
|
implementations are free to word wrap them as they see fit.
|
||||||
The body mayfrom gi.repository import GLib
|
The body functionality may not be implemented by the notification
|
||||||
import dbus
|
server, conforming clients should check if it is available before usings
|
||||||
from dbus.mainloop.glib import DBusGMainLoop
|
|
||||||
functionality may not be implemented by the notification
|
|
||||||
server, conforming clients should check if it is available before using
|
|
||||||
it (see the GetCapabilities message in Protocol). An implementation is
|
it (see the GetCapabilities message in Protocol). An implementation is
|
||||||
free to ignore any requested by the client. As an example one possible
|
free to ignore any requested by the client. As an example one possible
|
||||||
rendering of actions would be as buttons in the notification popup.
|
rendering of actions would be as buttons in the notification popup.
|
||||||
|
36
serveur.py
Normal file → Executable file
36
serveur.py
Normal file → Executable file
@ -1,4 +1,5 @@
|
|||||||
#!/bin/python
|
#!/bin/python
|
||||||
|
import hashlib
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import secrets
|
import secrets
|
||||||
import time
|
import time
|
||||||
@ -11,7 +12,6 @@ socketio = flask_socketio.SocketIO(app)
|
|||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
def first_run():
|
def first_run():
|
||||||
"""
|
"""
|
||||||
create databases
|
create databases
|
||||||
@ -135,14 +135,14 @@ def get_notifications():
|
|||||||
token = request.values.get("token")
|
token = request.values.get("token")
|
||||||
con = sqlite3.connect("database.db")
|
con = sqlite3.connect("database.db")
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
notifications = cur.execute("SELECT title,content \
|
notifications = cur.execute("SELECT * \
|
||||||
FROM NOTIFICATION \
|
FROM NOTIFICATION \
|
||||||
WHERE token=?",
|
WHERE token=?",
|
||||||
(token, )).fetchall()
|
(token, )).fetchall()
|
||||||
data = {"status": "ok"}
|
data = {"status": "ok"}
|
||||||
data["notifications"] = []
|
data["notifications"] = []
|
||||||
for notification in notifications:
|
for notification in notifications:
|
||||||
data["notifications"].append({"title": notification[0],"content": notification[1]})
|
data["notifications"].append()
|
||||||
return data, 200
|
return data, 200
|
||||||
|
|
||||||
|
|
||||||
@ -158,26 +158,31 @@ def get_notification_by_id(notifid):
|
|||||||
con = sqlite3.connect("database.db")
|
con = sqlite3.connect("database.db")
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
if notifid == -1:
|
if notifid == -1:
|
||||||
notifications = cur.execute("SELECT title,content \
|
notifications = cur.execute("SELECT * \
|
||||||
FROM NOTIFICATION \
|
FROM NOTIFICATION \
|
||||||
WHERE token=?\
|
WHERE token=?\
|
||||||
ORDER BY id DESC \
|
ORDER BY id DESC \
|
||||||
LIMIT 1",
|
LIMIT 1",
|
||||||
(token,)).fetchone()
|
(token,)).fetchone()
|
||||||
else:
|
else:
|
||||||
notifications = cur.execute("SELECT title,content \
|
notifications = cur.execute("SELECT * \
|
||||||
FROM NOTIFICATION \
|
FROM NOTIFICATION \
|
||||||
WHERE token=? AND id=?",
|
WHERE token=? AND id=?",
|
||||||
(token, notifid)).fetchone()
|
(token, notifid)).fetchone()
|
||||||
|
|
||||||
return {"status": "ok",
|
return {"status": "ok",
|
||||||
"notifications": {"title": notifications[0],
|
"notifications": notifications
|
||||||
"content": notifications[1]
|
|
||||||
}
|
|
||||||
}, 200
|
}, 200
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
def clipFromArray(clip):
|
||||||
|
return {"id": clip[0],
|
||||||
|
"timestamp": clip[1],
|
||||||
|
"deviceName": clip[2],
|
||||||
|
"token": clip[3],
|
||||||
|
"content": clip[3]}
|
||||||
|
|
||||||
|
|
||||||
@app.route("/clipboard", methods=['PUT'])
|
@app.route("/clipboard", methods=['PUT'])
|
||||||
def add_clipboard():
|
def add_clipboard():
|
||||||
@ -217,11 +222,11 @@ def get_clipboard():
|
|||||||
token = request.values.get("token")
|
token = request.values.get("token")
|
||||||
con = sqlite3.connect("database.db")
|
con = sqlite3.connect("database.db")
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
clipboard = cur.execute("SELECT content \
|
clipboard = cur.execute("SELECT * \
|
||||||
FROM CLIPBOARD \
|
FROM CLIPBOARD \
|
||||||
WHERE token=?",
|
WHERE token=?",
|
||||||
(token, )).fetchall()
|
(token, )).fetchall()
|
||||||
|
clipboard = [clipFromArray(clip) for clip in clipboard]
|
||||||
return {"status": "ok", "clipboard": clipboard}, 200
|
return {"status": "ok", "clipboard": clipboard}, 200
|
||||||
|
|
||||||
|
|
||||||
@ -237,19 +242,18 @@ def get_clipboard_by_id(clipid):
|
|||||||
con = sqlite3.connect("database.db")
|
con = sqlite3.connect("database.db")
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
if clipid == -1:
|
if clipid == -1:
|
||||||
clipboard = cur.execute("SELECT content \
|
clipboard = cur.execute("SELECT * \
|
||||||
FROM CLIPBOARD \
|
FROM CLIPBOARD \
|
||||||
WHERE token=? \
|
WHERE token=? \
|
||||||
ORDER BY id DESC \
|
ORDER BY id DESC \
|
||||||
LIMIT 1",
|
LIMIT 1",
|
||||||
(token,)).fetchone()
|
(token,)).fetchone()
|
||||||
else:
|
else:
|
||||||
clipboard = cur.execute("SELECT content \
|
clipboard = cur.execute("SELECT * \
|
||||||
FROM CLIPBOARD \
|
FROM CLIPBOARD \
|
||||||
token=? AND id=?",
|
WHERE token=? AND id=?",
|
||||||
(token, clipid)).fetchone()
|
(token, clipid)).fetchone()
|
||||||
|
return {"status": "ok", "clipboard": clipFromArray(clipboard)}, 200
|
||||||
return {"status": "ok", "clipboard": clipboard[0]}, 200
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user