Fix bugs when dispatch the RPC method

This commit is contained in:
Namhyeon Go 2024-10-25 08:59:49 +09:00
parent 08212459eb
commit 44425dbb8b
4 changed files with 24 additions and 9 deletions

View File

@ -166,9 +166,13 @@ class Extension:
@classmethod
def get_rpcmethod(cls, method):
for extension in cls.extensions:
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

View File

@ -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
});
});

View File

@ -2,3 +2,5 @@ python-decouple
requests
aiosmtpd
ruff
flask
flask_cors

17
web.py
View File

@ -7,18 +7,20 @@
# Namyheon Go (Catswords Research) <gnh1201@gmail.com>
# 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"})