key update

master
veypi 1 year ago
parent ae1b5608bd
commit f7ee8f7523

@ -13,7 +13,7 @@ use tracing::info;
use crate::{ use crate::{
libs, libs,
models::{access, app, rand_str, AccessLevel, Token}, models::{self, access, app, rand_str, AccessLevel, Token},
AppState, Error, Result, AppState, Error, Result,
}; };
@ -29,6 +29,24 @@ pub async fn get(id: web::Path<String>, stat: web::Data<AppState>) -> Result<imp
} }
} }
#[get("/app/{id}/key")]
#[access_delete("app")]
pub async fn get_key(id: web::Path<String>, stat: web::Data<AppState>) -> Result<impl Responder> {
let n = id.into_inner();
let obj = models::app::Entity::find_by_id(&n).one(stat.db()).await?;
if let Some(obj) = obj {
// Into ActiveModel
let mut obj: models::app::ActiveModel = obj.into();
let key = rand_str(32);
obj.key = sea_orm::ActiveValue::Set(key.clone());
obj.update(stat.db()).await?;
Ok(key)
} else {
Err(Error::NotFound(n))
}
}
#[get("/app/")] #[get("/app/")]
#[access_read("app")] #[access_read("app")]
pub async fn list(stat: web::Data<AppState>) -> Result<impl Responder> { pub async fn list(stat: web::Data<AppState>) -> Result<impl Responder> {

@ -25,6 +25,7 @@ pub fn routes(cfg: &mut web::ServiceConfig) {
.service(user::update) .service(user::update)
.service(user::delete); .service(user::delete);
cfg.service(app::get) cfg.service(app::get)
.service(app::get_key)
.service(app::list) .service(app::list)
.service(app::create) .service(app::create)
.service(app::update) .service(app::update)

@ -14,7 +14,7 @@ export default {
return ajax.get(this.local, { option: 'oa' }) return ajax.get(this.local, { option: 'oa' })
}, },
getKey(uuid: string) { getKey(uuid: string) {
return ajax.get(this.local + uuid, { option: 'key' }) return ajax.get(this.local + uuid + '/key')
}, },
create(name: string, icon: string) { create(name: string, icon: string) {
return ajax.post(this.local, { name, icon }) return ajax.post(this.local, { name, icon })

@ -8,6 +8,7 @@
// import '@veypi/oaer' // import '@veypi/oaer'
import oaer from '@veypi/oaer' import oaer from '@veypi/oaer'
import '@veypi/oaer/dist/index.css'
import bus from 'src/libs/bus' import bus from 'src/libs/bus'
import util from 'src/libs/util' import util from 'src/libs/util'

@ -20,7 +20,8 @@
</template> </template>
<template #k_key> <template #k_key>
<div class="w-full div-center"> <div class="w-full div-center">
<q-btn color='primary'>获取秘钥</q-btn> <q-btn color='primary' @click="getkey"></q-btn>
<span class="mx-2 select-all" v-if="tmpkey">{{ tmpkey }}</span>
</div> </div>
</template> </template>
<template #k_redirect_append> <template #k_redirect_append>
@ -42,6 +43,9 @@ import { inject, onMounted, Ref, ref } from 'vue';
import uploader from 'src/components/uploader'; import uploader from 'src/components/uploader';
import api from 'src/boot/api'; import api from 'src/boot/api';
import msg from '@veypi/msg'; import msg from '@veypi/msg';
import { useQuasar, copyToClipboard } from 'quasar';
let $q = useQuasar();
const keys = ref<any>([ const keys = ref<any>([
{ {
name: 'name', name: 'name',
@ -73,6 +77,28 @@ const save = () => {
}) })
} }
const tmpkey = ref('')
const getkey = () => {
$q.dialog({
title: '是否确定获取key',
message: '该操作会导致旧key失效',
cancel: true,
persistent: true
}).onOk(() => {
api.app.getKey(app.value.id).then(e => {
console.log(e)
tmpkey.value = e
copyToClipboard(e).then(e => {
msg.Info('已复制到剪贴板')
}).catch(e => {
tmpkey.value = e
})
}).catch(e => {
msg.Warn('获取失败 ' + e)
})
})
}
onMounted(() => { onMounted(() => {
}) })

@ -530,10 +530,10 @@
resolved "https://registry.yarnpkg.com/@veypi/msg/-/msg-0.1.1.tgz#94864ae2c0a81991b8a30d87f12d2245fdebbead" resolved "https://registry.yarnpkg.com/@veypi/msg/-/msg-0.1.1.tgz#94864ae2c0a81991b8a30d87f12d2245fdebbead"
integrity sha512-UiAF/Y0EGT/37tGApptzHBNUpo78LbnrEkCqGAGMkJp86wrUyOgTAvuvQ197Ifqw9PIbjZM9dAgMv4DfMJQEYA== integrity sha512-UiAF/Y0EGT/37tGApptzHBNUpo78LbnrEkCqGAGMkJp86wrUyOgTAvuvQ197Ifqw9PIbjZM9dAgMv4DfMJQEYA==
"@veypi/oaer@^0.0.5": "@veypi/oaer@^0.0.6":
version "0.0.5" version "0.0.6"
resolved "https://registry.yarnpkg.com/@veypi/oaer/-/oaer-0.0.5.tgz#e29626baad7fb32c8764c13b5b1c11c41ff04404" resolved "https://registry.yarnpkg.com/@veypi/oaer/-/oaer-0.0.6.tgz#02a1f9c54ec4e43805123a9f16ddfeda152e6758"
integrity sha512-QkYfpvu09b09YUByiS/ybmSeY6wKfjQZeEVTjWpqA1N4pU9/lQV9mXGPJmF2DduXD9EipctK4qzlsq1lsttoPA== integrity sha512-B1czF/GGWPCVRdtXvqVjTE9m/Tli8fmhy9K6lPnbt89QzkdYVmQ6DMs1rugMlPw+Lflc3pqeQuCUmlKjKgMqPQ==
dependencies: dependencies:
"@veypi/msg" "^0.1.0" "@veypi/msg" "^0.1.0"
"@veypi/one-icon" "2" "@veypi/one-icon" "2"

Loading…
Cancel
Save