UnisKB/ui/src/api/application/application-key.ts

79 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-06-10 12:07:14 +00:00
import { Result } from '@/request/Result'
import { get, post, del, put } from '@/request/index'
2025-06-16 04:08:09 +00:00
import useStore from '@/stores'
2025-06-10 12:07:14 +00:00
import { type Ref } from 'vue'
2025-06-16 04:08:09 +00:00
const prefix: any = { _value: '/workspace/' }
Object.defineProperty(prefix, 'value', {
get: function () {
const { user } = useStore()
return this._value + user.getWorkspaceId() + '/application'
},
})
2025-06-10 12:07:14 +00:00
/**
* API_KEY
* @param application_id
*/
const getAPIKey: (application_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
application_id,
loading,
) => {
2025-06-16 04:08:09 +00:00
return get(`${prefix.value}/${application_id}/application`, undefined, loading)
2025-06-10 12:07:14 +00:00
}
/**
* API_KEY
* @param application_id
*/
const postAPIKey: (application_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
application_id,
loading,
) => {
2025-06-16 04:08:09 +00:00
return post(`${prefix.value}/${application_id}/application`, {}, undefined, loading)
2025-06-10 12:07:14 +00:00
}
/**
* API_KEY
* @param application_id api_key_id
*/
const delAPIKey: (
application_id: string,
api_key_id: string,
loading?: Ref<boolean>,
) => Promise<Result<boolean>> = (application_id, api_key_id, loading) => {
2025-06-16 04:08:09 +00:00
return del(
`${prefix.value}/${application_id}/application/${api_key_id}`,
undefined,
undefined,
loading,
)
2025-06-10 12:07:14 +00:00
}
/**
* API_KEY
* @param application_id,api_key_id
* data {
* is_active: boolean
* }
*/
const putAPIKey: (
application_id: string,
api_key_id: string,
data: any,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (application_id, api_key_id, data, loading) => {
2025-06-16 04:08:09 +00:00
return put(
`${prefix.value}/${application_id}/application/${api_key_id}`,
data,
undefined,
loading,
)
2025-06-10 12:07:14 +00:00
}
export default {
getAPIKey,
postAPIKey,
delAPIKey,
putAPIKey,
}