Merge branch 'v2-dev' into v2-invite

This commit is contained in:
xiaojunnuo
2026-05-19 22:59:18 +08:00
41 changed files with 194 additions and 71 deletions
@@ -0,0 +1,17 @@
/// <reference types="mocha" />
/// <reference types="node" />
import assert from "node:assert/strict";
import { normalizeReleaseVersion } from "./app-controller.js";
describe("AppController.normalizeReleaseVersion", () => {
it("normalizes AtomGit release tag names", () => {
assert.equal(normalizeReleaseVersion({ tag_name: "v1.40.0" }), "1.40.0");
assert.equal(normalizeReleaseVersion({ tag_name: "1.40.0" }), "1.40.0");
});
it("falls back to release name when tag_name is empty", () => {
assert.equal(normalizeReleaseVersion({ name: "v1.40.0" }), "1.40.0");
});
});
@@ -3,6 +3,11 @@ import { BaseController, Constants, FileService, SysSettingsService, SysSiteInfo
import { http, logger } from '@certd/basic';
import { isComm } from '@certd/plus-core';
export function normalizeReleaseVersion(release: { tag_name?: string; name?: string }) {
const version = release?.tag_name || release?.name || '';
return version.replace(/^v/i, '');
}
/**
*/
@Provide()
@@ -17,12 +22,12 @@ export class AppController extends BaseController {
async latest(): Promise<any> {
try {
const res = await http.request({
url: 'https://registry.npmmirror.com/@certd/pipeline',
url: 'https://api.atomgit.com/api/v5/repos/certd/certd/releases/latest',
method: 'get',
logRes: false,
timeout: 5000,
});
const latest = res['dist-tags'].latest;
const latest = normalizeReleaseVersion(res);
return this.ok(latest);
} catch (e: any) {
logger.error(e);
@@ -1,5 +1,5 @@
import {Inject, Provide, Scope, ScopeEnum} from "@midwayjs/core";
import {BaseService, Constants, NeedSuiteException, NeedVIPException, SysSettingsService} from "@certd/lib-server";
import {BaseService, Constants, isEnterprise, NeedSuiteException, NeedVIPException, SysSettingsService} from "@certd/lib-server";
import {InjectEntityModel} from "@midwayjs/typeorm";
import {In, Repository} from "typeorm";
import {SiteInfoEntity} from "../entity/site-info.js";
@@ -59,25 +59,35 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
return this.repository;
}
async add(data: SiteInfoEntity) {
if (data.userId == null) {
throw new Error("userId is required");
async checkMonitorLimit(userId: number) {
if (isEnterprise()) {
//企业模式不限制
return;
}
if (isComm()) {
const suiteSetting = await this.userSuiteService.getSuiteSetting();
if (suiteSetting.enabled) {
const userSuite = await this.userSuiteService.getMySuiteDetail(data.userId);
const userSuite = await this.userSuiteService.getMySuiteDetail(userId);
if (userSuite.monitorCount.max != -1 && userSuite.monitorCount.max <= userSuite.monitorCount.used) {
throw new NeedSuiteException("站点监控数量已达上限,请购买或升级套餐");
}
}
} else if (!isPlus()) {
const count = await this.getUserMonitorCount(data.userId);
const count = await this.getUserMonitorCount(userId);
if (count >= 1) {
throw new NeedVIPException("站点监控数量已达上限,请升级专业版");
}
}
}
async add(data: SiteInfoEntity) {
if (data.userId == null) {
throw new Error("userId is required");
}
await this.checkMonitorLimit(data.userId);
data.disabled = false;
const found = await this.repository.findOne({