diff --git a/static-data/default-plugins/flow/flowapi.py b/static-data/default-plugins/circles/flowapi.py similarity index 71% rename from static-data/default-plugins/flow/flowapi.py rename to static-data/default-plugins/circles/flowapi.py index ef27a39f..f9802a3d 100755 --- a/static-data/default-plugins/flow/flowapi.py +++ b/static-data/default-plugins/circles/flowapi.py @@ -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 . """ -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_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/') 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//') +@flask_blueprint.route('/circles/getpostsbyboard//') 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//', methods=['POST']) +@flask_blueprint.route('/circles/removefromcache//', 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/') +#def get_popular(count): + #boards = read_only_cache.get + diff --git a/static-data/default-plugins/circles/info.json b/static-data/default-plugins/circles/info.json new file mode 100755 index 00000000..9e140e29 --- /dev/null +++ b/static-data/default-plugins/circles/info.json @@ -0,0 +1,4 @@ +{ "name": "circles", + "version": "1.0.0", + "author": "onionr" +} \ No newline at end of file diff --git a/static-data/default-plugins/flow/main.py b/static-data/default-plugins/circles/main.py similarity index 95% rename from static-data/default-plugins/flow/main.py rename to static-data/default-plugins/circles/main.py index f2d95795..0e75dc8b 100755 --- a/static-data/default-plugins/flow/main.py +++ b/static-data/default-plugins/circles/main.py @@ -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] diff --git a/static-data/default-plugins/flow/info.json b/static-data/default-plugins/flow/info.json deleted file mode 100755 index 13e05d76..00000000 --- a/static-data/default-plugins/flow/info.json +++ /dev/null @@ -1,4 +0,0 @@ -{ "name": "flow", - "version": "0.1.0", - "author": "onionr" -} \ No newline at end of file diff --git a/static-data/www/board/board.js b/static-data/www/board/board.js index 7cbe95ec..66bf01a9 100755 --- a/static-data/www/board/board.js +++ b/static-data/www/board/board.js @@ -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",