mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-31 03:22:18 +00:00
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:
@@ -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交流群: ',
|
||||
|
48
projects/app/src/service/core/app/template.ts
Normal file
48
projects/app/src/service/core/app/template.ts
Normal 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
|
||||
}));
|
||||
};
|
Reference in New Issue
Block a user