generated from lobehub/chat-plugin-realtime-weather
-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 92ef0d6
Showing
24 changed files
with
402 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@lobehub/lint').changelog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@lobehub/lint').commitlint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[Makefile] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/lambda/ | ||
/scripts | ||
/config | ||
.history | ||
public | ||
dist | ||
.umi | ||
mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const config = require('@lobehub/lint').eslint; | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Release CI | ||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8 | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20' | ||
|
||
- name: Install deps | ||
run: pnpm install | ||
|
||
- name: Test | ||
run: pnpm run test | ||
|
||
- name: release | ||
run: pnpm run release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Test | ||
on: [push] | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8 | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20' | ||
|
||
- name: Install deps | ||
run: pnpm install | ||
|
||
- name: Test and coverage | ||
run: pnpm run test:coverage | ||
|
||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
**/node_modules | ||
# roadhog-api-doc ignore | ||
/src/utils/request-temp.js | ||
_roadhog-api-doc | ||
|
||
# production | ||
/dist | ||
/.vscode | ||
|
||
# misc | ||
.DS_Store | ||
npm-debug.log* | ||
yarn-error.log | ||
|
||
/coverage | ||
.idea | ||
package-lock.json | ||
*bak | ||
.vscode | ||
|
||
# visual studio code | ||
.history | ||
*.log | ||
functions/* | ||
.temp/** | ||
|
||
# umi | ||
.umi | ||
.umi-production | ||
|
||
# screenshot | ||
screenshot | ||
.firebase | ||
.eslintcache | ||
|
||
build | ||
|
||
.env | ||
|
||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx --no -- commitlint --edit ${1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx --no-install lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
lockfile=false | ||
resolution-mode=highest | ||
public-hoist-pattern[]=*@umijs/lint* | ||
public-hoist-pattern[]=*changelog* | ||
public-hoist-pattern[]=*commitlint* | ||
public-hoist-pattern[]=*eslint* | ||
public-hoist-pattern[]=*postcss* | ||
public-hoist-pattern[]=*prettier* | ||
public-hoist-pattern[]=*remark* | ||
public-hoist-pattern[]=*semantic-release* | ||
public-hoist-pattern[]=*stylelint* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
**/*.svg | ||
**/*.ejs | ||
.umi | ||
.umi-production | ||
/dist | ||
.dockerignore | ||
.DS_Store | ||
.eslintignore | ||
*.png | ||
*.toml | ||
docker | ||
.editorconfig | ||
Dockerfile* | ||
.gitignore | ||
.prettierignore | ||
LICENSE | ||
.eslintcache | ||
*.lock | ||
yarn-error.log | ||
.history | ||
CNAME | ||
/build | ||
/public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@lobehub/lint').prettier; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@lobehub/lint').semanticRelease; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<a name="readme-top"></a> | ||
|
||
# Changelog | ||
|
||
## Version 1.0.0 | ||
|
||
<sup>Released on **2023-08-17**</sup> | ||
|
||
#### ♻ Code Refactoring | ||
|
||
- **misc**: 按照接口模式重构. | ||
|
||
<br/> | ||
|
||
<details> | ||
<summary><kbd>Improvements and Fixes</kbd></summary> | ||
|
||
#### Code refactoring | ||
|
||
- **misc**: 按照接口模式重构 ([0e66e76](https://github.com/lobehub/chat-plugin-real-time-weather/commit/0e66e76)) | ||
|
||
</details> | ||
|
||
<div align="right"> | ||
|
||
[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 LobeHub | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# LobeChat Plugin RealTime Weather | ||
|
||
[![Coverage][coverage]][codecov-url] ![Test CI status][test-ci] | ||
|
||
[test-ci]: https://github.com/lobehub/chat-plugin-market/workflows/Test/badge.svg | ||
[coverage]: https://codecov.io/gh/arvinxx/vercel-serverless-api-template/branch/master/graph/badge.svg | ||
[codecov-url]: https://codecov.io/gh/arvinxx/vercel-serverless-api-template/branch/master | ||
|
||
LobeChat Plugin RealTime Weather |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Response, WeatherParams, WeatherResult } from '../../type'; | ||
|
||
const weatherBaseURL = 'https://restapi.amap.com/v3/weather/weatherInfo'; | ||
|
||
const citySearchURL = 'https://restapi.amap.com/v3/config/district'; | ||
|
||
const KEY = process.env.GAODE_WEATHER_KEY; | ||
|
||
const fetchCityCode = async (keywords: string): Promise<string> => { | ||
const URL = `${citySearchURL}?keywords=${keywords}&subdistrict=0&extensions=base&key=${KEY}`; | ||
const res = await fetch(URL); | ||
|
||
const data = await res.json(); | ||
console.log(data); | ||
|
||
return data.districts[0].adcode; | ||
}; | ||
|
||
const fetchWeather = async ({ | ||
city, | ||
extensions = 'all', | ||
}: WeatherParams): Promise<WeatherResult> => { | ||
const cityCode = await fetchCityCode(city); | ||
|
||
const URL = `${weatherBaseURL}?city=${cityCode}&extensions=${extensions}&key=${KEY}`; | ||
const res = await fetch(URL); | ||
|
||
const data: Response = await res.json(); | ||
|
||
return data.forecasts; | ||
}; | ||
|
||
export default fetchWeather; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { WeatherParams } from '../../type'; | ||
import fetchWeather from './_utils'; | ||
|
||
export const config = { | ||
runtime: 'edge', | ||
}; | ||
|
||
export default async (req: Request) => { | ||
if (req.method !== 'POST') return new Response('Method Not Allowed', { status: 405 }); | ||
|
||
const args = (await req.json()) as WeatherParams; | ||
|
||
const result = await fetchWeather(args); | ||
|
||
return new Response(JSON.stringify(result)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"name": "chat-plugin-real-time-weather", | ||
"version": "1.0.0", | ||
"private": true, | ||
"description": "Lobe Chat Plugin Market", | ||
"repository": "https://github.com/lobehub/chat-plugin-real-time-weather.git", | ||
"scripts": { | ||
"ci": "npm run lint && npm run type-check", | ||
"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", | ||
"prepare": "husky install", | ||
"prettier": "prettier -c --write \"api/**/*\"", | ||
"release": "semantic-release", | ||
"start": "vercel dev", | ||
"test": "vitest --passWithNoTests", | ||
"test:coverage": "vitest --coverage --passWithNoTests", | ||
"type-check": "tsc --noEmit" | ||
}, | ||
"lint-staged": { | ||
"**/*.{js,jsx,ts,tsx}": "npm run lint-staged:js", | ||
"**/*.{js,jsx,tsx,ts,less,md,json}": [ | ||
"prettier --write" | ||
] | ||
}, | ||
"browserslist": [ | ||
"> 1%", | ||
"last 2 versions", | ||
"not ie <= 10" | ||
], | ||
"devDependencies": { | ||
"@lobehub/lint": "latest", | ||
"@vercel/node": "^2", | ||
"@vitest/coverage-v8": "latest", | ||
"commitlint": "^17", | ||
"cross-env": "^7", | ||
"eslint": "^8", | ||
"husky": "^8", | ||
"lint-staged": "^13", | ||
"prettier": "^2", | ||
"semantic-release": "^21", | ||
"typescript": "^5", | ||
"vercel": "^31.2.3", | ||
"vitest": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang='en'> | ||
<head> | ||
<meta charset='UTF-8'> | ||
<title>Lobe Chat Realtime Weather</title> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "CommonJS", | ||
"target": "ES5", | ||
"lib": ["esnext", "DOM"], | ||
"sourceMap": true, | ||
"baseUrl": ".", | ||
"allowSyntheticDefaultImports": true, | ||
"moduleResolution": "node", | ||
"forceConsistentCasingInFileNames": true, | ||
"noImplicitReturns": true, | ||
"noUnusedLocals": true, | ||
"skipLibCheck": true, | ||
"strict": true | ||
}, | ||
"include": ["types", "api"] | ||
} |
Oops, something went wrong.