Skip to content

Commit

Permalink
♻️ refactor: 重构为 iframe 模式
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Sep 3, 2023
1 parent e7cf27f commit 3060822
Show file tree
Hide file tree
Showing 18 changed files with 326 additions and 49 deletions.
19 changes: 0 additions & 19 deletions .fatherrc.ts

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ build

.vercel
.dumi
.next
5 changes: 5 additions & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
40 changes: 40 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
crossOrigin: 'anonymous',
transpilePackages: ['@lobehub/ui'],
async headers() {
return [
{
// matching all API routes
source: '/api/:path*',
headers: [
{ key: 'Access-Control-Allow-Credentials', value: 'true' },
{ key: 'Access-Control-Allow-Origin', value: '*' },
{ key: 'Access-Control-Allow-Methods', value: 'GET,OPTIONS,PATCH,DELETE,POST,PUT' },
{
key: 'Access-Control-Allow-Headers',
value:
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version',
},
],
},
{
// matching all API routes
source: '/:path*',
headers: [
{ key: 'Access-Control-Allow-Credentials', value: 'true' },
{ key: 'Access-Control-Allow-Origin', value: '*' },
{ key: 'Access-Control-Allow-Methods', value: 'GET,OPTIONS,PATCH,DELETE,POST,PUT' },
{
key: 'Access-Control-Allow-Headers',
value:
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version',
},
],
},
];
},
};

export default nextConfig;
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@lobehub/chat-plugin-realtime-weather",
"version": "1.4.2",
"private": true,
"description": "Lobe Chat RealTime Weather Plugin",
"homepage": "https://github.com/lobehub/chat-plugin-realtime-weather",
"repository": "https://github.com/lobehub/chat-plugin-realtime-weather.git",
Expand All @@ -9,22 +10,22 @@
"dist"
],
"scripts": {
"build": "father build",
"build": "next build",
"ci": "npm run lint && npm run type-check",
"dev": "father dev",
"docs:build": "dumi build",
"dev": "next dev -p 3410",
"docs:build": "npm run build && dumi build",
"docs:dev": "PORT=8110 dumi dev",
"doctor": "father doctor",
"lint": "npm run lint:js && npm run lint:prettier",
"lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx ",
"lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx ./api",
"lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx ./api",
"lint:prettier": "prettier --check \"api/**/*\" --end-of-line auto",
"lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx src/pages/api",
"lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx src/pages/api",
"lint:prettier": "prettier --check \\\"src/pages/api/**/*\\\" --end-of-line auto",
"prepare": "husky install",
"prepublishOnly": "npm run doctor && npm run build",
"prettier": "prettier -c --write \"api/**/*\"",
"prettier": "prettier -c --write \\\"src/pages/api/**/*\\\"",
"release": "semantic-release",
"start": "vercel dev --listen 3400",
"start": "next start",
"test": "vitest --passWithNoTests",
"test:coverage": "vitest --coverage --passWithNoTests",
"type-check": "tsc --noEmit"
Expand All @@ -41,12 +42,21 @@
"not ie <= 10"
],
"dependencies": {
"@lobehub/chat-plugin-sdk": "^1",
"@lobehub/chat-plugin-sdk": "^1.15.0",
"@lobehub/chat-plugins-gateway": "^1",
"@lobehub/ui": "latest",
"antd": "^5.8.6",
"antd-style": "^3",
"i18next": "^23",
"i18next-browser-languagedetector": "^7",
"next": "13.4.7",
"polished": "^4.2.2",
"query-string": "^8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^13",
"react-layout-kit": "^1"
"react-layout-kit": "^1",
"swr": "^2.2.2"
},
"devDependencies": {
"@lobehub/lint": "latest",
Expand All @@ -61,22 +71,12 @@
"eslint": "^8",
"father": "^4.3.1",
"husky": "^8",
"i18next": "^23",
"i18next-browser-languagedetector": "^7",
"lint-staged": "^13",
"lucide-react": "latest",
"prettier": "^3",
"semantic-release": "^21",
"typescript": "^5",
"vercel": "^28",
"vitest": "latest"
},
"peerDependencies": {
"antd": "^5",
"react": "^18"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
}
}
29 changes: 29 additions & 0 deletions public/manifest-dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"api": [
{
"url": "http://localhost:3410/api/v1",
"name": "fetchCurrentWeather",
"description": "获取当前天气情况",
"parameters": {
"properties": {
"city": {
"description": "城市名称",
"type": "string"
}
},
"required": [
"city"
],
"type": "object"
}
}
],
"gateway": "http://localhost:3410/api/gateway",
"identifier": "realtime-weather-dev",
"ui": {
"mode": "iframe",
"url": "http://localhost:3410",
"height": 310
},
"version": "1"
}
151 changes: 151 additions & 0 deletions public/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"openapi": "3.0.1",
"info": {
"title": "LobeChat Plugins",
"description": "",
"version": "1.0.0"
},
"tags": [
{
"name": "官方插件"
},
{
"name": "官方插件/天气插件(RealTime Weather)"
}
],
"paths": {
"/api/v1": {
"post": {
"summary": "查询天气",
"x-apifox-folder": "官方插件/天气插件(RealTime Weather)",
"x-apifox-status": "released",
"deprecated": false,
"description": "",
"tags": [
"官方插件/天气插件(RealTime Weather)"
],
"parameters": [],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"city": {
"type": "string",
"title": "城市"
}
},
"required": [
"city"
],
"x-apifox-orders": [
"city"
],
"x-apifox-ignore-properties": []
},
"example": {
"city": "杭州"
}
}
}
},
"responses": {
"200": {
"description": "成功",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {},
"x-apifox-orders": [],
"x-apifox-ignore-properties": []
},
"title": "天气"
},
"examples": {
"1": {
"summary": "成功示例",
"value": [
{
"city": "杭州市",
"adcode": "330100",
"province": "浙江",
"reporttime": "2023-08-17 23:01:56",
"casts": [
{
"date": "2023-08-17",
"week": "4",
"dayweather": "小雨",
"nightweather": "小雨",
"daytemp": "33",
"nighttemp": "24",
"daywind": "",
"nightwind": "",
"daypower": "≤3",
"nightpower": "≤3",
"daytemp_float": "33.0",
"nighttemp_float": "24.0"
},
{
"date": "2023-08-18",
"week": "5",
"dayweather": "小雨",
"nightweather": "小雨",
"daytemp": "32",
"nighttemp": "23",
"daywind": "东北",
"nightwind": "东北",
"daypower": "4",
"nightpower": "4",
"daytemp_float": "32.0",
"nighttemp_float": "23.0"
},
{
"date": "2023-08-19",
"week": "6",
"dayweather": "小雨",
"nightweather": "雷阵雨",
"daytemp": "32",
"nighttemp": "24",
"daywind": "",
"nightwind": "",
"daypower": "4",
"nightpower": "4",
"daytemp_float": "32.0",
"nighttemp_float": "24.0"
},
{
"date": "2023-08-20",
"week": "7",
"dayweather": "雷阵雨",
"nightweather": "多云",
"daytemp": "33",
"nighttemp": "25",
"daywind": "",
"nightwind": "",
"daypower": "≤3",
"nightpower": "≤3",
"daytemp_float": "33.0",
"nighttemp_float": "25.0"
}
]
}
]
}
}
}
}
}
},
"x-run-in-apifox": "https://apifox.com/web/project/3171264/apis/api-103858950-run"
}
}
},
"components": {
"schemas": {}
},
"servers": []
}
2 changes: 1 addition & 1 deletion src/Render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const useStyles = createStyles(({ css, token }) => ({
}));

const i18n = createI18nNext();
const Render = memo<PluginRenderProps<WeatherResult>>(({ content }) => {
const Render = memo<{ content: WeatherResult }>(({ content }) => {
const { t } = useTranslation('common');

const { styles } = useStyles();
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts

This file was deleted.

9 changes: 9 additions & 0 deletions src/layout/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ThemeProvider } from '@lobehub/ui';
import 'antd/dist/reset.css';
import { PropsWithChildren, memo } from 'react';

const Layout = memo<PropsWithChildren>(({ children }) => {
return <ThemeProvider themeMode={'auto'}>{children}</ThemeProvider>;
});

export default Layout;
13 changes: 13 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { AppProps } from 'next/app';

import Layout from '@/layout';

import './global.css';

export default function App({ Component, pageProps }: AppProps) {
return (
<Layout>
<Component {...pageProps} />
</Layout>
);
}
13 changes: 13 additions & 0 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Head, Html, Main, NextScript } from 'next/document';

export default function Document() {
return (
<Html lang="en">
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
Loading

0 comments on commit 3060822

Please sign in to comment.