pull/243/head
xiaojunnuo 2024-11-07 00:17:35 +08:00
parent 61b14b52d9
commit 17638f3d3a
5 changed files with 42 additions and 31 deletions

0
index.ts Normal file
View File

View File

@ -34,7 +34,8 @@
"license": "AGPL-3.0", "license": "AGPL-3.0",
"dependencies": { "dependencies": {
"axios": "^1.7.7", "axios": "^1.7.7",
"lodash-es": "^4.17.21" "lodash-es": "^4.17.21",
"typescript": "^5.4.2"
}, },
"workspaces": [ "workspaces": [
"packages/**" "packages/**"

View File

@ -1,4 +1,4 @@
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core'; import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { AppKey, PlusRequestService, verify } from '@certd/plus-core'; import { AppKey, PlusRequestService, verify } from '@certd/plus-core';
import { logger } from '@certd/basic'; import { logger } from '@certd/basic';
import { SysInstallInfo, SysLicenseInfo, SysSettingsService } from '../../settings/index.js'; import { SysInstallInfo, SysLicenseInfo, SysSettingsService } from '../../settings/index.js';
@ -8,15 +8,10 @@ import { SysInstallInfo, SysLicenseInfo, SysSettingsService } from '../../settin
export class PlusService { export class PlusService {
@Inject() @Inject()
sysSettingsService: SysSettingsService; sysSettingsService: SysSettingsService;
@Config('plus.server.baseUrls')
plusServerBaseUrls: string[];
async getPlusRequestService() { async getPlusRequestService() {
const subjectId = await this.getSubjectId(); const subjectId = await this.getSubjectId();
return new PlusRequestService({ return new PlusRequestService({ subjectId });
plusServerBaseUrls: this.plusServerBaseUrls,
subjectId,
});
} }
async getSubjectId() { async getSubjectId() {
@ -60,26 +55,16 @@ export class PlusService {
const licenseInfo: SysLicenseInfo = await this.sysSettingsService.getSetting(SysLicenseInfo); const licenseInfo: SysLicenseInfo = await this.sysSettingsService.getSetting(SysLicenseInfo);
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo); const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
const plusRequestService = await this.getPlusRequestService();
return await verify({ return await verify({
subjectId: plusRequestService.subjectId, subjectId: installInfo.siteId,
license: licenseInfo.license, license: licenseInfo.license,
plusRequestService: plusRequestService,
bindUrl: installInfo?.bindUrl, bindUrl: installInfo?.bindUrl,
}); });
} }
async bindUrl(subjectId: string, url: string) { async bindUrl(url: string) {
const plusRequestService = await this.getPlusRequestService(); const plusRequestService = await this.getPlusRequestService();
return await plusRequestService.request({ return await plusRequestService.bindUrl(url);
url: '/activation/subject/urlBind',
data: {
subjectId,
appKey: AppKey,
url,
},
});
} }
async register() { async register() {
@ -88,16 +73,11 @@ export class PlusService {
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo); const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
if (!licenseInfo?.license) { if (!licenseInfo?.license) {
//还没有license注册一个 //还没有license注册一个
const res = await plusRequestService.requestWithoutSign({ const license = await plusRequestService.register({
url: '/activation/subject/register',
data: {
appKey: AppKey,
subjectId: installInfo.siteId,
installTime: installInfo.installTime, installTime: installInfo.installTime,
},
}); });
if (res.license) { if (license) {
await this.updateLicense(res.license); await this.updateLicense(license);
logger.info('站点注册成功'); logger.info('站点注册成功');
} }
} }

View File

@ -0,0 +1,29 @@
# key: ./data/ssl/cert.key
# cert: ./data/ssl/cert.crt
#plus:
# server:
# baseUrl: 'http://127.0.0.1:11007'
#flyway:
# scriptDir: './db/migration-pg'
#typeorm:
# dataSource:
# default:
# type: postgres
# host: localhost
# port: 5433
# username: postgres
# password: root
# database: postgres
typeorm:
dataSource:
default:
database: './data/db-plus-dev.sqlite'
# plus server: 'http://127.0.0.1:11007'
account:
server:
baseUrl: 'http://127.0.0.1:1017/subject'

View File

@ -10,6 +10,7 @@
"commdev": "cross-env NODE_ENV=commdev mwtsc --watch --run @midwayjs/mock/app", "commdev": "cross-env NODE_ENV=commdev mwtsc --watch --run @midwayjs/mock/app",
"commpro": "cross-env NODE_ENV=commpro mwtsc --watch --run @midwayjs/mock/app", "commpro": "cross-env NODE_ENV=commpro mwtsc --watch --run @midwayjs/mock/app",
"pgdev": "cross-env NODE_ENV=pgdev mwtsc --watch --run @midwayjs/mock/app", "pgdev": "cross-env NODE_ENV=pgdev mwtsc --watch --run @midwayjs/mock/app",
"local-plus": "cross-env NODE_ENV=localplus mwtsc --watch --run @midwayjs/mock/app",
"pgpl": "cross-env NODE_ENV=pgpl mwtsc --watch --run @midwayjs/mock/app", "pgpl": "cross-env NODE_ENV=pgpl mwtsc --watch --run @midwayjs/mock/app",
"dev-new": "cross-env NODE_ENV=devnew mwtsc --watch --run @midwayjs/mock/app", "dev-new": "cross-env NODE_ENV=devnew mwtsc --watch --run @midwayjs/mock/app",
"rm-db-new": "rimraf ./data/db-new.sqlite", "rm-db-new": "rimraf ./data/db-new.sqlite",