Skip to content

Commit

Permalink
feat(replicate): impl replicate request
Browse files Browse the repository at this point in the history
  • Loading branch information
walle233 committed May 1, 2022
1 parent 592849a commit 0f6e3b0
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 184 deletions.
55 changes: 40 additions & 15 deletions packages/app-console/src/api/replicate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import store from '@/store'
import request from '@/utils/request'
import axios from 'axios'

/**
* Get replicated auths
Expand Down Expand Up @@ -31,17 +30,14 @@ export function createReplicateAuth(target_appid) {
}

/**
* Update a replicated auth
* Accept a replicated auth
* @returns
*/
export function updateReplicateAuth(auth_id, status) {
export function acceptReplicateAuth(auth_id) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/replicate/replicate_auth/${auth_id}`,
method: 'post',
data: {
status
}
method: 'post'
})
}

Expand All @@ -59,17 +55,30 @@ export function deleteReplicateAuth(auth_id) {
}

/**
* apply a replicated auth
* get replicate requests
* @returns
*/
export function getReplicateRequests(params) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/replicate/replicate_request`,
method: 'get',
params
})
}

/**
* create a replicate request
* @param {string} target_appid
* @param {object} functions
* @param {object} policies
* @returns
*/
export function applyReplicateAuth({ target_appid, functions, policies }) {
export function createReplicateRequest({ target_appid, functions, policies }) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/replicate/replicas`,
method: 'put',
url: `/apps/${appid}/replicate/replicate_request`,
method: 'post',
data: {
target_appid,
functions,
Expand All @@ -79,14 +88,30 @@ export function applyReplicateAuth({ target_appid, functions, policies }) {
}

/**
* accept a replicated auth
* accept a replicate request
* @param {string} auth_id
* @returns
*/
export function acceptReplicateAuth(auth_id) {
export function acceptReplicateRequest(request_id, status) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/replicate/replicate_request/${request_id}`,
method: 'put',
data: {
status
}
})
}

/**
* delete a replicate request
* @param {string} request_id
* @returns
*/
export function deleteReplicateRequest(request_id) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/replicate/replicas/${auth_id}`,
method: 'put'
url: `/apps/${appid}/replicate/replicate_request/${request_id}`,
method: 'delete'
})
}
6 changes: 3 additions & 3 deletions packages/app-console/src/router/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ export const asyncRoutes = [
}
},
{
path: 'replicas',
component: () => import('@/views/replicate/replicas'),
name: 'ReplicateReplicas',
path: 'request',
component: () => import('@/views/replicate/request'),
name: 'ReplicateRequest',
meta: {
title: '请求部署',
icon: 'guide',
Expand Down
33 changes: 11 additions & 22 deletions packages/app-console/src/views/replicate/auth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
>
<template slot-scope="scope">
<el-tag
:type="scope.row.status === 'accept' ? 'success' : 'warning'"
:type="scope.row.status === 'accepted' ? 'success' : 'warning'"
>
{{ scope.row.status }}
</el-tag>
Expand Down Expand Up @@ -112,10 +112,9 @@
</template>

<script>
import { assert } from '@/utils/assert'
import store from '@/store'
import dayjs from 'dayjs'
import { getReplicateAuths, createReplicateAuth, updateReplicateAuth, deleteReplicateAuth, applyReplicateAuth, acceptReplicateAuth } from '../../api/replicate'
import { getReplicateAuths, createReplicateAuth, acceptReplicateAuth, deleteReplicateAuth } from '../../api/replicate'
export default {
data() {
Expand Down Expand Up @@ -163,7 +162,14 @@ export default {
this.listLoading = true
const res = await getReplicateAuths()
assert(res.code === 0, 'getReplicateAuths got error')
if (res.code) {
this.$notify({
type: 'error',
title: '操作失败',
message: res.message
})
return
}
this.list = res.data.map(item => {
item.created_at = dayjs(item.created_at).format('YYYY-MM-DD HH:mm:ss')
Expand Down Expand Up @@ -201,7 +207,7 @@ export default {
async handleUpdateAuth(auth) {
await this.$confirm('是否同意此授权?', '授权确认')
const res = await updateReplicateAuth(auth._id, 'accept')
const res = await acceptReplicateAuth(auth._id)
if (res.code) {
this.$notify({
type: 'error',
Expand All @@ -228,23 +234,6 @@ export default {
this.getReplicateAuths()
},
async applyReplicateAuth(auth) {
const params = {
auth_id: auth._id,
functions: {
type: 'all',
},
policies: {
type: 'all',
},
}
const res = await applyReplicateAuth(params)
// this.getReplicateAuths()
},
async acceptReplicateAuth(auth) {
const res = await acceptReplicateAuth(auth._id)
// this.getReplicateAuths()
},
},
}
Expand Down
Loading

0 comments on commit 0f6e3b0

Please sign in to comment.