Changed '/get' from a query to a path parameter

This commit is contained in:
Marc-Andre Ferland 2022-10-15 01:32:53 -04:00
parent 3d4e961320
commit e9f9670eb5
2 changed files with 9 additions and 9 deletions

View File

@ -1213,7 +1213,7 @@ useBetaChannelField.addEventListener('click', async function(e) {
async function getAppConfig() { async function getAppConfig() {
try { try {
let res = await fetch('/get?key=app_config') let res = await fetch('/get/app_config')
const config = await res.json() const config = await res.json()
if (config.update_branch === 'beta') { if (config.update_branch === 'beta') {
@ -1229,7 +1229,7 @@ async function getAppConfig() {
async function getModels() { async function getModels() {
try { try {
let res = await fetch('/get?key=models') let res = await fetch('/get/models')
const models = await res.json() const models = await res.json()
let activeModel = models['active'] let activeModel = models['active']
@ -1494,7 +1494,7 @@ async function getDiskPath() {
return return
} }
let res = await fetch('/get?key=output_dir') let res = await fetch('/get/output_dir')
if (res.status === 200) { if (res.status === 200) {
res = await res.json() res = await res.json()
res = res[0] res = res[0]
@ -1613,7 +1613,7 @@ function resizeModifierCards(val) {
async function loadModifiers() { async function loadModifiers() {
try { try {
let res = await fetch('/get?key=modifiers') let res = await fetch('/get/modifiers')
if (res.status === 200) { if (res.status === 200) {
res = await res.json() res = await res.json()

View File

@ -494,19 +494,19 @@ def getModels():
return models return models
@app.get('/get') @app.get('/get/{key:path}')
def read_web_data(key:str=None): def read_web_data(key:str=None):
if key is None: # /get without parameters, stable-diffusion easter egg. if not key: # /get without parameters, stable-diffusion easter egg.
return HTTPException(status_code=418, detail="StableDiffusion is drawing a teapot!") # HTTP418 I'm a teapot return HTTPException(status_code=418, detail="StableDiffusion is drawing a teapot!") # HTTP418 I'm a teapot
elif key == 'app_config': elif key == 'app_config':
config = getConfig(default_val=None) config = getConfig(default_val=None)
if config is None: if config is None:
return HTTPException(status_code=500, detail="Config file is missing or unreadable") return HTTPException(status_code=500, detail="Config file is missing or unreadable")
return config return JSONResponse(config, headers=NOCACHE_HEADERS)
elif key == 'models': elif key == 'models':
return getModels() return JSONResponse(getModels(), headers=NOCACHE_HEADERS)
elif key == 'modifiers': return FileResponse(os.path.join(SD_UI_DIR, 'modifiers.json'), headers=NOCACHE_HEADERS) elif key == 'modifiers': return FileResponse(os.path.join(SD_UI_DIR, 'modifiers.json'), headers=NOCACHE_HEADERS)
elif key == 'output_dir': return {outpath} elif key == 'output_dir': return JSONResponse({outpath}, headers=NOCACHE_HEADERS)
else: else:
return HTTPException(status_code=404, detail=f'Request for unknown {key}') # HTTP404 Not Found return HTTPException(status_code=404, detail=f'Request for unknown {key}') # HTTP404 Not Found