From 0f154832a59b593b08563b7fd1ebdb0ef70d9240 Mon Sep 17 00:00:00 2001 From: "maxiaozhe@alicorns.co.jp" Date: Wed, 8 Nov 2023 15:44:42 +0900 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AFAPI=E3=81=AEURL=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=8C=96=E5=AF=BE=E5=BF=9C=E3=81=8A=E3=82=88=E3=81=B3?= =?UTF-8?q?=E3=83=90=E3=83=83=E3=82=AF=E3=82=A8=E3=83=B3=E3=83=89=E3=81=AE?= =?UTF-8?q?BugFix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/api_v1/routers/kintone.py | 28 +++++++++++--------- frontend/.env | 2 +- frontend/src/components/ActionSelect.vue | 2 +- frontend/src/components/AppInfo.vue | 11 ++++---- frontend/src/components/AppSelect.vue | 2 +- frontend/src/components/DocUpload.vue | 9 ++++++- frontend/src/components/DomainSelect.vue | 2 +- frontend/src/components/FieldSelect.vue | 2 +- frontend/src/components/left/AppSelector.vue | 5 +++- frontend/src/control/auth.ts | 3 ++- frontend/src/control/flowctrl.ts | 8 +++--- frontend/src/pages/TenantDomain.vue | 8 +++--- frontend/src/pages/UserDomain.vue | 10 +++---- frontend/src/stores/useAuthStore.ts | 8 +++--- 14 files changed, 58 insertions(+), 42 deletions(-) diff --git a/backend/app/api/api_v1/routers/kintone.py b/backend/app/api/api_v1/routers/kintone.py index 476395a..e060c09 100644 --- a/backend/app/api/api_v1/routers/kintone.py +++ b/backend/app/api/api_v1/routers/kintone.py @@ -8,7 +8,7 @@ import deepdiff import app.core.config as config import os from app.db.session import SessionLocal -from app.db.crud import get_flows,get_activedomain +from app.db.crud import get_flows_by_app,get_activedomain from app.core.auth import get_current_active_user,get_current_user kinton_router = r = APIRouter() @@ -258,19 +258,17 @@ def updateappjscss(app,uploads,c:config.KINTONE_ENV): def createappjs(app): db = SessionLocal() - flows = get_flows(db,app) + flows = get_flows_by_app(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',encoding="utf-8") - file.write(js) - file.close() + js = 'const alcflow=' + json.dumps(content) + fpath = os.path.join("Temp",f"alc_setting_{app}.js") + with open(fpath,'w') as file: + file.write(js) return fpath - @r.post("/test",) async def test(file:UploadFile= File(...),app:str=None): if file.filename.endswith('.xlsx'): @@ -340,7 +338,14 @@ async def jscss(app:str,files:t.List[UploadFile] = File(...),env = Depends(getki return appjscs except Exception as e: raise HTTPException(status_code=400, detail=f"Error occurred while update file {file.filename}: {str(e)}") - + +@r.get("/app") +async def app(app:str,c:config.KINTONE_ENV=Depends(getkintoneenv)): + headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE} + url = f"{c.BASE_URL}{config.API_V1_STR}/app.json" + params ={"id":app} + r = httpx.get(url,headers=headers,params=params) + return r.json() @r.get("/allapps") async def allapps(c:config.KINTONE_ENV=Depends(getkintoneenv)): @@ -401,7 +406,7 @@ async def createappfromexcel(files:t.List[UploadFile] = File(...),env = Depends( app = updateappsettingstokintone(result["app"],{"description":desc},env) if app.get("revision") != None: result["revision"] = app["revision"] - app = addfieldstokintone(result["app"],env,fields) + app = addfieldstokintone(result["app"],fields,env) if len(processes)> 0: app = updateprocesstokintone(result["app"],processes,env) if app.get("revision") != None: @@ -410,8 +415,7 @@ async def createappfromexcel(files:t.List[UploadFile] = File(...),env = Depends( except Exception as e: raise HTTPException(status_code=400, detail=f"Error occurred while parsing file {file.filename}: {str(e)}") else: - raise HTTPException(status_code=400, detail=f"File {file.filename} is not an Excel file") - + raise HTTPException(status_code=400, detail=f"File {file.filename} is not an Excel file") return result diff --git a/frontend/.env b/frontend/.env index 3e3182f..2807162 100644 --- a/frontend/.env +++ b/frontend/.env @@ -1,2 +1,2 @@ -KAB_BACKEND_URL="http://127.0.0.1:8000/api/v1/" +KAB_BACKEND_URL="http://127.0.0.1:8000/" diff --git a/frontend/src/components/ActionSelect.vue b/frontend/src/components/ActionSelect.vue index bd8dfd0..d934ac5 100644 --- a/frontend/src/components/ActionSelect.vue +++ b/frontend/src/components/ActionSelect.vue @@ -27,7 +27,7 @@ export default { ] const rows = reactive([]) onMounted(async () => { - await api.get('http://127.0.0.1:8000/api/kintone/1').then(res =>{ + await api.get('api/kintone/1').then(res =>{ res.data.forEach((item) => { rows.push({name:item.name,desc:item.desc,content:item.content}); diff --git a/frontend/src/components/AppInfo.vue b/frontend/src/components/AppInfo.vue index 22cc51f..5aacc39 100644 --- a/frontend/src/components/AppInfo.vue +++ b/frontend/src/components/AppInfo.vue @@ -36,7 +36,7 @@ import { AppInfo, AppSeed } from './models'; import { ref, defineComponent, watch, onMounted , toRefs } from 'vue'; import { api } from 'boot/axios'; -import { promises } from 'dns'; +import { useAuthStore } from 'src/stores/useAuthStore'; export default defineComponent({ props: { @@ -44,12 +44,13 @@ export default defineComponent({ }, setup(props) { const { app } = toRefs(props); + const authStore = useAuthStore(); const appinfo = ref({ appId: "", name: "", description: "" }); - const link= ref('https://mfu07rkgnb7c.cybozu.com/k/' + app.value); + const link= ref(`${authStore.currentDomain.kintoneUrl}/k/${app.value}`); const getAppInfo = async (appId:string|undefined) => { if(!appId){ return; @@ -59,7 +60,7 @@ export default defineComponent({ let retry =0; while(retry<=3 && result && result.appId!==appId){ await new Promise(resolve => setTimeout(resolve, 1000)); - const response = await api.get('app', { + const response = await api.get('api/v1/app', { params:{ app: appId } @@ -73,7 +74,7 @@ export default defineComponent({ watch(app, async (newApp) => { appinfo.value = await getAppInfo(newApp); - link.value = 'https://mfu07rkgnb7c.cybozu.com/k/' + newApp; + link.value = `${authStore.currentDomain.kintoneUrl}/k/${newApp}`; }, { immediate: true }); const linkClick=(ev : MouseEvent)=>{ @@ -82,7 +83,7 @@ export default defineComponent({ }; onMounted(async ()=>{ appinfo.value = await getAppInfo(app.value); - link.value = 'https://mfu07rkgnb7c.cybozu.com/k/' + app.value; + link.value = `${authStore.currentDomain.kintoneUrl}/k/${app.value}`; }); return { diff --git a/frontend/src/components/AppSelect.vue b/frontend/src/components/AppSelect.vue index 1cbc10c..79d0452 100644 --- a/frontend/src/components/AppSelect.vue +++ b/frontend/src/components/AppSelect.vue @@ -22,7 +22,7 @@ export default { ] const rows = reactive([]) onMounted( () => { - api.get('allapps').then(res =>{ + api.get('api/v1/allapps').then(res =>{ res.data.apps.forEach((item) => { rows.push({id:item.appId,name:item.name,creator:item.creator.name,createdate:item.createdAt}); diff --git a/frontend/src/components/DocUpload.vue b/frontend/src/components/DocUpload.vue index 65c9eb9..0a877f1 100644 --- a/frontend/src/components/DocUpload.vue +++ b/frontend/src/components/DocUpload.vue @@ -4,6 +4,7 @@ style="max-width: 400px" :url="uploadUrl" :label="title" + :headers="headers" accept=".csv,.xlsx" v-on:rejected="onRejected" v-on:uploaded="onUploadFinished" @@ -15,7 +16,10 @@