From 44425dbb8bc22af9d0b524df6ae47417f4dc381c Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Fri, 25 Oct 2024 08:59:49 +0900 Subject: [PATCH] Fix bugs when dispatch the RPC method --- base.py | 10 +++++++--- console.html | 4 ++-- requirements.txt | 2 ++ web.py | 17 +++++++++++++---- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/base.py b/base.py index 6ae9137..a2d58f2 100644 --- a/base.py +++ b/base.py @@ -166,9 +166,13 @@ class Extension: @classmethod def get_rpcmethod(cls, method): for extension in cls.extensions: - is_exported_method = (method == extension.method) or ( - method in extension.exported_methods - ) + is_exported_method = False + try: + is_exported_method = (method == extension.method) or ( + method in extension.exported_methods + ) + except: + pass if extension.type == "rpcmethod" and is_exported_method: return extension return None diff --git a/console.html b/console.html index e252db3..549b15b 100644 --- a/console.html +++ b/console.html @@ -296,7 +296,7 @@ if (env.method == "analyze_sequence") { var _this = this; this.read("Enter the sequence:\r\n", function(message) { - jsonrpc2_request(this, env.method, { + jsonrpc2_request(_this, env.method, { "sequence": message }); }); @@ -307,7 +307,7 @@ if (env.method == "gc_content_calculation") { var _this = this; this.read("Enter the sequence:\r\n", function(message) { - jsonrpc2_request(this, env.method, { + jsonrpc2_request(_this, env.method, { "sequence": message }); }); diff --git a/requirements.txt b/requirements.txt index cfb6c59..37a380b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,5 @@ python-decouple requests aiosmtpd ruff +flask +flask_cors \ No newline at end of file diff --git a/web.py b/web.py index 8b0f752..3067be4 100644 --- a/web.py +++ b/web.py @@ -7,18 +7,20 @@ # Namyheon Go (Catswords Research) # https://github.com/gnh1201/caterpillar # Created at: 2024-05-20 -# Updated at: 2024-07-10 +# Updated at: 2024-10-25 # import os import sys from decouple import config from flask import Flask, request, render_template +from flask_cors import CORS from base import Extension, jsonrpc2_error_encode, Logger # TODO: 나중에 Flask 커스텀 핸들러 구현 해야 함 logger = Logger(name="web") app = Flask(__name__) +CORS(app) app.config["UPLOAD_FOLDER"] = "data/" if not os.path.exists(app.config["UPLOAD_FOLDER"]): os.makedirs(app.config["UPLOAD_FOLDER"]) @@ -51,9 +53,16 @@ def process_jsonrpc2(): # JSON-RPC 2.0 request json_data = request.get_json(silent=True) if json_data["jsonrpc"] == "2.0": - return Extension.dispatch_rpcmethod( - json_data["method"], "call", json_data["id"], json_data["params"], conn - ) + result = Extension.dispatch_rpcmethod( + json_data["method"], "call", json_data["id"], json_data["params"], conn) + + return { + "jsonrpc": "2.0", + "result": { + "data": result + }, + "id": None + } # when error return jsonrpc2_error_encode({"message": "Not valid JSON-RPC 2.0 request"})