upload kintone jscss file
This commit is contained in:
@@ -6,6 +6,7 @@ import json
|
||||
import httpx
|
||||
import deepdiff
|
||||
import app.core.config as c
|
||||
import os
|
||||
|
||||
|
||||
kinton_router = r = APIRouter()
|
||||
@@ -216,6 +217,33 @@ def getkintoneorgs():
|
||||
r = httpx.get(url,headers=headers,params=params)
|
||||
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()
|
||||
|
||||
|
||||
@r.post("/test",)
|
||||
async def test(file:UploadFile= File(...),app:str=None):
|
||||
if file.filename.endswith('.xlsx'):
|
||||
@@ -240,6 +268,14 @@ async def test(file:UploadFile= File(...),app:str=None):
|
||||
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",)
|
||||
async def upload(files:t.List[UploadFile] = File(...)):
|
||||
dataframes = []
|
||||
@@ -257,6 +293,28 @@ async def upload(files:t.List[UploadFile] = File(...)):
|
||||
|
||||
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",)
|
||||
async def allapps():
|
||||
try:
|
||||
@@ -284,7 +342,7 @@ async def appfields(app:str):
|
||||
async def appprocess(app:str):
|
||||
return getprocessfromkintone(app)
|
||||
|
||||
@r.get("/alljscs")
|
||||
@r.get("/alljscss")
|
||||
async def alljscs(app:str):
|
||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
||||
url = f"{c.BASE_URL}{c.API_V1_STR}/app/customize.json"
|
||||
|
||||
Reference in New Issue
Block a user