diff --git a/package.json b/package.json index 614f9c97..f4c27915 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "start:admin-old": "cd server/admin-old && pnpm start", "build": "concurrently npm:build:web npm:build:server npm:build:admin npm:build:admin-old && cp -r client/web/dist/* server/dist/public", "build:web": "cd client/web && pnpm build", - "build:server": "cd server && pnpm build && echo \"Install server side plugin:\" && pnpm run plugin:install com.msgbyte.tasks com.msgbyte.linkmeta com.msgbyte.github com.msgbyte.simplenotify com.msgbyte.topic com.msgbyte.agora com.msgbyte.wxpusher com.msgbyte.welcome && mkdir -p ./dist/public && cp -r ./public/plugins ./dist/public && cp ./public/registry-be.json ./dist/public", + "build:server": "cd server && pnpm build && echo \"Install server side plugin:\" && pnpm run plugin:install com.msgbyte.tasks com.msgbyte.linkmeta com.msgbyte.github com.msgbyte.simplenotify com.msgbyte.topic com.msgbyte.agora com.msgbyte.wxpusher com.msgbyte.welcome com.msgbyte.fim && mkdir -p ./dist/public && cp -r ./public/plugins ./dist/public && cp ./public/registry-be.json ./dist/public", "build:admin": "cd server/admin && pnpm build", "build:admin-old": "cd server/admin-old && pnpm build", "check:type": "concurrently npm:check:type:client npm:check:type:server", diff --git a/server/plugins/com.msgbyte.fim/services/fim.service.dev.ts b/server/plugins/com.msgbyte.fim/services/fim.service.ts similarity index 77% rename from server/plugins/com.msgbyte.fim/services/fim.service.dev.ts rename to server/plugins/com.msgbyte.fim/services/fim.service.ts index 93daf9b4..2451523f 100644 --- a/server/plugins/com.msgbyte.fim/services/fim.service.dev.ts +++ b/server/plugins/com.msgbyte.fim/services/fim.service.ts @@ -1,5 +1,11 @@ -import { TcService, TcDbService, TcPureContext, db } from 'tailchat-server-sdk'; -import type { UserStructWithToken } from 'tailchat-server-sdk/src/structs/user'; +import { + TcService, + TcDbService, + TcPureContext, + db, + UserStructWithToken, +} from 'tailchat-server-sdk'; +import { isValidStaticAssetsUrl } from '../../../lib/utils'; import type { FimDocument, FimModel } from '../models/fim'; import { strategies } from '../strategies'; import type { StrategyType } from '../strategies/types'; @@ -87,12 +93,31 @@ class FimService extends TcService { return generatePostMessageHtml({ type: 'existed' }); } + let avatar = providerUserInfo.avatar; + if (avatar && isValidStaticAssetsUrl(avatar)) { + try { + const { url } = (await ctx.call( + 'file.saveFileWithUrl', + { + fileUrl: avatar, + }, + { + timeout: 3000, + } + )) as { url: string }; + avatar = url; + } catch (err) { + this.logger.error('Cannot storage avatar', avatar, err); + } + } + const newUserInfo: UserStructWithToken = await ctx.call( 'user.register', { email: providerUserInfo.email, nickname: providerUserInfo.nickname, - password: new db.Types.ObjectId(), // random password + password: String(new db.Types.ObjectId()), // random password + avatar, } ); @@ -115,7 +140,10 @@ class FimService extends TcService { function generatePostMessageHtml(obj: Record) { return { __raw: true, - html: ``, + html: `
Waiting for close
`, }; } diff --git a/server/services/core/user/user.service.ts b/server/services/core/user/user.service.ts index 4b1eeb4e..62be7bb8 100644 --- a/server/services/core/user/user.service.ts +++ b/server/services/core/user/user.service.ts @@ -89,6 +89,7 @@ class UserService extends TcService { nickname: { type: 'string', optional: true, max: 40 }, password: { type: 'string', max: 40 }, emailOTP: { type: 'string', optional: true }, + avatar: { type: 'string', optional: true }, }, }); this.registerAction('signUserToken', this.signUserToken, { @@ -413,6 +414,7 @@ class UserService extends TcService { nickname?: string; password: string; emailOTP?: string; + avatar?: string; }, any > @@ -457,7 +459,6 @@ class UserService extends TcService { nickname, discriminator, emailVerified, - avatar: null, createdAt: new Date(), }); const user = await this.transformDocuments(ctx, {}, doc);