Move default function code/environment to constants file
This commit is contained in:
33
app.py
33
app.py
@@ -16,6 +16,7 @@ from routes.home import home
|
|||||||
from routes.http import http
|
from routes.http import http
|
||||||
from routes.llm import llm
|
from routes.llm import llm
|
||||||
from routes.auth import auth
|
from routes.auth import auth
|
||||||
|
from constants import DEFAULT_FUNCTION_NAME, DEFAULT_SCRIPT, DEFAULT_ENVIRONMENT
|
||||||
from flask_apscheduler import APScheduler
|
from flask_apscheduler import APScheduler
|
||||||
import asyncio
|
import asyncio
|
||||||
import aiohttp
|
import aiohttp
|
||||||
@@ -47,38 +48,6 @@ app.register_blueprint(auth, url_prefix='/auth')
|
|||||||
# https://stackoverflow.com/questions/76886643/linking-two-not-exposed-dokku-apps
|
# https://stackoverflow.com/questions/76886643/linking-two-not-exposed-dokku-apps
|
||||||
API_URL = os.environ.get('API_URL', 'http://isolator.web:5000/execute') # 'https://isolator.peterstockings.com/execute' 'http://127.0.0.1:5000/execute'
|
API_URL = os.environ.get('API_URL', 'http://isolator.web:5000/execute') # 'https://isolator.peterstockings.com/execute' 'http://127.0.0.1:5000/execute'
|
||||||
|
|
||||||
DEFAULT_FUNCTION_NAME = 'foo'
|
|
||||||
|
|
||||||
DEFAULT_SCRIPT = """async (req) => {
|
|
||||||
console.log(`Method:${req.method}`)
|
|
||||||
console.log(`Generating ${environment.lines} random lines...`)
|
|
||||||
let svgContent = "";
|
|
||||||
|
|
||||||
for (let i = 0; i < environment.lines; i++) {
|
|
||||||
console.log(i)
|
|
||||||
let pathD = "M2 " + Math.random() * 79;
|
|
||||||
let circles = "";
|
|
||||||
|
|
||||||
for (let x = 12; x <= 202; x += 10) {
|
|
||||||
let y = Math.random() * 79
|
|
||||||
pathD += ` L${x} ${y}`;
|
|
||||||
circles += `<circle cx="${x}" cy="${y}" r="1"></circle>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let pathColor = `rgb(${Math.random() * 255}, ${Math.random() * 255}, ${Math.random() * 255})`;
|
|
||||||
svgContent += `
|
|
||||||
<g style="fill: ${pathColor}; stroke: ${pathColor};">
|
|
||||||
<path d="${pathD}" fill="none" stroke="${pathColor}"></path>
|
|
||||||
${circles}
|
|
||||||
</g>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return HtmlResponse(`<svg viewBox="0 0 204 79" preserveAspectRatio="none">${svgContent}</svg>`);
|
|
||||||
}"""
|
|
||||||
|
|
||||||
DEFAULT_ENVIRONMENT = """{
|
|
||||||
"lines": 3
|
|
||||||
}"""
|
|
||||||
|
|
||||||
def map_isolator_response_to_flask_response(response):
|
def map_isolator_response_to_flask_response(response):
|
||||||
"""
|
"""
|
||||||
|
|||||||
32
constants.py
Normal file
32
constants.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
DEFAULT_FUNCTION_NAME = 'foo'
|
||||||
|
|
||||||
|
DEFAULT_SCRIPT = """async (req) => {
|
||||||
|
console.log(`Method:${req.method}`)
|
||||||
|
console.log(`Generating ${environment.lines} random lines...`)
|
||||||
|
let svgContent = "";
|
||||||
|
|
||||||
|
for (let i = 0; i < environment.lines; i++) {
|
||||||
|
console.log(i)
|
||||||
|
let pathD = "M2 " + Math.random() * 79;
|
||||||
|
let circles = "";
|
||||||
|
|
||||||
|
for (let x = 12; x <= 202; x += 10) {
|
||||||
|
let y = Math.random() * 79
|
||||||
|
pathD += ` L${x} ${y}`;
|
||||||
|
circles += `<circle cx="${x}" cy="${y}" r="1"></circle>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
let pathColor = `rgb(${Math.random() * 255}, ${Math.random() * 255}, ${Math.random() * 255})`;
|
||||||
|
svgContent += `
|
||||||
|
<g style="fill: ${pathColor}; stroke: ${pathColor};">
|
||||||
|
<path d="${pathD}" fill="none" stroke="${pathColor}"></path>
|
||||||
|
${circles}
|
||||||
|
</g>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return HtmlResponse(`<svg viewBox="0 0 204 79" preserveAspectRatio="none">${svgContent}</svg>`);
|
||||||
|
}"""
|
||||||
|
|
||||||
|
DEFAULT_ENVIRONMENT = """{
|
||||||
|
"lines": 3
|
||||||
|
}"""
|
||||||
Reference in New Issue
Block a user