feat(fim): add avatar storage and enable fim

pull/100/head
moonrailgun 2 years ago
parent f6ef59e37d
commit a8bb744bfd

@ -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",

@ -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<string, any>) {
return {
__raw: true,
html: `<script>window.postMessage(${JSON.stringify(obj)})</script>`,
html: `<script>window.opener.postMessage(${JSON.stringify({
source: 'plugin:com.msgbyte.fim',
...obj,
})}, "*");</script><div>Waiting for close</div>`,
};
}

@ -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);

Loading…
Cancel
Save