From e76ec1d77020b0e5f6b3585cdb7cc65e62ae5f2c Mon Sep 17 00:00:00 2001
From: jingyang <3161362058@qq.com>
Date: Sun, 17 Dec 2023 17:48:40 +0800
Subject: [PATCH 1/2] fix template readme img src
Signed-off-by: jingyang <3161362058@qq.com>
---
.../template/src/pages/deploy/components/ReadMe.tsx | 10 +++++-----
frontend/providers/template/src/utils/tools.ts | 5 +++--
service/license/src/pages/api/cluster/activeCluster.ts | 4 ++--
service/license/src/services/backend/db/payment.ts | 3 +--
4 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/frontend/providers/template/src/pages/deploy/components/ReadMe.tsx b/frontend/providers/template/src/pages/deploy/components/ReadMe.tsx
index 4e33b41ccf1..9eb76dad561 100644
--- a/frontend/providers/template/src/pages/deploy/components/ReadMe.tsx
+++ b/frontend/providers/template/src/pages/deploy/components/ReadMe.tsx
@@ -50,7 +50,9 @@ const ReadMe = ({ templateDetail }: { templateDetail: TemplateType }) => {
// @ts-ignore
const myRewrite = (node, index, parent) => {
if (node.tagName === 'img' && !node.properties.src.startsWith('http')) {
- node.properties.src = `https://raw.githubusercontent.com/${githubOptions?.organization}/${githubOptions?.repository}/${githubOptions?.branch}/${node.properties.src}`;
+ const imgSrc = node.properties.src.replace(/^\.\/|^\//, '');
+
+ node.properties.src = `https://${githubOptions?.hostname}/${githubOptions?.organization}/${githubOptions?.repository}/${githubOptions?.branch}/${imgSrc}`;
}
};
@@ -61,8 +63,7 @@ const ReadMe = ({ templateDetail }: { templateDetail: TemplateType }) => {
borderBottom={'1px solid #DEE0E2'}
color={'#24282C'}
fontSize={'18px'}
- fontWeight={500}
- >
+ fontWeight={500}>
README.md
@@ -70,8 +71,7 @@ const ReadMe = ({ templateDetail }: { templateDetail: TemplateType }) => {
+ remarkPlugins={[remarkGfm, remarkUnwrapImages]}>
{templateReadMe}
diff --git a/frontend/providers/template/src/utils/tools.ts b/frontend/providers/template/src/utils/tools.ts
index 1df9b976db1..badc04e4d58 100644
--- a/frontend/providers/template/src/utils/tools.ts
+++ b/frontend/providers/template/src/utils/tools.ts
@@ -194,9 +194,10 @@ export function downLoadBold(content: BlobPart, type: string, fileName: string)
export const parseGithubUrl = (url: string) => {
if (!url) return null;
- var urlObj = new URL(url);
- var pathParts = urlObj.pathname.split('/');
+ let urlObj = new URL(url);
+ let pathParts = urlObj.pathname.split('/');
return {
+ hostname: urlObj.hostname,
organization: pathParts[1],
repository: pathParts[2],
branch: pathParts[3]
diff --git a/service/license/src/pages/api/cluster/activeCluster.ts b/service/license/src/pages/api/cluster/activeCluster.ts
index 76ca842147a..30a774aed29 100644
--- a/service/license/src/pages/api/cluster/activeCluster.ts
+++ b/service/license/src/pages/api/cluster/activeCluster.ts
@@ -70,7 +70,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const _token = generateLicenseToken({
type: 'Account',
- clusterID: clusterId,
+ clusterID: kubeSystemID,
data: { amount: payment.amount }
});
@@ -98,7 +98,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const handleStandardAndLicense = async () => {
const _token = generateLicenseToken({
type: 'Account',
- clusterID: clusterId,
+ clusterID: kubeSystemID,
data: { amount: 299 }
});
const record: LicenseRecordPayload = {
diff --git a/service/license/src/services/backend/db/payment.ts b/service/license/src/services/backend/db/payment.ts
index 505e3123c9b..83a53e95056 100644
--- a/service/license/src/services/backend/db/payment.ts
+++ b/service/license/src/services/backend/db/payment.ts
@@ -1,6 +1,5 @@
-import { LicenseType, PaymentDB, PaymentStatus, TPayMethod } from '@/types';
+import { PaymentDB, PaymentStatus, TPayMethod } from '@/types';
import { connectToDatabase } from './mongodb';
-import { createLicenseRecord, generateLicenseToken } from './license';
async function connectPaymentCollection() {
const client = await connectToDatabase();
From 8456c3a73706368ebfd92a894bfed57397949ac7 Mon Sep 17 00:00:00 2001
From: jingyang <3161362058@qq.com>
Date: Sun, 17 Dec 2023 19:04:12 +0800
Subject: [PATCH 2/2] add cdn env
Signed-off-by: jingyang <3161362058@qq.com>
---
.../template/src/pages/api/listTemplate.ts | 26 ++++++++++++++++++-
.../providers/template/src/utils/tools.ts | 4 ++-
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/frontend/providers/template/src/pages/api/listTemplate.ts b/frontend/providers/template/src/pages/api/listTemplate.ts
index 013f3524e06..3db4850c75f 100644
--- a/frontend/providers/template/src/pages/api/listTemplate.ts
+++ b/frontend/providers/template/src/pages/api/listTemplate.ts
@@ -1,19 +1,43 @@
import { jsonRes } from '@/services/backend/response';
import { ApiResp } from '@/services/kubernet';
import { TemplateType } from '@/types/app';
+import { parseGithubUrl } from '@/utils/tools';
import fs from 'fs';
import type { NextApiRequest, NextApiResponse } from 'next';
import path from 'path';
+function replaceRawWithCDN(url: string, cdnUrl: string) {
+ let parsedUrl = parseGithubUrl(url);
+ if (!parsedUrl || !cdnUrl) return url;
+
+ if (parsedUrl.hostname === 'raw.githubusercontent.com') {
+ const newUrl = `https://${cdnUrl}/gh/${parsedUrl.organization}/${parsedUrl.repository}@${parsedUrl.branch}/${parsedUrl.remainingPath}`;
+ return newUrl;
+ }
+
+ return url;
+}
+
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const originalPath = process.cwd();
const jsonPath = path.resolve(originalPath, 'fast_deploy_template.json');
+ const cdnUrl = process.env.CDN_URL;
try {
if (fs.existsSync(jsonPath)) {
const jsonData = fs.readFileSync(jsonPath, 'utf8');
const _templates: TemplateType[] = JSON.parse(jsonData);
- const templates = _templates.filter((item) => item?.spec?.draft !== true);
+
+ const templates = _templates
+ .filter((item) => item?.spec?.draft !== true)
+ .map((item) => {
+ if (!!cdnUrl) {
+ item.spec.readme = replaceRawWithCDN(item.spec.readme, cdnUrl);
+ item.spec.icon = replaceRawWithCDN(item.spec.icon, cdnUrl);
+ }
+ return item;
+ });
+
return jsonRes(res, { data: templates, code: 200 });
} else {
return jsonRes(res, { data: [], code: 200 });
diff --git a/frontend/providers/template/src/utils/tools.ts b/frontend/providers/template/src/utils/tools.ts
index badc04e4d58..2a8ec0b8d99 100644
--- a/frontend/providers/template/src/utils/tools.ts
+++ b/frontend/providers/template/src/utils/tools.ts
@@ -196,11 +196,13 @@ export const parseGithubUrl = (url: string) => {
if (!url) return null;
let urlObj = new URL(url);
let pathParts = urlObj.pathname.split('/');
+
return {
hostname: urlObj.hostname,
organization: pathParts[1],
repository: pathParts[2],
- branch: pathParts[3]
+ branch: pathParts[3],
+ remainingPath: pathParts.slice(4).join('/') + urlObj.search
};
};