parent
c2999ea5e7
commit
e381eb9598
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "hooks-react-starter",
|
"name": "paul-api-next",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
@ -14,12 +14,14 @@
|
||||||
"@midwayjs/rpc": "^3.0.0",
|
"@midwayjs/rpc": "^3.0.0",
|
||||||
"ahooks": "^3.3.0",
|
"ahooks": "^3.3.0",
|
||||||
"isomorphic-unfetch": "^3.1.0",
|
"isomorphic-unfetch": "^3.1.0",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
"redis": "^4.0.6"
|
"redis": "^4.0.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@midwayjs/mock": "^3.3.0",
|
"@midwayjs/mock": "^3.3.0",
|
||||||
|
"@types/lodash": "^4.14.181",
|
||||||
"@types/react": "^17.0.44",
|
"@types/react": "^17.0.44",
|
||||||
"@types/react-dom": "^17.0.15",
|
"@types/react-dom": "^17.0.15",
|
||||||
"@vitejs/plugin-react": "^1.3.0",
|
"@vitejs/plugin-react": "^1.3.0",
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import { Api, Get, Query, useContext } from '@midwayjs/hooks';
|
import { Api, Get, Query, useContext } from "@midwayjs/hooks";
|
||||||
import fetch from 'isomorphic-unfetch';
|
import fetch from "isomorphic-unfetch";
|
||||||
|
|
||||||
import { client } from '../utils/redis';
|
import { client } from "../utils/redis";
|
||||||
|
|
||||||
export default Api(
|
export default Api(
|
||||||
Get(),
|
Get(),
|
||||||
Query<{ info: undefined }>(),
|
Query<{ info?: string }>(),
|
||||||
async (ddd) => {
|
async () => {
|
||||||
const ctx = useContext();
|
const ctx = useContext();
|
||||||
|
|
||||||
// 增加使用数量
|
// 增加使用数量
|
||||||
|
|
@ -51,11 +51,12 @@ export default Api(
|
||||||
// 没有 info,跳转图片地址
|
// 没有 info,跳转图片地址
|
||||||
if (!("info" in ctx.query)) {
|
if (!("info" in ctx.query)) {
|
||||||
ctx.status = 302;
|
ctx.status = 302;
|
||||||
ctx.set('location', image.url);
|
ctx.set("location", image.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code: 1,
|
code: 1,
|
||||||
|
msg: "Success",
|
||||||
data: image,
|
data: image,
|
||||||
cached: cache.length ? true : false
|
cached: cache.length ? true : false
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,22 @@ import { Api, Get } from '@midwayjs/hooks';
|
||||||
|
|
||||||
import { client } from '../utils/redis';
|
import { client } from '../utils/redis';
|
||||||
|
|
||||||
export default Api(Get(), async (repo: string) => {
|
export default Api(
|
||||||
const neteaseStat = await client.get("api-next:stat:netease");
|
Get(),
|
||||||
const bingStat = await client.get("api-next:stat:bing");
|
async () => {
|
||||||
|
const neteaseStat = await client.get("api-next:stat:netease");
|
||||||
|
const bingStat = await client.get("api-next:stat:bing");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code: 1,
|
code: 1,
|
||||||
data: {
|
data: {
|
||||||
wallpaper: -1,
|
wallpaper: -1,
|
||||||
netease: Number(neteaseStat),
|
netease: Number(neteaseStat),
|
||||||
music: -1,
|
music: -1,
|
||||||
avatar: -1,
|
avatar: -1,
|
||||||
bili: -1,
|
bili: -1,
|
||||||
bing: Number(bingStat),
|
bing: Number(bingStat),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
import { Api, Get, Query, useContext } from "@midwayjs/hooks";
|
||||||
|
|
||||||
|
import { source } from "../data/wallpaper";
|
||||||
|
import { random } from "lodash";
|
||||||
|
import { client } from "../utils/redis";
|
||||||
|
|
||||||
|
export default Api(
|
||||||
|
Get(),
|
||||||
|
Query<{ source: string }>(),
|
||||||
|
async () => {
|
||||||
|
const ctx = useContext();
|
||||||
|
const sourceResult = source[ctx.query.source || "jsd"];
|
||||||
|
|
||||||
|
// 增加使用数量
|
||||||
|
await client.incr("api-next:stat:wallpaper");
|
||||||
|
|
||||||
|
const number = random(sourceResult.start, sourceResult.end);
|
||||||
|
|
||||||
|
ctx.status = 302;
|
||||||
|
ctx.set("location", `${sourceResult.url}${number}.jpg`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
code: 1,
|
||||||
|
msg: "Success"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { IWallpaperSource } from "../types/wallpaper";
|
||||||
|
|
||||||
|
// 随机动漫壁纸静态源
|
||||||
|
export const source: Record<string, IWallpaperSource> = {
|
||||||
|
gt: {
|
||||||
|
name: "Gitee",
|
||||||
|
url: "https://dreamer-paul.gitee.io/anime-wallpaper/",
|
||||||
|
start: 1,
|
||||||
|
end: 104
|
||||||
|
},
|
||||||
|
gh: {
|
||||||
|
name: "GitHub",
|
||||||
|
url: "https://dreamer-paul.github.io/Anime-Wallpaper/",
|
||||||
|
start: 1,
|
||||||
|
end: 104
|
||||||
|
},
|
||||||
|
jsd: {
|
||||||
|
name: "JSDelivr",
|
||||||
|
url: "https://fastly.jsdelivr.net/gh/Dreamer-Paul/Anime-Wallpaper/",
|
||||||
|
start: 1,
|
||||||
|
end: 104
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
export interface IWallpaperSource {
|
||||||
|
name: string
|
||||||
|
url: string
|
||||||
|
start: number
|
||||||
|
end: number
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
"allowJs": false,
|
"allowJs": false,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"strict": false,
|
"strict": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
|
|
|
||||||
17
yarn.lock
17
yarn.lock
|
|
@ -202,6 +202,13 @@
|
||||||
"@babel/plugin-syntax-jsx" "^7.16.7"
|
"@babel/plugin-syntax-jsx" "^7.16.7"
|
||||||
"@babel/types" "^7.17.0"
|
"@babel/types" "^7.17.0"
|
||||||
|
|
||||||
|
"@babel/runtime@^7.7.6":
|
||||||
|
version "7.17.9"
|
||||||
|
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.17.9.tgz#d19fbf802d01a8cb6cf053a64e472d42c434ba72"
|
||||||
|
integrity sha512-lSiBBvodq29uShpWGNbgFdKYNiFDo5/HIYsaCEY9ff4sb10x9jizo2+pRrSyF4jKZCXqgzuqBOQKbUm90gQwJg==
|
||||||
|
dependencies:
|
||||||
|
regenerator-runtime "^0.13.4"
|
||||||
|
|
||||||
"@babel/template@^7.16.7":
|
"@babel/template@^7.16.7":
|
||||||
version "7.16.7"
|
version "7.16.7"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.16.7.tgz#8d126c8701fde4d66b264b3eba3d96f07666d155"
|
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.16.7.tgz#8d126c8701fde4d66b264b3eba3d96f07666d155"
|
||||||
|
|
@ -868,6 +875,11 @@
|
||||||
"@types/koa-compose" "*"
|
"@types/koa-compose" "*"
|
||||||
"@types/node" "*"
|
"@types/node" "*"
|
||||||
|
|
||||||
|
"@types/lodash@^4.14.181":
|
||||||
|
version "4.14.181"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.181.tgz#d1d3740c379fda17ab175165ba04e2d03389385d"
|
||||||
|
integrity sha512-n3tyKthHJbkiWhDZs3DkhkCzt2MexYHXlX0td5iMplyfwketaOeKboEVBqzceH7juqvEg3q5oUoBFxSLu7zFag==
|
||||||
|
|
||||||
"@types/mime@^1":
|
"@types/mime@^1":
|
||||||
version "1.3.2"
|
version "1.3.2"
|
||||||
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a"
|
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a"
|
||||||
|
|
@ -2487,6 +2499,11 @@ reflect-metadata@^0.1.13:
|
||||||
resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.13.tgz#67ae3ca57c972a2aa1642b10fe363fe32d49dc08"
|
resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.13.tgz#67ae3ca57c972a2aa1642b10fe363fe32d49dc08"
|
||||||
integrity sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==
|
integrity sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==
|
||||||
|
|
||||||
|
regenerator-runtime@^0.13.4:
|
||||||
|
version "0.13.9"
|
||||||
|
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52"
|
||||||
|
integrity sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==
|
||||||
|
|
||||||
resize-observer-polyfill@^1.5.1:
|
resize-observer-polyfill@^1.5.1:
|
||||||
version "1.5.1"
|
version "1.5.1"
|
||||||
resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464"
|
resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue