MCPcopy
hub / github.com/labring/FastGPT / create

Function create

projects/app/src/pages/api/core/app/create.ts:189–281  ·  view source on GitHub ↗
(session: ClientSession)

Source from the content-addressed store, hash-verified

187 }
188
189 const create = async (session: ClientSession) => {
190 const resourceRefs = extractAppResourceRefsFromNodes(modules);
191 const _avatar = await (async () => {
192 if (!templateId || isPluginSystemTemplate(templateId)) return avatar;
193
194 const template = await MongoAppTemplate.findOne({ templateId }, 'avatar').lean();
195 if (!template?.avatar) return avatar;
196
197 const s3AvatarSource = getS3AvatarSource();
198 if (!isS3ObjectKey(template.avatar?.slice(s3AvatarSource.prefix.length), 'avatar')) {
199 return template.avatar;
200 }
201
202 return await copyAvatarImage({
203 teamId,
204 imageUrl: template.avatar,
205 temporary: true,
206 session
207 });
208 })();
209
210 const [app] = await MongoApp.create(
211 [
212 {
213 ...parseParentIdInMongo(parentId),
214 avatar: _avatar,
215 name,
216 intro,
217 teamId,
218 tmbId,
219 modules,
220 edges,
221 chatConfig,
222 type,
223 version: 'v2',
224 pluginData,
225 templateId,
226 ...(!AppFolderTypeList.includes(type!) && { resourceRefs })
227 }
228 ],
229 { session, ordered: true }
230 );
231
232 const appId = String(app._id);
233
234 if (!AppFolderTypeList.includes(type!)) {
235 await MongoAppVersion.create(
236 [
237 {
238 tmbId,
239 appId,
240 nodes: modules,
241 edges,
242 chatConfig,
243 versionName: name,
244 username,
245 avatar: userAvatar,
246 isPublish: true,

Callers 10

onCreateAppFunction · 0.70
searchTest.tsFile · 0.50
dataset.tsFile · 0.50
markdata.tsFile · 0.50
storeShareChat.tsFile · 0.50
useChatStore.tsFile · 0.50
useSystemStore.tsFile · 0.50
useUserStore.tsFile · 0.50

Calls 13

isPluginSystemTemplateFunction · 0.90
getS3AvatarSourceFunction · 0.90
isS3ObjectKeyFunction · 0.90
copyAvatarImageFunction · 0.90
parseParentIdInMongoFunction · 0.90
addAuditLogFunction · 0.90
getI18nAppTypeFunction · 0.90
refreshAvatarMethod · 0.80
createMethod · 0.65
sliceMethod · 0.45

Tested by

no test coverage detected