App template market (#2337)

* feat: add app template market (#2012)

* feat: add app template market

* fix

* fix

* i18n

* fix

* perf: template market ux

* perf: simple mode app ui

* perf: tempalte modal ui

* perf: tempalte market ui

* perf: template position

* feat: create app modal

* regiter default app

* perf: icon

* change templates position (#2331)

* change templates position

* fix

* perf: template market ux

---------

Co-authored-by: heheer <heheer@sealos.io>
This commit is contained in:
Archer
2024-08-12 16:21:21 +08:00
committed by GitHub
parent 231afc4ac5
commit 2196930005
58 changed files with 5934 additions and 3165 deletions

View File

@@ -62,6 +62,8 @@ const defaultFeConfigs: FastGPTFeConfigsType = {
docUrl: 'https://doc.fastgpt.in',
openAPIDocUrl: 'https://doc.fastgpt.in/docs/development/openapi',
systemPluginCourseUrl: 'https://fael3z0zfze.feishu.cn/wiki/ERZnw9R26iRRG0kXZRec6WL9nwh',
appTemplateCourse:
'https://fael3z0zfze.feishu.cn/wiki/CX9wwMGyEi5TL6koiLYcg7U0nWb?fromScene=spaceOverview',
systemTitle: 'FastGPT',
concatMd:
'项目开源地址: [FastGPT GitHub](https://github.com/labring/FastGPT)\n交流群: ![](https://oss.laf.run/htr4n1-images/fastgpt-qr-code.jpg)',

View File

@@ -0,0 +1,48 @@
import { isProduction } from '@fastgpt/service/common/system/constants';
import { readdirSync, readFileSync } from 'fs';
import path from 'path';
// Get template from memory or file system
const loadTemplateMarketItems = async () => {
if (isProduction && global.appMarketTemplates) return global.appMarketTemplates;
const templatesDir = path.join(process.cwd(), 'public', 'appMarketTemplates');
const templateNames = readdirSync(templatesDir);
global.appMarketTemplates = templateNames.map((name) => {
try {
const filePath = path.join(templatesDir, name, 'template.json');
const fileContent = readFileSync(filePath, 'utf-8');
const data = JSON.parse(fileContent);
return {
id: name,
...data
};
} catch (error) {
console.error(`Error fetching template ${name}:`, error);
return null;
}
});
global.appMarketTemplates.sort((a, b) => (b.weight ?? 0) - (a.weight ?? 0));
return global.appMarketTemplates;
};
export const getTemplateMarketItemDetail = async (id: string) => {
const templateMarketItems = await loadTemplateMarketItems();
return templateMarketItems.find((item) => item.id === id);
};
export const getTemplateMarketItemList = async () => {
const templateMarketItems = await loadTemplateMarketItems();
return templateMarketItems.map((item) => ({
id: item.id,
name: item.name,
avatar: item.avatar,
intro: item.intro,
author: item.author,
tags: item.tags,
type: item.type
}));
};