-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41e452d
commit 6067034
Showing
11 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from flask_restful import Resource, reqparse | ||
|
||
from controllers.console import api | ||
from controllers.console.setup import setup_required | ||
from controllers.console.wraps import account_initialization_required | ||
from libs.login import login_required | ||
from services.form_schemas_service import FormSchemasService | ||
|
||
|
||
class FormSchemas(Resource): | ||
|
||
@setup_required | ||
@login_required | ||
@account_initialization_required | ||
def get(self): | ||
parser = reqparse.RequestParser() | ||
parser.add_argument('module', type=str, required=True, location='args') | ||
args = parser.parse_args() | ||
|
||
return FormSchemasService.get_form_schemas(args['module']) | ||
|
||
|
||
api.add_resource(FormSchemas, '/form-schemas') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from core.hooks.moderation.cloud_service.cloud_service import CloudService |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import json | ||
import os | ||
|
||
registered_hooks = {} | ||
|
||
class BaseHook: | ||
|
||
def __init_subclass__(cls, **kwargs): | ||
super().__init_subclass__(**kwargs) | ||
cls.register() | ||
|
||
@classmethod | ||
def register(cls): | ||
subclass_path = os.path.abspath(cls.__module__.replace(".", os.path.sep) + '.py') | ||
subclass_dir_path = os.path.dirname(subclass_path) | ||
parent_folder_name = os.path.basename(os.path.dirname(subclass_dir_path)) | ||
|
||
if parent_folder_name == 'hooks': | ||
return | ||
|
||
json_path = os.path.join(subclass_dir_path, 'schema.json') | ||
json_data = {} | ||
if os.path.exists(json_path): | ||
with open(json_path, 'r') as f: | ||
json_data = json.load(f) | ||
|
||
if parent_folder_name not in registered_hooks: | ||
registered_hooks[parent_folder_name] = [] | ||
|
||
registered_hooks[parent_folder_name].append(json_data) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from ..base_hook import BaseHook | ||
|
||
class BaseModeration(BaseHook): | ||
pass |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from ...moderation.base_moderation import BaseModeration | ||
|
||
class CloudService(BaseModeration): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "cloud_service", | ||
"label": { | ||
"en-US": "Cloud Service", | ||
"zh-Hans": "云服务" | ||
}, | ||
"form_schema": [ | ||
{ | ||
"select": { | ||
"label": { | ||
"en-US": "Cloud Provider", | ||
"zh-Hans": "云计算厂商" | ||
}, | ||
"variable": "cloud_provider", | ||
"required": true, | ||
"options": [ | ||
"腾讯云", | ||
"阿里云", | ||
"AWS" | ||
], | ||
"default": "", | ||
"placeholder": "" | ||
} | ||
}, | ||
{ | ||
"text-input": { | ||
"label": { | ||
"en-US": "API Endpoint", | ||
"zh-Hans": "API Endpoint" | ||
}, | ||
"variable": "api_endpoint", | ||
"required": true, | ||
"max-length": 100, | ||
"default": "", | ||
"placeholder": "" | ||
} | ||
}, | ||
{ | ||
"paragraph": { | ||
"label": { | ||
"en-US": "API Key", | ||
"zh-Hans": "API Key" | ||
}, | ||
"variable": "api_keys", | ||
"required": true, | ||
"default": "", | ||
"placeholder": "" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from core.hooks.base_hook import registered_hooks | ||
|
||
class FormSchemasService: | ||
|
||
@classmethod | ||
def get_form_schemas(cls, module: str) -> list[dict]: | ||
return registered_hooks.get(module, []) |