Added work on popular board listing

master
Kevin Froman 2020-03-28 00:16:42 -05:00
parent 418881fc32
commit 179ec4a3be
5 changed files with 33 additions and 22 deletions

View File

@ -1,6 +1,6 @@
"""Onionr - Private P2P Communication.
This file primarily serves to allow specific fetching of flow board messages
This file primarily serves to allow specific fetching of circles board messages
"""
import json
import os
@ -24,16 +24,23 @@ from utils import identifyhome
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
flask_blueprint = Blueprint('flow', __name__)
flask_blueprint = Blueprint('circles', __name__)
with open(os.path.dirname(os.path.realpath(__file__)) + '/info.json', 'r') as info_file:
data = info_file.read().strip()
version = json.loads(data, strict=False)['version']
@flask_blueprint.route('/flow/getpostsbyboard/<board>')
BOARD_CACHE_FILE = identifyhome.identify_home() + '/board-index.cache.json',
read_only_cache = DeadSimpleKV(
BOARD_CACHE_FILE,
flush_on_exit=False,
refresh_seconds=30)
@flask_blueprint.route('/circles/getpostsbyboard/<board>')
def get_post_by_board(board):
board_cache = DeadSimpleKV(
identifyhome.identify_home() + '/board-index.cache.json',
BOARD_CACHE_FILE,
flush_on_exit=False)
board_cache.refresh()
posts = board_cache.get(board)
@ -43,12 +50,12 @@ def get_post_by_board(board):
posts = ','.join(posts)
return Response(posts)
@flask_blueprint.route('/flow/getpostsbyboard/<board>/<offset>')
@flask_blueprint.route('/circles/getpostsbyboard/<board>/<offset>')
def get_post_by_board_with_offset(board, offset):
offset = int(offset)
OFFSET_COUNT = 10
board_cache = DeadSimpleKV(
identifyhome.identify_home() + '/board-index.cache.json',
BOARD_CACHE_FILE,
flush_on_exit=False)
board_cache.refresh()
posts = board_cache.get(board)
@ -59,14 +66,13 @@ def get_post_by_board_with_offset(board, offset):
posts = ','.join(posts[offset:offset + OFFSET_COUNT])
return Response(posts)
@flask_blueprint.route('/flow/version')
@flask_blueprint.route('/circles/version')
def get_version():
return Response(version)
@flask_blueprint.route('/flow/removefromcache/<board>/<name>', methods=['POST'])
@flask_blueprint.route('/circles/removefromcache/<board>/<name>', methods=['POST'])
def remove_from_cache(board, name):
board_cache = DeadSimpleKV(identifyhome.identify_home() +
'/board-index.cache.json',
board_cache = DeadSimpleKV(BOARD_CACHE_FILE,
flush_on_exit=False)
board_cache.refresh()
posts = board_cache.get(board)
@ -76,3 +82,8 @@ def remove_from_cache(board, name):
pass
board_cache.put(board, posts)
return Response('success')
#@flask_blueprint.route('/circles/getpopular/<count>')
#def get_popular(count):
#boards = read_only_cache.get

View File

@ -0,0 +1,4 @@
{ "name": "circles",
"version": "1.0.0",
"author": "onionr"
}

View File

@ -38,7 +38,7 @@ import flowapi # noqa
flask_blueprint = flowapi.flask_blueprint
security_whitelist = ['staticfiles.boardContent', 'staticfiles.board']
plugin_name = 'flow'
plugin_name = 'circles'
PLUGIN_VERSION = '0.1.0'
EXPIRE_TIME = 43200
@ -67,7 +67,7 @@ class OnionrFlow:
if self.channel == "":
self.channel = "global"
try:
message = logger.readline('\nInsert message into flow:').strip().replace(
message = logger.readline(f'\nInsert message into {plugin_name}:').strip().replace(
'\n', '\\n').replace('\r', '\\r')
except EOFError:
pass
@ -84,7 +84,7 @@ class OnionrFlow:
meta = {
'ch': self.channel})
logger.info("Flow is exiting, goodbye", terminal=True)
logger.info(f"{plugin_name} is exiting, goodbye", terminal=True)
return
def showOutput(self):
@ -115,11 +115,11 @@ class OnionrFlow:
self.flowRunning = False
def on_flow_cmd(api, data=None):
def on_circles_cmd(api, data=None):
OnionrFlow().start()
def on_flowsend_cmd(api, data=None):
def on_circlesend_cmd(api, data=None):
err_msg = "Second arg is board name, third is quoted message"
try:
sys.argv[2]

View File

@ -1,4 +0,0 @@
{ "name": "flow",
"version": "0.1.0",
"author": "onionr"
}

View File

@ -35,7 +35,7 @@ let toggleLoadingMessage = function(){
}
}
fetch('/flow/version', {
fetch('/circles/version', {
method: 'GET',
headers: {
"token": webpass
@ -147,7 +147,7 @@ function getBlocks(){
}
fetch('/flow/getpostsbyboard/' + ch, {
fetch('/circles/getpostsbyboard/' + ch, {
method: 'GET',
headers: {
"token": webpass
@ -181,7 +181,7 @@ function loadMessage(blockHash, blockList, count, channel){
if (!response.ok) {
let on404 = function() {
if (response.status == 404){
fetch('/flow/removefromcache/' + channel + '/' + blockHash, {
fetch('/circles/removefromcache/' + channel + '/' + blockHash, {
method: 'POST',
headers: {
"content-type": "application/json",