Merge branch 'mvp_step2_dev' of https://dev.azure.com/alicorn-dev/KintoneAppBuilder/_git/KintoneAppBuilder into mvp_step2_dev
This commit is contained in:
2
backend/Temp/alc_runtime.js
Normal file
2
backend/Temp/alc_runtime.js
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
test()
|
||||||
|
{}
|
||||||
@@ -6,7 +6,9 @@ import json
|
|||||||
import httpx
|
import httpx
|
||||||
import deepdiff
|
import deepdiff
|
||||||
import app.core.config as c
|
import app.core.config as c
|
||||||
|
import os
|
||||||
|
from app.db.session import SessionLocal
|
||||||
|
from app.db.crud import get_flows
|
||||||
|
|
||||||
kinton_router = r = APIRouter()
|
kinton_router = r = APIRouter()
|
||||||
|
|
||||||
@@ -216,6 +218,46 @@ def getkintoneorgs():
|
|||||||
r = httpx.get(url,headers=headers,params=params)
|
r = httpx.get(url,headers=headers,params=params)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
def uploadkintonefiles(file):
|
||||||
|
upload_files = {'file': open(file,'rb')}
|
||||||
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
||||||
|
data ={'name':'file','filename':os.path.basename(file)}
|
||||||
|
url = f"{c.BASE_URL}/k/v1/file.json"
|
||||||
|
r = httpx.post(url,headers=headers,data=data,files=upload_files)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
def updateappjscss(app,uploads):
|
||||||
|
dsjs = []
|
||||||
|
dscss = []
|
||||||
|
for upload in uploads:
|
||||||
|
for key in upload:
|
||||||
|
if key.endswith('.js'):
|
||||||
|
dsjs.append({'type':'FILE','file':{'fileKey':upload[key]}})
|
||||||
|
elif key.endswith('.css'):
|
||||||
|
dscss.append({'type':'FILE','file':{'fileKey':upload[key]}})
|
||||||
|
ds ={'js':dsjs,'css':dscss}
|
||||||
|
mb ={'js':[],'css':[]}
|
||||||
|
data = {'app':app,'scope':'ALL','desktop':ds,'mobile':mb}
|
||||||
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
||||||
|
url = f"{c.BASE_URL}{c.API_V1_STR}/preview/app/customize.json"
|
||||||
|
print(data)
|
||||||
|
r = httpx.put(url,headers=headers,data=json.dumps(data))
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
def createappjs(app):
|
||||||
|
db = SessionLocal()
|
||||||
|
flows = get_flows(db,app)
|
||||||
|
db.close()
|
||||||
|
content={}
|
||||||
|
for flow in flows:
|
||||||
|
content[flow.eventid] = {'flowid':flow.flowid,'name':flow.name,'content':flow.content}
|
||||||
|
js = 'const flow=' + json.dumps(content)
|
||||||
|
fpath = '{}\\alc_setting_{}.js'.format('Temp',app)
|
||||||
|
file = open(fpath,'w')
|
||||||
|
file.write(js)
|
||||||
|
file.close()
|
||||||
|
return fpath
|
||||||
|
|
||||||
@r.post("/test",)
|
@r.post("/test",)
|
||||||
async def test(file:UploadFile= File(...),app:str=None):
|
async def test(file:UploadFile= File(...),app:str=None):
|
||||||
if file.filename.endswith('.xlsx'):
|
if file.filename.endswith('.xlsx'):
|
||||||
@@ -240,6 +282,14 @@ async def test(file:UploadFile= File(...),app:str=None):
|
|||||||
return test
|
return test
|
||||||
|
|
||||||
|
|
||||||
|
@r.post("/download",)
|
||||||
|
async def download(key):
|
||||||
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
||||||
|
params = {"fileKey":key}
|
||||||
|
url = f"{c.BASE_URL}/k/v1/file.json"
|
||||||
|
r = httpx.get(url,headers=headers,params=params)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
@r.post("/upload",)
|
@r.post("/upload",)
|
||||||
async def upload(files:t.List[UploadFile] = File(...)):
|
async def upload(files:t.List[UploadFile] = File(...)):
|
||||||
dataframes = []
|
dataframes = []
|
||||||
@@ -257,6 +307,28 @@ async def upload(files:t.List[UploadFile] = File(...)):
|
|||||||
|
|
||||||
return {"files": [file.filename for file in files]}
|
return {"files": [file.filename for file in files]}
|
||||||
|
|
||||||
|
@r.post("/updatejscss")
|
||||||
|
async def jscss(app:str,files:t.List[UploadFile] = File(...)):
|
||||||
|
try:
|
||||||
|
jscs=[]
|
||||||
|
for file in files:
|
||||||
|
fbytes = file.file.read()
|
||||||
|
fname = file.filename
|
||||||
|
fpath = '{}\\{}'.format('Temp',fname)
|
||||||
|
fout = open(fpath,'wb')
|
||||||
|
fout.write(fbytes)
|
||||||
|
fout.close()
|
||||||
|
upload = uploadkintonefiles(fpath)
|
||||||
|
if upload.get('fileKey') != None:
|
||||||
|
jscs.append({ file.filename:upload['fileKey']})
|
||||||
|
appjscs = updateappjscss(app,jscs)
|
||||||
|
if appjscs.get("revision") != None:
|
||||||
|
deoployappfromkintone(app,appjscs["revision"])
|
||||||
|
return appjscs
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=400, detail=f"Error occurred while update file {file.filename}: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
@r.get("/allapps",)
|
@r.get("/allapps",)
|
||||||
async def allapps():
|
async def allapps():
|
||||||
try:
|
try:
|
||||||
@@ -284,7 +356,7 @@ async def appfields(app:str):
|
|||||||
async def appprocess(app:str):
|
async def appprocess(app:str):
|
||||||
return getprocessfromkintone(app)
|
return getprocessfromkintone(app)
|
||||||
|
|
||||||
@r.get("/alljscs")
|
@r.get("/alljscss")
|
||||||
async def alljscs(app:str):
|
async def alljscs(app:str):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
||||||
url = f"{c.BASE_URL}{c.API_V1_STR}/app/customize.json"
|
url = f"{c.BASE_URL}{c.API_V1_STR}/app/customize.json"
|
||||||
@@ -430,3 +502,21 @@ async def updateprocessfromexcel(app:str):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@r.post("/createjstokintone",)
|
||||||
|
async def createjstokintone(app:str):
|
||||||
|
|
||||||
|
try:
|
||||||
|
jscs=[]
|
||||||
|
files=[]
|
||||||
|
files.append(createappjs(app))
|
||||||
|
files.append('Temp\\alc_runtime.js')
|
||||||
|
for file in files:
|
||||||
|
upload = uploadkintonefiles(file)
|
||||||
|
if upload.get('fileKey') != None:
|
||||||
|
jscs.append({ app + '.js':upload['fileKey']})
|
||||||
|
appjscs = updateappjscss(app,jscs)
|
||||||
|
if appjscs.get("revision") != None:
|
||||||
|
deoployappfromkintone(app,appjscs["revision"])
|
||||||
|
return appjscs
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=400, detail=f"Error occurred : {str(e)}")
|
||||||
Reference in New Issue
Block a user