mirror of
https://github.com/certd/certd.git
synced 2026-05-21 01:37:37 +08:00
perf(controller): 更换版本获取源并添加版本标准化处理
将npm镜像源的版本查询替换为AtomGit仓库的最新release接口,新增normalizeReleaseVersion方法标准化版本号格式,移除v前缀
This commit is contained in:
@@ -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 { http, logger } from '@certd/basic';
|
||||||
import { isComm } from '@certd/plus-core';
|
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()
|
@Provide()
|
||||||
@@ -17,12 +22,12 @@ export class AppController extends BaseController {
|
|||||||
async latest(): Promise<any> {
|
async latest(): Promise<any> {
|
||||||
try {
|
try {
|
||||||
const res = await http.request({
|
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',
|
method: 'get',
|
||||||
logRes: false,
|
logRes: false,
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
});
|
});
|
||||||
const latest = res['dist-tags'].latest;
|
const latest = normalizeReleaseVersion(res);
|
||||||
return this.ok(latest);
|
return this.ok(latest);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user