mirror of
				https://github.com/suyiiyii/nonebot-bison.git
				synced 2025-10-26 08:24:53 +08:00 
			
		
		
		
	update
This commit is contained in:
		
							parent
							
								
									ea928bf3fc
								
							
						
					
					
						commit
						014ec92ff9
					
				| @ -11,7 +11,9 @@ export const store = configureStore({ | ||||
|     [subscribeApi.reducerPath]: subscribeApi.reducer, | ||||
|     [weightApi.reducerPath]: weightApi.reducer, | ||||
|   }, | ||||
|   middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(subscribeApi.middleware), | ||||
|   middleware: (getDefaultMiddleware) => getDefaultMiddleware() | ||||
|     .concat(subscribeApi.middleware) | ||||
|     .concat(weightApi.middleware), | ||||
| }); | ||||
| 
 | ||||
| export type AppDispatch = typeof store.dispatch; | ||||
|  | ||||
| @ -1,9 +1,28 @@ | ||||
| import React from 'react'; | ||||
| import { useGetWeightQuery } from './weightConfigSlice'; | ||||
| import { WeightConfig } from '../../utils/type'; | ||||
| import { useGetWeightQuery, useUpdateWeightMutation } from './weightConfigSlice'; | ||||
| 
 | ||||
| export default function WeightManager() { | ||||
|   const { data: weight } = useGetWeightQuery(); | ||||
|   const [updateWeight] = useUpdateWeightMutation(); | ||||
| 
 | ||||
|   const doUpdate = () => { | ||||
|     const weightConfig: WeightConfig = { | ||||
|       default: 20, | ||||
|       time_config: [ | ||||
|         { | ||||
|           start_time: '01:00', | ||||
|           end_time: '02:00', | ||||
|           weight: 50, | ||||
|         }, | ||||
|       ], | ||||
|     }; | ||||
|     updateWeight({ weight: weightConfig, platform_name: 'weibo', target: '' }); | ||||
|   }; | ||||
|   return ( | ||||
|     <div>{weight && JSON.stringify(weight)}</div> | ||||
|     <> | ||||
|       <div>{weight && JSON.stringify(weight)}</div> | ||||
|       <button type="button" onClick={doUpdate}> 123</button> | ||||
|     </> | ||||
|   ); | ||||
| } | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| import { createApi } from '@reduxjs/toolkit/query/react'; | ||||
| import { PlatformWeightConfigResp, StatusResp } from '../../utils/type'; | ||||
| import baseQueryWithAuth from '../auth/authQuery'; | ||||
| 
 | ||||
| export const weightApi = createApi({ | ||||
| @ -6,13 +7,22 @@ export const weightApi = createApi({ | ||||
|   baseQuery: baseQueryWithAuth, | ||||
|   tagTypes: ['Weight'], | ||||
|   endpoints: (builder) => ({ | ||||
|     getWeight: builder.query<any, void>({ | ||||
|     getWeight: builder.query<PlatformWeightConfigResp, void>({ | ||||
|       query: () => '/weight', | ||||
|       providesTags: ['Weight'], | ||||
|     }), | ||||
|     updateWeight: builder.mutation<StatusResp, | ||||
|       Pick<PlatformWeightConfigResp, 'platform_name' | 'target' | 'weight' >>({ | ||||
|         query: ({ platform_name: platformName, target, weight }) => ({ | ||||
|           method: 'PUT', | ||||
|           url: `/weight?platform_name=${platformName}&target=${target}`, | ||||
|           body: weight, | ||||
|         }), | ||||
|         invalidatesTags: ['Weight'], | ||||
|       }), | ||||
|   }), | ||||
| }); | ||||
| 
 | ||||
| export const { | ||||
|   useGetWeightQuery, | ||||
|   useGetWeightQuery, useUpdateWeightMutation, | ||||
| } = weightApi; | ||||
|  | ||||
| @ -58,3 +58,15 @@ export interface TimeWeightConfig { | ||||
|   end_time: string; | ||||
|   weight: number; | ||||
| } | ||||
| 
 | ||||
| export interface WeightConfig { | ||||
|   default: number; | ||||
|   time_config: TimeWeightConfig[]; | ||||
| } | ||||
| 
 | ||||
| export interface PlatformWeightConfigResp { | ||||
|   target: string; | ||||
|   target_name: string; | ||||
|   platform_name: string; | ||||
|   weight: WeightConfig; | ||||
| } | ||||
|  | ||||
| @ -136,9 +136,9 @@ def register_router_fastapi(driver: Driver, socketio): | ||||
|     async def _get_weight_config(): | ||||
|         return await get_weight_config() | ||||
| 
 | ||||
|     @app.patch(WEIGHT_URL, dependencies=[Depends(check_is_superuser)]) | ||||
|     async def _update_weight_config(platformName: str, target: str, req: WeightConfig): | ||||
|         return await update_weigth_config(platformName, target, req) | ||||
|     @app.put(WEIGHT_URL, dependencies=[Depends(check_is_superuser)]) | ||||
|     async def _update_weight_config(platform_name: str, target: str, req: WeightConfig): | ||||
|         return await update_weigth_config(platform_name, target, req) | ||||
| 
 | ||||
|     app.mount(URL_BASE, SinglePageApplication(directory=static_path), name="bison") | ||||
| 
 | ||||
|  | ||||
| @ -1,11 +1,10 @@ | ||||
| from pathlib import Path | ||||
| 
 | ||||
| import nonebot | ||||
| from alembic.config import Config | ||||
| from alembic.runtime.environment import EnvironmentContext | ||||
| from alembic.script.base import ScriptDirectory | ||||
| from nonebot.log import logger | ||||
| from nonebot_plugin_datastore import PluginData, create_session, db | ||||
| from nonebot_plugin_datastore import PluginData, db | ||||
| from nonebot_plugin_datastore.db import get_engine | ||||
| from sqlalchemy.engine.base import Connection | ||||
| from sqlalchemy.ext.asyncio.session import AsyncSession | ||||
|  | ||||
| @ -195,7 +195,10 @@ class DBConfig: | ||||
|                 raise NoSuchTargetException() | ||||
|             target_id = targetObj.id | ||||
|             targetObj.default_schedule_weight = conf.default | ||||
|             delete(ScheduleTimeWeight).where(ScheduleTimeWeight.target_id == target_id) | ||||
|             delete_statement = delete(ScheduleTimeWeight).where( | ||||
|                 ScheduleTimeWeight.target_id == target_id | ||||
|             ) | ||||
|             await sess.execute(delete_statement) | ||||
|             for time_conf in conf.time_config: | ||||
|                 new_conf = ScheduleTimeWeight( | ||||
|                     start_time=time_conf.start_time, | ||||
| @ -271,6 +274,7 @@ class DBConfig: | ||||
|                 res[platform_name][target.target] = PlatformWeightConfigResp( | ||||
|                     target=T_Target(target.target), | ||||
|                     target_name=target.target_name, | ||||
|                     platform_name=platform_name, | ||||
|                     weight=WeightConfig( | ||||
|                         default=target.default_schedule_weight, time_config=[] | ||||
|                     ), | ||||
|  | ||||
| @ -1,9 +1,7 @@ | ||||
| from datetime import datetime | ||||
| 
 | ||||
| from sqlalchemy.ext.declarative import declarative_base | ||||
| from sqlalchemy.orm import relationship | ||||
| from sqlalchemy.sql.schema import Column, ForeignKey, UniqueConstraint | ||||
| from sqlalchemy.sql.sqltypes import JSON, DateTime, Integer, String, Time | ||||
| from sqlalchemy.sql.sqltypes import JSON, Integer, String, Time | ||||
| 
 | ||||
| Base = declarative_base() | ||||
| 
 | ||||
|  | ||||
| @ -1,6 +1,8 @@ | ||||
| from dataclasses import dataclass | ||||
| from datetime import time | ||||
| from typing import Any, Callable, Literal, NamedTuple, NewType | ||||
| from typing import Any, Literal, NamedTuple, NewType | ||||
| 
 | ||||
| from pydantic import BaseModel | ||||
| 
 | ||||
| RawPost = NewType("RawPost", Any) | ||||
| Target = NewType("Target", str) | ||||
| @ -27,22 +29,19 @@ class UserSubInfo(NamedTuple): | ||||
|     tags: list[Tag] | ||||
| 
 | ||||
| 
 | ||||
| @dataclass | ||||
| class TimeWeightConfig: | ||||
| class TimeWeightConfig(BaseModel): | ||||
|     start_time: time | ||||
|     end_time: time | ||||
|     weight: int | ||||
| 
 | ||||
| 
 | ||||
| @dataclass | ||||
| class WeightConfig: | ||||
| 
 | ||||
| class WeightConfig(BaseModel): | ||||
|     default: int | ||||
|     time_config: list[TimeWeightConfig] | ||||
| 
 | ||||
| 
 | ||||
| @dataclass | ||||
| class PlatformWeightConfigResp: | ||||
| class PlatformWeightConfigResp(BaseModel): | ||||
|     target: Target | ||||
|     target_name: str | ||||
|     platform_name: str | ||||
|     weight: WeightConfig | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user