v3
veypi 1 month ago
parent d8544a48dd
commit e7786e3042

@ -0,0 +1,26 @@
//
// nats.go
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-10-11 17:32
// Distributed under terms of the MIT license.
//
package cfg
import (
"github.com/nats-io/nats-server/v2/server"
"github.com/veypi/utils/logv"
)
func RunNats() {
opts := &server.Options{
ConfigFile: "~/.config/oa/nats.cfg2",
}
ns, err := server.NewServer(opts)
if err != nil {
panic(err)
}
// Start the nats server
logv.Info().Msg("nats server start")
ns.Start()
}

@ -10,6 +10,7 @@ require (
github.com/go-sql-driver/mysql v1.7.0
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/google/uuid v1.6.0
github.com/nats-io/nats-server/v2 v2.10.21
github.com/veypi/OneBD v0.0.0-00010101000000-000000000000
github.com/veypi/utils v0.3.7
gorm.io/driver/mysql v1.5.7
@ -19,9 +20,17 @@ require (
require (
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/minio/highwayhash v1.0.3 // indirect
github.com/nats-io/jwt/v2 v2.5.8 // indirect
github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/rs/zerolog v1.17.2 // indirect
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.6.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

@ -11,19 +11,41 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/minio/highwayhash v1.0.3 h1:kbnuUMoHYyVl7szWjSxJnxw11k2U709jqFPPmIUyD6Q=
github.com/minio/highwayhash v1.0.3/go.mod h1:GGYsuwP/fPD6Y9hMiXuapVvlIUEhFhMTh0rxU3ik1LQ=
github.com/nats-io/jwt/v2 v2.5.8 h1:uvdSzwWiEGWGXf+0Q+70qv6AQdvcvxrv9hPM0RiPamE=
github.com/nats-io/jwt/v2 v2.5.8/go.mod h1:ZdWS1nZa6WMZfFwwgpEaqBV8EPGVgOTDHN/wTbz0Y5A=
github.com/nats-io/nats-server/v2 v2.10.21 h1:gfG6T06wBdI25XyY2IsauarOc2srWoFxxfsOKjrzoRA=
github.com/nats-io/nats-server/v2 v2.10.21/go.mod h1:I1YxSAEWbXCfy0bthwvNb5X43WwIWMz7gx5ZVPDr5Rc=
github.com/nats-io/nats.go v1.36.0 h1:suEUPuWzTSse/XhESwqLxXGuj8vGRuPRoG7MoRN/qyU=
github.com/nats-io/nats.go v1.36.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8=
github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=
github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.17.2 h1:RMRHFw2+wF7LO0QqtELQwo8hqSmqISyCJeFeAAuWcRo=
github.com/rs/zerolog v1.17.2/go.mod h1:9nvC1axdVrAHcu/s9taAVfBuIdTZLVQmKQyvrUjF5+I=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

@ -27,6 +27,7 @@ func main() {
}
func runWeb() error {
go cfg.RunNats()
app, err := rest.New(&cfg.Config.RestConf)
if err != nil {
return err

@ -3,8 +3,7 @@ package models
import "time"
type AppGet struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_id"`
Name string `json:"name" parse:"json"`
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_id"`
}
type AppPatch struct {

@ -7,7 +7,7 @@ import (
type App struct {
BaseModel
Name string `json:"name" methods:"get,post,*patch,*list" parse:"json"`
Name string `json:"name" methods:"post,*patch,*list" parse:"json"`
Icon string `json:"icon" methods:"post,*patch" parse:"json"`
Des string `json:"des" methods:"post,*patch" parse:"json"`
Participate string `json:"participate" gorm:"default:auto" methods:"post,*patch" parse:"json"`

@ -17,7 +17,7 @@ export interface ListQuery {
updated_at?: Date
}
export function List(json: ListOpts, query: ListQuery) {
return webapi.Get<models.Access>(`/access`, { json, query })
return webapi.Get<[models.Access]>(`/access`, { json, query })
}
export interface PostOpts {

@ -6,11 +6,8 @@
import webapi from "./webapi"
import * as models from "./models"
export interface GetOpts {
name: string
}
export function Get(app_id: string, json: GetOpts) {
return webapi.Get<models.App>(`/app/${app_id}`, { json })
export function Get(app_id: string) {
return webapi.Get<models.App>(`/app/${app_id}`, {})
}
export interface PatchOpts {
@ -25,7 +22,7 @@ export function Patch(app_id: string, json: PatchOpts) {
}
export function Delete(app_id: string) {
return webapi.Delete<models.App>(`/app/${app_id}`, { })
return webapi.Delete<models.App>(`/app/${app_id}`, {})
}
export interface PostOpts {
@ -42,7 +39,7 @@ export interface ListOpts {
name?: string
}
export function List(json: ListOpts) {
return webapi.Get<models.App>(`/app`, { json })
return webapi.Get<[models.App]>(`/app`, { json })
}
export interface AppUserGetOpts {
@ -60,7 +57,7 @@ export function AppUserPatch(app_user_id: string, app_id: string, json: AppUserP
}
export function AppUserDelete(app_user_id: string, app_id: string) {
return webapi.Delete<models.AppUser>(`/app/${app_id}/app_user/${app_user_id}`, { })
return webapi.Delete<models.AppUser>(`/app/${app_id}/app_user/${app_user_id}`, {})
}
export interface AppUserListOpts {
@ -68,7 +65,7 @@ export interface AppUserListOpts {
status?: string
}
export function AppUserList(app_id: string, json: AppUserListOpts) {
return webapi.Get<models.AppUser>(`/app/${app_id}/app_user`, { json })
return webapi.Get<[models.AppUser]>(`/app/${app_id}/app_user`, { json })
}
export interface AppUserPostOpts {
@ -84,7 +81,7 @@ export interface ResourceListQuery {
updated_at?: Date
}
export function ResourceList(app_id: string, query: ResourceListQuery) {
return webapi.Get<models.Resource>(`/app/${app_id}/resource`, { query })
return webapi.Get<[models.Resource]>(`/app/${app_id}/resource`, { query })
}
export interface ResourcePostOpts {
@ -103,10 +100,10 @@ export function ResourceDelete(app_id: string, json: ResourceDeleteOpts) {
}
export function ResourceGet(app_id: string) {
return webapi.Get<models.Resource>(`/app/${app_id}/resource`, { })
return webapi.Get<models.Resource>(`/app/${app_id}/resource`, {})
}
export function ResourcePatch(app_id: string) {
return webapi.Patch<models.Resource>(`/app/${app_id}/resource`, { })
return webapi.Patch<models.Resource>(`/app/${app_id}/resource`, {})
}

@ -76,3 +76,4 @@ export interface UserRole {
app_id: string
status: string
}

@ -36,6 +36,6 @@ export interface ListOpts {
name?: string
}
export function List(json: ListOpts) {
return webapi.Get<models.Role>(`/role`, { json })
return webapi.Get<[models.Role]>(`/role`, { json })
}

@ -30,7 +30,7 @@ export function Post(json: PostOpts) {
return webapi.Post<string>(`/token`, { json })
}
export function Get(token_id: string) {
return webapi.Get<models.Token>(`/token/${token_id}`, {})
return webapi.Get<models.Token>(`/token/${token_id}`, { })
}
export interface PatchOpts {
@ -42,7 +42,7 @@ export function Patch(token_id: string, json: PatchOpts) {
}
export function Delete(token_id: string) {
return webapi.Delete<models.Token>(`/token/${token_id}`, {})
return webapi.Delete<models.Token>(`/token/${token_id}`, { })
}
export interface ListOpts {
@ -50,6 +50,6 @@ export interface ListOpts {
app_id: string
}
export function List(json: ListOpts) {
return webapi.Get<models.Token>(`/token`, { json })
return webapi.Get<[models.Token]>(`/token`, { json })
}

@ -7,7 +7,7 @@
import webapi from "./webapi"
import * as models from "./models"
export function Get(user_id: string) {
return webapi.Get<models.User>(`/user/${user_id}`, {})
return webapi.Get<models.User>(`/user/${user_id}`, { })
}
export interface PatchOpts {
@ -23,7 +23,7 @@ export function Patch(user_id: string, json: PatchOpts) {
}
export function Delete(user_id: string) {
return webapi.Delete<models.User>(`/user/${user_id}`, {})
return webapi.Delete<models.User>(`/user/${user_id}`, { })
}
export interface PostOpts {
@ -47,11 +47,11 @@ export interface ListOpts {
status?: number
}
export function List(json: ListOpts) {
return webapi.Get<models.User>(`/user`, { json })
return webapi.Get<[models.User]>(`/user`, { json })
}
export function UserRoleGet(user_role_id: string, user_id: string) {
return webapi.Get<models.UserRole>(`/user/${user_id}/user_role/${user_role_id}`, {})
return webapi.Get<models.UserRole>(`/user/${user_id}/user_role/${user_role_id}`, { })
}
export interface UserRolePatchOpts {
@ -82,6 +82,6 @@ export interface UserRoleListOpts {
status?: string
}
export function UserRoleList(user_id: string, json: UserRoleListOpts) {
return webapi.Get<models.UserRole>(`/user/${user_id}/user_role`, { json })
return webapi.Get<[models.UserRole]>(`/user/${user_id}/user_role`, { json })
}

@ -1,6 +1,6 @@
//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-10-11 14:37:08
// 2024-10-11 15:31:08
// Distributed under terms of the MIT license.
//

@ -8,7 +8,6 @@
export * from './api/models'
export type Dict = { [key: string]: any }
export enum ArgType {
Text = 'text',
Password = 'password',
@ -53,3 +52,11 @@ export interface DocGroup {
items?: DocItem[]
}
export enum AUStatus {
OK = 0,
Disabled = 1,
Applying = 2,
Deny = 3,
}

@ -1,101 +0,0 @@
/*
* auth.ts
* Copyright (C) 2023 veypi <i@veypi.com>
* 2023-10-02 16:44
* Distributed under terms of the MIT license.
*/
export interface modelsSimpleAuth {
level: number
name: string
tid: string
}
export const R = {
// 应用管理配置权限
App: 'app',
// 用户管理和绑定应用权限
User: 'user',
// 权限资源定义权限
Resource: 'resource',
// 角色管理和绑定用户权限
Role: 'role',
// 权限管理和绑定角色权限
Auth: 'auth',
}
export enum AccessLevel {
None = 0,
Do = 1,
Read = 1,
Create = 2,
Update = 3,
Delete = 4,
All = 5
}
export const LevelOptions = [
{ key: 0, name: '无权限' },
{ key: 1, name: '读取数据权限' },
{ key: 2, name: '创建数据权限' },
{ key: 3, name: '更新数据权限' },
{ key: 4, name: '删除数据权限' },
{ key: 5, name: '管理员权限' },
]
class authLevel {
level = AccessLevel.None
constructor(level: number) {
this.level = level
}
CanDo(): boolean {
return this.level >= AccessLevel.Do
}
CanRead(): boolean {
return this.level >= AccessLevel.Read
}
CanCreate(): boolean {
return this.level >= AccessLevel.Create
}
CanUpdate(): boolean {
return this.level >= AccessLevel.Update
}
CanDelete(): boolean {
return this.level >= AccessLevel.Delete
}
CanDoAny(): boolean {
return this.level >= AccessLevel.All
}
}
export class auths {
private readonly list: modelsSimpleAuth[]
constructor(auths: modelsSimpleAuth[]) {
this.list = auths
}
Get(name: string, rid: string): authLevel {
let l = AccessLevel.None
for (let i of this.list) {
if (i.name == name && (!i.tid || i.tid === rid) && i.level > l) {
l = i.level
}
}
return new authLevel(l)
}
}
export interface Auths {
Get(name: string, rid: string): authLevel
}
export function NewAuths(a: modelsSimpleAuth[]): Auths {
return new auths(a)
}

@ -1,9 +0,0 @@
/*
* @name: index
* @author: veypi <i@veypi.com>
* @date: 2021-11-18 17:36
* @descriptionindex
*/
export { type Auths, type modelsSimpleAuth, NewAuths, R, AccessLevel, LevelOptions } from './auth'

@ -67,23 +67,24 @@
</template>
<script setup lang="ts">
import type { models } from '#imports';
import msg from '@veypi/msg';
let user = useUserStore()
let apps = ref<modelsApp[]>([]);
let ofApps = ref<modelsApp[]>([]);
let apps = ref<models.App[]>([]);
let ofApps = ref<models.App[]>([]);
function getApps() {
api.app.list().then(
(e: modelsApp[]) => {
api.app.List({}).then(
(e) => {
apps.value = e;
api.app.user('-').list(user.id).then((aus: modelsAppUser[]) => {
api.app.AppUserList("*", { user_id: user.id }).then(aus => {
for (let i in aus) {
let ai = apps.value.findIndex(a => a.id === aus[i].app_id)
if (ai >= 0) {
if (aus[i].status === AUStatus.OK) {
if (aus[i].status === "ok") {
ofApps.value.push(apps.value[ai])
apps.value.splice(ai, 1)
}
@ -110,8 +111,10 @@ let rules = {
};
function create_new() {
api.app.create(temp_app.value.name, temp_app.value.icon).then((e:
modelsApp) => {
api.app.Post({
name: temp_app.value.name, icon: temp_app.value.icon,
des: "", participate: "auto"
}).then((e: models.App) => {
ofApps.value.push(e);
msg.Info("创建成功");
new_flag.value = false;

@ -152,6 +152,7 @@ const login = () => {
localStorage.setItem('refresh', e)
api.token.Post({ user_id: id, token: e }).then(e => {
localStorage.setItem('token', e)
redirect("")
console.log(e)
})
}).catch(e => {
@ -193,7 +194,7 @@ const register = () => {
}
let salt = crypto.lib.WordArray.random(128 / 8).toString()
let key = deriveKey(data.value.password, salt)
api.user.reg({
api.user.Post({
username: data.value.username,
salt: salt,
code: key.toString(crypto.enc.Hex)
@ -225,11 +226,13 @@ function redirect(url: string) {
url = ''
}
if (uuid.value && uuid.value !== app.id) {
api.app.get(uuid.value as string).then((app) => {
api.token(uuid.value as string).get({
token: util.getToken(),
api.app.Get(uuid.value as string).then((app) => {
api.token.Post({
token: localStorage.getItem('refresh') || '',
user_id: uuid.value as string,
app_id: uuid.value as string,
}).then(e => {
url = url || app.redirect
url = url || app.init_url
// let data = JSON.parse(Base64.decode(e.split('.')[1]))
// console.log(data)
e = encodeURIComponent(e)
@ -269,6 +272,7 @@ onMounted(() => {
if (ifLogOut.value) {
util.setToken('')
} else if (util.checkLogin()) {
console.log(util.checkLogin())
redirect(route.query.redirect as string || '')
}
})

Loading…
Cancel
Save