Compare commits
3 Commits
bc6df19c9c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| c5ee6d20e6 | |||
| dc56548cdf | |||
| f8e2f74d5e |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
node_modules
|
||||
dist
|
||||
.turbo
|
||||
24
bun.config.ts
Normal file
24
bun.config.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
|
||||
import { resolvePath } from '@kevisual/use-config';
|
||||
import { execSync } from 'node:child_process';
|
||||
|
||||
const buildFn = async (opts: { entry?: string, naming?: string }) => {
|
||||
const entry = opts.entry || 'agent/opencode.ts';
|
||||
const naming = opts.naming || 'opencode';
|
||||
const external: string[] = ["bun", "ws"];
|
||||
await Bun.build({
|
||||
target: 'node',
|
||||
format: 'esm',
|
||||
entrypoints: [resolvePath(entry, { meta: import.meta })],
|
||||
outdir: resolvePath('./dist', { meta: import.meta }),
|
||||
naming: {
|
||||
entry: `${naming}.js`,
|
||||
},
|
||||
external,
|
||||
});
|
||||
const cmd = `dts -i ${entry} -o ${naming}.d.ts`;
|
||||
execSync(cmd);
|
||||
};
|
||||
|
||||
await buildFn({ naming: 'config-permission', entry: 'src/config-permission.ts' });
|
||||
14
package.json
14
package.json
@@ -1,15 +1,14 @@
|
||||
{
|
||||
"name": "@kevisual/permission",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.4",
|
||||
"description": "",
|
||||
"main": "dist/config-permission.js",
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"dev": "tsup --watch",
|
||||
"dev:lib": "tsup --watch"
|
||||
"build": "bun run bun.config.ts"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
"dist",
|
||||
"src"
|
||||
],
|
||||
"keywords": [],
|
||||
"author": "abearxiong <xiongxiao@xiongxiao.me>",
|
||||
@@ -22,6 +21,9 @@
|
||||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tsup": "^8.4.0"
|
||||
"@kevisual/types": "^0.0.12",
|
||||
"@kevisual/use-config": "^1.0.28",
|
||||
"@types/bun": "^1.3.8",
|
||||
"@types/node": "^25.1.0"
|
||||
}
|
||||
}
|
||||
85
pnpm-lock.yaml
generated
Normal file
85
pnpm-lock.yaml
generated
Normal file
@@ -0,0 +1,85 @@
|
||||
lockfileVersion: '9.0'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
importers:
|
||||
|
||||
.:
|
||||
devDependencies:
|
||||
'@kevisual/types':
|
||||
specifier: ^0.0.12
|
||||
version: 0.0.12
|
||||
'@kevisual/use-config':
|
||||
specifier: ^1.0.28
|
||||
version: 1.0.28(dotenv@17.2.3)
|
||||
'@types/bun':
|
||||
specifier: ^1.3.8
|
||||
version: 1.3.8
|
||||
'@types/node':
|
||||
specifier: ^25.1.0
|
||||
version: 25.1.0
|
||||
|
||||
packages:
|
||||
|
||||
'@kevisual/load@0.0.6':
|
||||
resolution: {integrity: sha512-+3YTFehRcZ1haGel5DKYMUwmi5i6f2psyaPZlfkKU/cOXgkpwoG9/BEqPCnPjicKqqnksEpixVRkyHJ+5bjLVA==}
|
||||
|
||||
'@kevisual/types@0.0.12':
|
||||
resolution: {integrity: sha512-zJXH2dosir3jVrQ6QG4i0+iLQeT9gJ3H+cKXs8ReWboxBSYzUZO78XssVeVrFPsJ33iaAqo4q3DWbSS1dWGn7Q==}
|
||||
|
||||
'@kevisual/use-config@1.0.28':
|
||||
resolution: {integrity: sha512-ngF+LDbjxpXWrZNmnShIKF/jPpAa+ezV+DcgoZIIzHlRnIjE+rr9sLkN/B7WJbiH9C/j1tQXOILY8ujBqILrow==}
|
||||
peerDependencies:
|
||||
dotenv: ^17
|
||||
|
||||
'@types/bun@1.3.8':
|
||||
resolution: {integrity: sha512-3LvWJ2q5GerAXYxO2mffLTqOzEu5qnhEAlh48Vnu8WQfnmSwbgagjGZV6BoHKJztENYEDn6QmVd949W4uESRJA==}
|
||||
|
||||
'@types/node@25.1.0':
|
||||
resolution: {integrity: sha512-t7frlewr6+cbx+9Ohpl0NOTKXZNV9xHRmNOvql47BFJKcEG1CxtxlPEEe+gR9uhVWM4DwhnvTF110mIL4yP9RA==}
|
||||
|
||||
bun-types@1.3.8:
|
||||
resolution: {integrity: sha512-fL99nxdOWvV4LqjmC+8Q9kW3M4QTtTR1eePs94v5ctGqU8OeceWrSUaRw3JYb7tU3FkMIAjkueehrHPPPGKi5Q==}
|
||||
|
||||
dotenv@17.2.3:
|
||||
resolution: {integrity: sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
eventemitter3@5.0.4:
|
||||
resolution: {integrity: sha512-mlsTRyGaPBjPedk6Bvw+aqbsXDtoAyAzm5MO7JgU+yVRyMQ5O8bD4Kcci7BS85f93veegeCPkL8R4GLClnjLFw==}
|
||||
|
||||
undici-types@7.16.0:
|
||||
resolution: {integrity: sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==}
|
||||
|
||||
snapshots:
|
||||
|
||||
'@kevisual/load@0.0.6':
|
||||
dependencies:
|
||||
eventemitter3: 5.0.4
|
||||
|
||||
'@kevisual/types@0.0.12': {}
|
||||
|
||||
'@kevisual/use-config@1.0.28(dotenv@17.2.3)':
|
||||
dependencies:
|
||||
'@kevisual/load': 0.0.6
|
||||
dotenv: 17.2.3
|
||||
|
||||
'@types/bun@1.3.8':
|
||||
dependencies:
|
||||
bun-types: 1.3.8
|
||||
|
||||
'@types/node@25.1.0':
|
||||
dependencies:
|
||||
undici-types: 7.16.0
|
||||
|
||||
bun-types@1.3.8:
|
||||
dependencies:
|
||||
'@types/node': 25.1.0
|
||||
|
||||
dotenv@17.2.3: {}
|
||||
|
||||
eventemitter3@5.0.4: {}
|
||||
|
||||
undici-types@7.16.0: {}
|
||||
@@ -36,7 +36,7 @@ type ConfigPermissionOptions = {
|
||||
/**
|
||||
* 所有者
|
||||
*/
|
||||
owner: string;
|
||||
owner?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -49,6 +49,23 @@ export class ConfigPermission {
|
||||
this.permission = permission || ({} as Permission);
|
||||
this.owner = owner;
|
||||
}
|
||||
/**
|
||||
* 暴露的公共的permission的值
|
||||
*/
|
||||
getPublicPermission() {
|
||||
if (!this.permission?.share) return {};
|
||||
return {
|
||||
share: this.permission.share,
|
||||
};
|
||||
}
|
||||
static getDataPublicPermission(value: { data: { permission?: Permission }; [key: string]: any }) {
|
||||
const { data } = value;
|
||||
if (data.permission) {
|
||||
data.permission = new ConfigPermission({ permission: data.permission }).getPublicPermission();
|
||||
value.data = data;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查权限是否为公共权限
|
||||
@@ -117,7 +134,7 @@ export class ConfigPermission {
|
||||
*/
|
||||
checkPassword(password: string) {
|
||||
if (this.permission.password) {
|
||||
const ok = this.permission.password !== password;
|
||||
const ok = this.permission.password === password;
|
||||
return ok ? 'success' : 'error';
|
||||
}
|
||||
return 'none';
|
||||
@@ -143,6 +160,9 @@ export class ConfigPermission {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static create(opts: ConfigPermissionOptions) {
|
||||
return new ConfigPermission(opts);
|
||||
}
|
||||
}
|
||||
|
||||
export type UserPermissionOptions = {
|
||||
@@ -162,7 +182,12 @@ export class UserPermission extends ConfigPermission {
|
||||
constructor({ permission, owner }: ConfigPermissionOptions) {
|
||||
super({ permission, owner });
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查权限 20100 以上全是错误
|
||||
*
|
||||
* @param checkOptions
|
||||
* @returns
|
||||
*/
|
||||
checkPermission(checkOptions: UserPermissionOptions) {
|
||||
const { username, password } = checkOptions;
|
||||
|
||||
@@ -210,15 +235,21 @@ export class UserPermission extends ConfigPermission {
|
||||
}
|
||||
// 第三步,检查用户名
|
||||
const usernamesCheck = this.checkUsernames(username);
|
||||
if (usernamesCheck) {
|
||||
if (username && usernamesCheck) {
|
||||
return {
|
||||
code: 20003,
|
||||
message: '使用用户名访问',
|
||||
};
|
||||
}
|
||||
if (username) {
|
||||
return {
|
||||
code: 20004,
|
||||
meassage: '登陆的用户都能够访问',
|
||||
};
|
||||
}
|
||||
return {
|
||||
code: 20101,
|
||||
message: '资源是私有的',
|
||||
message: '资源是私有的,需要登陆',
|
||||
};
|
||||
}
|
||||
checkPermissionSuccess(checkOptions: UserPermissionOptions) {
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import { defineConfig } from 'tsup';
|
||||
|
||||
export default defineConfig({
|
||||
entry: ['src/config-permission.ts'],
|
||||
|
||||
splitting: false,
|
||||
sourcemap: false,
|
||||
clean: true,
|
||||
format: 'esm',
|
||||
dts: true,
|
||||
outDir: 'dist',
|
||||
tsconfig: 'tsconfig.json',
|
||||
});
|
||||
Reference in New Issue
Block a user