diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 851d10d9..52e0d022 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -6,8 +6,8 @@ name: Docker Build, Push and Publish # events but only for the master branch on: push: - branches: - - main + tags: + - v* # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dd3f3728..710456f5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,35 +11,11 @@ jobs: VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - - uses: pnpm/action-setup@v2 - with: - version: 8 - - - uses: actions/setup-node@v3 - if: ${{ !env.VERCEL_TOKEN || !env.VERCEL_ORG_ID || !env.VERCEL_PROJECT_ID }} - with: - node-version: 18 - cache: pnpm - - - name: Install Dependencies - if: ${{ !env.VERCEL_TOKEN || !env.VERCEL_ORG_ID || !env.VERCEL_PROJECT_ID }} - run: pnpm i --frozen-lockfile - - - name: Export Static pages - if: ${{ !env.VERCEL_TOKEN || !env.VERCEL_ORG_ID || !env.VERCEL_PROJECT_ID }} - run: pnpm export - - - name: Deploy to GitHub pages - uses: peaceiris/actions-gh-pages@v3 - if: ${{ !env.VERCEL_TOKEN || !env.VERCEL_ORG_ID || !env.VERCEL_PROJECT_ID }} - with: - publish_dir: ./out - personal_token: ${{ secrets.GITHUB_TOKEN }} - force_orphan: true + - uses: actions/checkout@v4 + if: ${{ env.VERCEL_TOKEN && env.VERCEL_ORG_ID && env.VERCEL_PROJECT_ID }} - name: Deploy to Vercel + id: vercel-deployment uses: amondnet/vercel-action@v25 if: ${{ env.VERCEL_TOKEN && env.VERCEL_ORG_ID && env.VERCEL_PROJECT_ID }} with: @@ -49,3 +25,29 @@ jobs: vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} working-directory: ./ vercel-args: --prod + + - name: Lark notification + uses: foxundermoon/feishu-action@v2 + with: + url: ${{ secrets.LARK_CHATBOT_HOOK_URL }} + msg_type: post + content: | + post: + zh_cn: + title: Vercel 预览环境 + content: + - - tag: text + text: Git 仓库: + - tag: a + text: ${{ github.server_url }}/${{ github.repository }} + href: ${{ github.server_url }}/${{ github.repository }} + - - tag: text + text: 代码分支: + - tag: a + text: ${{ github.ref }} + href: ${{ github.server_url }}/${{ github.repository }}/tree/${{ github.ref_name }} + - - tag: text + text: 预览链接: + - tag: a + text: ${{ steps.vercel-deployment.outputs.preview-url }} + href: ${{ steps.vercel-deployment.outputs.preview-url }} diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 84944c1a..ede12ff2 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -15,6 +15,7 @@ jobs: if: ${{ env.VERCEL_TOKEN && env.VERCEL_ORG_ID && env.VERCEL_PROJECT_ID }} - name: Deploy to Vercel + id: vercel-deployment uses: amondnet/vercel-action@v25 if: ${{ env.VERCEL_TOKEN && env.VERCEL_ORG_ID && env.VERCEL_PROJECT_ID }} with: @@ -23,3 +24,29 @@ jobs: vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} working-directory: ./ + + - name: Lark notification + uses: foxundermoon/feishu-action@v2 + with: + url: ${{ secrets.LARK_CHATBOT_HOOK_URL }} + msg_type: post + content: | + post: + zh_cn: + title: Vercel 预览环境 + content: + - - tag: text + text: Git 仓库: + - tag: a + text: ${{ github.server_url }}/${{ github.repository }} + href: ${{ github.server_url }}/${{ github.repository }} + - - tag: text + text: 代码分支: + - tag: a + text: ${{ github.ref }} + href: ${{ github.server_url }}/${{ github.repository }}/tree/${{ github.ref_name }} + - - tag: text + text: 预览链接: + - tag: a + text: ${{ steps.vercel-deployment.outputs.preview-url }} + href: ${{ steps.vercel-deployment.outputs.preview-url }} diff --git a/components/Team/TeamWorkList.tsx b/components/Team/TeamWorkList.tsx index e4e7d0ee..c7d4a05f 100644 --- a/components/Team/TeamWorkList.tsx +++ b/components/Team/TeamWorkList.tsx @@ -1,9 +1,9 @@ import { faCalendarDay } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { ScrollList } from 'mobx-restful-table'; -import { FilePreview } from 'mobx-restful-table'; +import { observer } from 'mobx-react'; +import { FilePreview, ScrollList } from 'mobx-restful-table'; import { FC, PureComponent } from 'react'; -import { Button, Card, Col, Container, Row } from 'react-bootstrap'; +import { Button, Card, CardProps, Col, Container, Row } from 'react-bootstrap'; import activityStore from '../../models/Activity'; import { TeamWork } from '../../models/Activity/Team'; @@ -12,93 +12,117 @@ import { XScrollListProps } from '../layout/ScrollList'; const { t } = i18n; -export interface TeamWorkListLayoutProps extends XScrollListProps { - activity: string; - team: string; - size?: 'sm' | 'lg'; +export interface TeamWorkCardProps extends TeamWork, Omit { controls?: boolean; onDelete?: (id: TeamWork['id']) => any; } -export const TeamWorkListLayout: FC = ({ - defaultData = [], - size, - controls, - onDelete, - activity, - team, -}) => ( - - {controls && ( -
- -
- )} - - {defaultData.map(({ id, updatedAt, type, url, title, description }) => ( - - - - - {title || url} - -

- {description} -

-
- -
- -
- {controls && ( - - - - - )} -
- - ))} -
-
+ {title || url} + +

+ {description} +

+
+ +
+ + + {controls && ( + + + + + )} + + ), +); + +export interface TeamWorkListLayoutProps + extends XScrollListProps, + Pick { + activity: string; + team: string; + size?: 'sm' | 'lg'; +} + +export const TeamWorkListLayout: FC = observer( + ({ defaultData = [], size, controls, onDelete, activity, team }) => ( + + {controls && ( +
+ +
+ )} + + {defaultData.map(work => ( + + + + ))} + +
+ ), ); export class TeamWorkList extends PureComponent { diff --git a/components/User/ServerSessionBox.tsx b/components/User/ServerSessionBox.tsx index 6813c3d0..6173d5dc 100644 --- a/components/User/ServerSessionBox.tsx +++ b/components/User/ServerSessionBox.tsx @@ -1,13 +1,28 @@ -import dynamic from 'next/dynamic'; +import { Icon } from 'idea-react'; +import { observer } from 'mobx-react'; import { JWTProps } from 'next-ssr-middleware'; import { FC, HTMLAttributes } from 'react'; +import { Button } from 'react-bootstrap'; -const AuthingGuard = dynamic(() => import('./AuthingGuard'), { ssr: false }); +import { i18n } from '../../models/Base/Translation'; +import { strapiClient } from '../../models/User/Session'; export type ServerSessionBoxProps = HTMLAttributes & JWTProps; -export const ServerSessionBox: FC = ({ - jwtPayload, - children, - ...props -}) =>
{jwtPayload ? children : }
; +export const ServerSessionBox: FC = observer( + ({ jwtPayload, children, ...props }) => ( +
+ {jwtPayload ? ( + children + ) : ( + + )} +
+ ), +); diff --git a/models/User/Session.ts b/models/User/Session.ts index 38c0ed5e..ad6483ea 100644 --- a/models/User/Session.ts +++ b/models/User/Session.ts @@ -1,12 +1,40 @@ import { HTTPClient } from 'koajax'; import { computed, makeObservable, observable } from 'mobx'; -import { setCookie } from 'mobx-i18n'; +import { parseCookie, setCookie } from 'mobx-i18n'; import { BaseModel, toggle } from 'mobx-restful'; import { buildURLData, sleep } from 'web-utility'; import { AuthingIdentity, AuthingUserBase, User } from '.'; -const { localStorage } = globalThis; +const { localStorage, document } = globalThis; + +const { token } = (document ? parseCookie() : {}) as { token: string }; + +export const strapiClient = new HTTPClient({ + baseURI: `${ + process.env.NODE_ENV === 'development' + ? 'http://127.0.0.1:1337' + : 'https://hackathon-server.kaiyuanshe.cn' + }/api/`, + responseType: 'json', +}).use(({ request }, next) => { + if (token) + request.headers = { ...request.headers, Authorization: `Bearer ${token}` }; + + return next(); +}); + +export interface Base extends Record<'createdAt' | 'updatedAt', string> { + id: number; +} + +export interface SessionUser + extends Base, + Record<'username' | 'email', string>, + Record<'confirmed' | 'blocked', boolean> { + provider: 'local' | 'github'; + gender?: 'Female' | 'Male' | 'Other'; +} export class SessionModel extends BaseModel { constructor() { diff --git a/pages/_document.tsx b/pages/_document.tsx index 59399456..1bbc284f 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -17,7 +17,7 @@ export default function Document() { /> { + const { body } = await strapiClient.get<{ jwt: string; user: SessionUser }>( + `auth/github/callback?${buildURLData(query)}`, + ); + res.setHeader('Set-Cookie', `token=${body!.jwt}; Path=/`); + + return { props: {}, redirect: { statusCode: 302, destination: '/' } }; + }, +); + +const GitHubRedirection: FC = () => <>; + +export default GitHubRedirection; diff --git a/pages/user/[id].tsx b/pages/user/[id].tsx index bdfdec2c..94734c1a 100644 --- a/pages/user/[id].tsx +++ b/pages/user/[id].tsx @@ -37,80 +37,66 @@ const UserDetailPage = ({ registerSource, }: InferGetServerSidePropsType) => (
- - + - - - - - - {nickname} - - + + + + {nickname} + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + +
+ + + + + + + + + + + +
);