恢复文件

This commit is contained in:
Wang Kejun 2023-08-01 15:17:26 +08:00
parent c66a0fa5cc
commit f507bb4639
9 changed files with 1342 additions and 758 deletions

View File

@ -1,12 +1,11 @@
import { WebEnv, WechatMpEnv } from "../general-app-domain/Token/Schema";
import { WebEnv, WechatMpEnv } from '../general-app-domain/Token/Schema';
import { AppType } from '../general-app-domain/Application/Schema';
import { EntityDict } from "../general-app-domain";
import { QiniuUploadInfo } from "oak-frontend-base/lib/types/Upload";
import { Config, Origin } from "../types/Config";
import { BackendRuntimeContext } from "../context/BackendRuntimeContext";
import { CommonAspectDict } from "oak-common-aspect";
import { FrontendRuntimeContext } from "../context/FrontendRuntimeContext";
import { EntityDict } from '../general-app-domain';
import { QiniuUploadInfo } from 'oak-frontend-base/lib/types/Upload';
import { Config, Origin } from '../types/Config';
import { BackendRuntimeContext } from '../context/BackendRuntimeContext';
import { CommonAspectDict } from 'oak-common-aspect';
import { FrontendRuntimeContext } from '../context/FrontendRuntimeContext';
type GeneralAspectDict<
ED extends EntityDict,
@ -69,6 +68,13 @@ type GeneralAspectDict<
},
context: Cxt
) => Promise<void>;
wakeupParasite: (
params: {
id: string;
env: WebEnv | WechatMpEnv;
},
context: Cxt
) => Promise<string>;
getUploadInfo: (
params: { origin: Origin; bucket?: string; key?: string },
context: Cxt
@ -122,38 +128,37 @@ type GeneralAspectDict<
getMpUnlimitWxaCode: (
wechatQrCodeId: string,
context: Cxt
) => Promise<string>;
) => Promise<string>;
createWechatLogin: (
params: {
type: EntityDict['wechatLogin']['Schema']['type'];
interval: number;
},
context: Cxt
) => Promise<string>;
unbindingWechat: (
params: {
wechatUserId: string;
captcha?: string;
mobile?: string;
},
context: Cxt
) => Promise<void>;
loginByWechat: (
params: {
wechatLoginId: string;
env: WebEnv;
},
context: Cxt
) => Promise<string>;
getInfoByUrl: (
params: {
url: string;
},
) => Promise<{
title: string;
publishDate: number | undefined;
imageList: string[];
}>
) => Promise<string>;
unbindingWechat: (
params: {
wechatUserId: string;
captcha?: string;
mobile?: string;
},
context: Cxt
) => Promise<void>;
loginByWechat: (
params: {
wechatLoginId: string;
env: WebEnv;
},
context: Cxt
) => Promise<string>;
getInfoByUrl: (params: { url: string }) => Promise<{
title: string;
publishDate: number | undefined;
imageList: string[];
}>;
};
export type AspectDict<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>> = GeneralAspectDict<ED, Cxt>;
export type AspectDict<
ED extends EntityDict,
Cxt extends BackendRuntimeContext<ED>
> = GeneralAspectDict<ED, Cxt>;

View File

@ -9,6 +9,7 @@ import {
getWechatMpUserPhoneNumber,
logout,
loginByWechat,
wakeupParasite,
} from './token';
import { getUploadInfo, getInfoByUrl } from './extraFile';
import { getApplication, signatureJsSDK } from './application';
@ -24,6 +25,7 @@ const aspectDict = {
loginByMobile,
loginWechat,
loginWechatMp,
wakeupParasite,
syncUserInfoWechatMp,
getUploadInfo,
sendCaptcha,
@ -39,4 +41,4 @@ const aspectDict = {
getInfoByUrl,
};
export default aspectDict;
export default aspectDict;

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,7 @@ import mobileChecker from './mobile';
import wechatPublicTagChecker from './wechatPublicTag';
import messageChecker from './message';
import messageTypeTemplateId from './messageTypeTemplateId';
import parasite from './parasite';
const checkers = [
...mobileChecker,
@ -20,6 +21,7 @@ const checkers = [
...wechatPublicTagChecker,
...messageChecker,
...messageTypeTemplateId,
...parasite,
];

View File

@ -54,6 +54,7 @@ export interface Schema extends EntityShape {
entityId: String<64>;
user?: User;
player?: User;
disablesAt?: Datetime;
env: Environment;
};
@ -62,9 +63,14 @@ type Action = AbleAction;
const AbleActionDef: ActionDef<AbleAction, AbleState> = makeAbleActionDef('enabled');
const locale: LocaleDef<Schema, Action, '', {
ableState: AbleState,
}> = {
const locale: LocaleDef<
Schema,
Action,
'',
{
ableState: AbleState;
}
> = {
zh_CN: {
name: '令牌',
attr: {
@ -75,6 +81,7 @@ const locale: LocaleDef<Schema, Action, '', {
player: '扮演者',
env: '环境',
ableState: '状态',
disablesAt: '禁用时间',
},
action: {
enable: '激活',
@ -83,8 +90,8 @@ const locale: LocaleDef<Schema, Action, '', {
v: {
ableState: {
enabled: '使用中',
disabled: '已禁用'
disabled: '已禁用',
},
},
},
};
};

View File

@ -1,5 +1,9 @@
import { Feature } from 'oak-frontend-base/lib/types/Feature';
import { OakRowInconsistencyException, OakUnloggedInException, OakUserUnpermittedException } from 'oak-domain/lib/types/Exception';
import {
OakRowInconsistencyException,
OakUnloggedInException,
OakUserUnpermittedException,
} from 'oak-domain/lib/types/Exception';
import { Cache } from 'oak-frontend-base/lib/features/cache';
import { LocalStorage } from 'oak-frontend-base/lib/features/localStorage';
import { CommonAspectDict } from 'oak-common-aspect';
@ -226,4 +230,15 @@ export class Token<
});
this.publish();
}
}
async wakeupParasite(id: string) {
const env = await getEnv();
const { result } = await this.cache.exec('wakeupParasite', {
id,
env: env as WechatMpEnv,
});
this.tokenValue = result;
this.storage.save('token:token', result);
this.publish();
}
}

View File

@ -1,4 +1,4 @@
import { generateNewId } from 'oak-domain/lib/utils/uuid';
import { generateNewId, generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
import { CreateTrigger, Trigger } from 'oak-domain/lib/types/Trigger';
import { EntityDict } from '../general-app-domain/EntityDict';
import { CreateOperationData as CreateUserRoleData } from '../general-app-domain/UserRole/Schema';
@ -28,37 +28,39 @@ const triggers: Trigger<EntityDict, 'user', RuntimeCxt>[] = [
};
if (data instanceof Array) {
await Promise.all(
data.map(
async ele => {
Object.assign(ele, {
userSystem$user: [{
data.map(async (ele) => {
Object.assign(ele, {
userSystem$user: [
{
id: generateNewId(),
action: 'create',
data: {
id: generateNewId(),
systemId,
}
}],
})
setDefaultState(ele);
}
));
}
else {
},
},
],
});
setDefaultState(ele);
})
);
} else {
Object.assign(data, {
userSystem$user: [{
id: generateNewId(),
action: 'create',
data: {
userSystem$user: [
{
id: generateNewId(),
systemId,
}
}],
})
action: 'create',
data: {
id: generateNewId(),
systemId,
},
},
],
});
setDefaultState(data);
}
return 1;
}
},
} as CreateTrigger<EntityDict, 'user', RuntimeCxt>,
{
name: '系统生成的第一个用户默认注册为root用户的初始状态默认为shadow',
@ -69,43 +71,74 @@ const triggers: Trigger<EntityDict, 'user', RuntimeCxt>[] = [
const { data } = operation;
assert(!(data instanceof Array));
if (NO_ANY_USER) {
const result = await context.select('user', {
data: {
id: 1,
},
filter: {
id: {
$ne: ROOT_USER_ID,
},
},
indexFrom: 0,
count: 1,
}, {
dontCollect: true,
});
if (result.length === 0) {
await context.operate('userRole', {
id: generateNewId(),
action: 'create',
const result = await context.select(
'user',
{
data: {
id: generateNewId(),
userId: data.id,
roleId: ROOT_ROLE_ID,
relation: 'owner',
id: 1,
},
}, {
blockTrigger: true,
filter: {
id: {
$ne: ROOT_USER_ID,
},
},
indexFrom: 0,
count: 1,
},
{
dontCollect: true,
});
}
);
if (result.length === 0) {
await context.operate(
'userRole',
{
id: generateNewId(),
action: 'create',
data: {
id: generateNewId(),
userId: data.id,
roleId: ROOT_ROLE_ID,
relation: 'owner',
},
},
{
blockTrigger: true,
dontCollect: true,
}
);
return 1;
}
else {
} else {
NO_ANY_USER = false;
}
}
return 0;
}
},
} as CreateTrigger<EntityDict, 'user', RuntimeCxt>,
{
name: '当用户被激活时将所有的parasite作废',
entity: 'user',
action: 'activate',
when: 'before',
fn: async ({ operation }) => {
const { data } = operation as EntityDict['user']['Update'];
assert(!(data instanceof Array));
data.parasite$user = {
id: await generateNewIdAsync(),
action: 'update',
data: {
expired: true,
token$entity: {
id: await generateNewIdAsync(),
action: 'disable',
data: {},
},
},
};
return 1;
},
},
];
export default triggers;

View File

@ -1,5 +1,10 @@
import { EntityDict } from '../general-app-domain';
import { Watcher } from 'oak-domain/lib/types';
import { BackendRuntimeContext } from '../context/BackendRuntimeContext';
import token from './token';
export default [] as Watcher<EntityDict, keyof EntityDict, BackendRuntimeContext<EntityDict>>[];
export default [...token] as Watcher<
EntityDict,
keyof EntityDict,
BackendRuntimeContext<EntityDict>
>[];

25
src/watchers/token.ts Normal file
View File

@ -0,0 +1,25 @@
import { EntityDict } from '../general-app-domain';
import { BackendRuntimeContext } from '../context/BackendRuntimeContext';
import { Watcher, BBWatcher } from 'oak-domain/lib/types/Watcher';
const watchers: Watcher<
EntityDict,
'token',
BackendRuntimeContext<EntityDict>
>[] = [
{
name: '使定期禁用的token被禁用',
entity: 'token',
filter() {
const now = Date.now();
return {
disablesAt: {
$lt: now,
},
ableState: 'enabled',
};
},
action: 'disable',
actionData: {},
},
];
export default watchers;