mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-03-20 12:08:09 +08:00
Merge pull request #2793 from InfinityPacer/feature/db
This commit is contained in:
@@ -86,13 +86,13 @@ def delete_transfer_history(history_in: schemas.TransferHistory,
|
||||
return schemas.Response(success=False, msg="记录不存在")
|
||||
# 册除媒体库文件
|
||||
if deletedest and history.dest_fileitem:
|
||||
dest_fileitem = schemas.FileItem(**json.loads(history.dest_fileitem))
|
||||
dest_fileitem = schemas.FileItem(**history.dest_fileitem)
|
||||
state = StorageChain().delete_file(dest_fileitem)
|
||||
if not state:
|
||||
return schemas.Response(success=False, msg=f"{dest_fileitem.path}删除失败")
|
||||
# 删除源文件
|
||||
if deletesrc and history.dest_fileitem:
|
||||
dest_fileitem = schemas.FileItem(**json.loads(history.dest_fileitem))
|
||||
dest_fileitem = schemas.FileItem(**history.dest_fileitem)
|
||||
state = StorageChain().delete_file(dest_fileitem)
|
||||
if not state:
|
||||
return schemas.Response(success=False, msg=f"{dest_fileitem.path}删除失败")
|
||||
|
||||
@@ -78,7 +78,7 @@ async def login_access_token(
|
||||
user_name=user.name,
|
||||
avatar=user.avatar,
|
||||
level=level,
|
||||
permissions=json.loads(user.permissions or '{}')
|
||||
permissions=user.permissions or {}
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -89,14 +89,14 @@ def manual_transfer(transer_item: ManualTransferItem,
|
||||
force = True
|
||||
if history.status and ("move" in history.mode):
|
||||
# 重新整理成功的转移,则使用成功的 dest 做 in_path
|
||||
src_fileitem = FileItem(**json.loads(history.dest_fileitem))
|
||||
src_fileitem = FileItem(**history.dest_fileitem)
|
||||
else:
|
||||
# 源路径
|
||||
src_fileitem = FileItem(**json.loads(history.src_fileitem))
|
||||
src_fileitem = FileItem(**history.src_fileitem)
|
||||
# 目的路径
|
||||
if history.dest_fileitem:
|
||||
# 删除旧的已整理文件
|
||||
dest_fileitem = FileItem(**json.loads(history.dest_fileitem))
|
||||
dest_fileitem = FileItem(**history.dest_fileitem)
|
||||
StorageChain().delete_file(dest_fileitem)
|
||||
|
||||
# 从历史数据获取信息
|
||||
|
||||
@@ -151,7 +151,7 @@ class MediaServerChain(ChainBase):
|
||||
seasoninfo[episode.season] = episode.episodes
|
||||
# 插入数据
|
||||
item_dict = item.dict()
|
||||
item_dict["seasoninfo"] = json.dumps(seasoninfo)
|
||||
item_dict["seasoninfo"] = seasoninfo
|
||||
item_dict["item_type"] = item_type
|
||||
self.dboper.add(**item_dict)
|
||||
logger.info(f"{server_name} 媒体库 {library.name} 同步完成,共同步数量:{library_count}")
|
||||
|
||||
@@ -501,7 +501,7 @@ class MessageChain(ChainBase):
|
||||
# 获取已下载剧集
|
||||
downloaded = [download.meta_info.begin_episode for download in downloads
|
||||
if download.meta_info.begin_episode]
|
||||
note = json.dumps(downloaded)
|
||||
note = downloaded
|
||||
else:
|
||||
note = None
|
||||
# 添加订阅,状态为R
|
||||
|
||||
@@ -480,7 +480,7 @@ class SubscribeChain(ChainBase):
|
||||
return default_sites
|
||||
try:
|
||||
# 尝试解析订阅中的站点数据
|
||||
user_sites = json.loads(subscribe.sites)
|
||||
user_sites = subscribe.sites
|
||||
# 计算 user_sites 和 default_sites 的交集
|
||||
intersection_sites = [site for site in user_sites if site in default_sites]
|
||||
# 如果交集与原始订阅不一致,更新数据库
|
||||
@@ -542,7 +542,7 @@ class SubscribeChain(ChainBase):
|
||||
domains = []
|
||||
if subscribe.sites:
|
||||
try:
|
||||
siteids = json.loads(subscribe.sites)
|
||||
siteids = subscribe.sites
|
||||
if siteids:
|
||||
domains = self.siteoper.get_domains_by_ids(siteids)
|
||||
except JSONDecodeError:
|
||||
@@ -812,10 +812,7 @@ class SubscribeChain(ChainBase):
|
||||
return
|
||||
note = []
|
||||
if subscribe.note:
|
||||
try:
|
||||
note = json.loads(subscribe.note)
|
||||
except JSONDecodeError:
|
||||
note = []
|
||||
note = subscribe.note or []
|
||||
for context in downloads:
|
||||
meta = context.meta_info
|
||||
mediainfo = context.media_info
|
||||
@@ -846,13 +843,9 @@ class SubscribeChain(ChainBase):
|
||||
return []
|
||||
if subscribe.type != MediaType.TV.value:
|
||||
return []
|
||||
try:
|
||||
episodes = json.loads(subscribe.note)
|
||||
logger.info(f'订阅 {subscribe.name} 第{subscribe.season}季 已下载集数:{episodes}')
|
||||
return episodes
|
||||
except JSONDecodeError:
|
||||
logger.warn(f'订阅 {subscribe.name} note字段解析失败')
|
||||
return []
|
||||
episodes = subscribe.note or []
|
||||
logger.info(f'订阅 {subscribe.name} 第{subscribe.season}季 已下载集数:{episodes}')
|
||||
return episodes
|
||||
|
||||
def __update_lack_episodes(self, lefts: Dict[Union[int, str], Dict[int, NotExistMediaInfo]],
|
||||
subscribe: Subscribe,
|
||||
@@ -1110,10 +1103,7 @@ class SubscribeChain(ChainBase):
|
||||
for subscribe in self.subscribeoper.list():
|
||||
if not subscribe.sites:
|
||||
continue
|
||||
try:
|
||||
sites = json.loads(subscribe.sites)
|
||||
except JSONDecodeError:
|
||||
sites = []
|
||||
sites = subscribe.sites or []
|
||||
if site_id not in sites:
|
||||
continue
|
||||
sites.remove(site_id)
|
||||
|
||||
@@ -603,13 +603,13 @@ class TransferChain(ChainBase):
|
||||
# 删除旧的已整理文件
|
||||
if history.dest_fileitem:
|
||||
# 解析目标文件对象
|
||||
dest_fileitem = FileItem(**json.loads(history.dest_fileitem))
|
||||
dest_fileitem = FileItem(**history.dest_fileitem)
|
||||
self.storagechain.delete_file(dest_fileitem)
|
||||
|
||||
# 强制整理
|
||||
if history.src_fileitem:
|
||||
# 解析源文件对象
|
||||
fileitem = FileItem(**json.loads(history.src_fileitem))
|
||||
fileitem = FileItem(**history.src_fileitem)
|
||||
state, errmsg = self.__do_transfer(fileitem=fileitem,
|
||||
mediainfo=mediainfo,
|
||||
download_hash=history.download_hash,
|
||||
|
||||
@@ -160,8 +160,6 @@ class Base:
|
||||
def update(self, db: Session, payload: dict):
|
||||
payload = {k: v for k, v in payload.items() if v is not None}
|
||||
for key, value in payload.items():
|
||||
if ObjectUtils.is_obj(value):
|
||||
value = json.dumps(value)
|
||||
setattr(self, key, value)
|
||||
if inspect(self).detached:
|
||||
db.add(self)
|
||||
|
||||
@@ -54,7 +54,7 @@ class MediaServerOper(DbOper):
|
||||
# 判断季是否存在
|
||||
if not item.seasoninfo:
|
||||
return None
|
||||
seasoninfo = json.loads(item.seasoninfo) or {}
|
||||
seasoninfo = item.seasoninfo or {}
|
||||
if kwargs.get("season") not in seasoninfo.keys():
|
||||
return None
|
||||
return item
|
||||
|
||||
@@ -52,7 +52,7 @@ class MessageOper(DbOper):
|
||||
"userid": userid,
|
||||
"action": action,
|
||||
"reg_time": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
|
||||
"note": note
|
||||
"note": note or {}
|
||||
})
|
||||
|
||||
# 从kwargs中去掉Message中没有的字段
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import time
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Sequence
|
||||
from sqlalchemy import Column, Integer, String, Sequence, JSON
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db import db_query, db_update, Base
|
||||
@@ -46,7 +46,7 @@ class DownloadHistory(Base):
|
||||
# 创建时间
|
||||
date = Column(String)
|
||||
# 附加信息
|
||||
note = Column(String)
|
||||
note = Column(JSON)
|
||||
|
||||
@staticmethod
|
||||
@db_query
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Sequence
|
||||
from sqlalchemy import Column, Integer, String, Sequence, JSON
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db import db_query, db_update, Base
|
||||
@@ -35,9 +35,9 @@ class MediaServerItem(Base):
|
||||
# 路径
|
||||
path = Column(String)
|
||||
# 季集
|
||||
seasoninfo = Column(String)
|
||||
seasoninfo = Column(JSON, default=dict)
|
||||
# 备注
|
||||
note = Column(String)
|
||||
note = Column(JSON)
|
||||
# 同步时间
|
||||
lst_mod_date = Column(String, default=datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Column, Integer, String, Sequence
|
||||
from sqlalchemy import Column, Integer, String, Sequence, JSON
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db import db_query, Base
|
||||
@@ -30,7 +30,7 @@ class Message(Base):
|
||||
# 消息方向:0-接收息,1-发送消息
|
||||
action = Column(Integer)
|
||||
# 附件json
|
||||
note = Column(String)
|
||||
note = Column(JSON)
|
||||
|
||||
@staticmethod
|
||||
@db_query
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Column, Integer, String, Sequence
|
||||
from sqlalchemy import Column, Integer, String, Sequence, JSON
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db import db_query, db_update, Base
|
||||
@@ -11,7 +11,7 @@ class PluginData(Base):
|
||||
id = Column(Integer, Sequence('id'), primary_key=True, index=True)
|
||||
plugin_id = Column(String, nullable=False, index=True)
|
||||
key = Column(String, index=True, nullable=False)
|
||||
value = Column(String)
|
||||
value = Column(JSON)
|
||||
|
||||
@staticmethod
|
||||
@db_query
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Boolean, Column, Integer, String, Sequence
|
||||
from sqlalchemy import Boolean, Column, Integer, String, Sequence, JSON
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db import db_query, db_update, Base
|
||||
@@ -38,7 +38,7 @@ class Site(Base):
|
||||
# 是否公开站点
|
||||
public = Column(Integer)
|
||||
# 附加信息
|
||||
note = Column(String)
|
||||
note = Column(JSON)
|
||||
# 流控单位周期
|
||||
limit_interval = Column(Integer, default=0)
|
||||
# 流控次数
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Sequence
|
||||
from sqlalchemy import Column, Integer, String, Sequence, JSON
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db import db_query, db_update, Base
|
||||
@@ -24,7 +24,7 @@ class SiteStatistic(Base):
|
||||
# 最后访问时间
|
||||
lst_mod_date = Column(String, default=datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
||||
# 耗时记录 Json
|
||||
note = Column(String)
|
||||
note = Column(JSON)
|
||||
|
||||
@staticmethod
|
||||
@db_query
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Sequence, Float
|
||||
from sqlalchemy import Column, Integer, String, Sequence, Float, JSON
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db import db_query, Base
|
||||
@@ -40,11 +40,11 @@ class SiteUserData(Base):
|
||||
# 下载体积
|
||||
leeching_size = Column(Float, default=0)
|
||||
# 做种人数, 种子大小 JSON
|
||||
seeding_info = Column(String)
|
||||
seeding_info = Column(JSON, default=dict)
|
||||
# 未读消息
|
||||
message_unread = Column(Integer, default=0)
|
||||
# 未读消息内容 JSON
|
||||
message_unread_contents = Column(String)
|
||||
message_unread_contents = Column(JSON, default=list)
|
||||
# 错误信息
|
||||
err_msg = Column(String)
|
||||
# 更新日期
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import time
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Sequence, Float
|
||||
from sqlalchemy import Column, Integer, String, Sequence, Float, JSON
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db import db_query, db_update, Base
|
||||
@@ -53,7 +53,7 @@ class Subscribe(Base):
|
||||
# 缺失集数
|
||||
lack_episode = Column(Integer)
|
||||
# 附加信息
|
||||
note = Column(String)
|
||||
note = Column(JSON)
|
||||
# 状态:N-新建, R-订阅中
|
||||
state = Column(String, nullable=False, index=True, default='N')
|
||||
# 最后更新时间
|
||||
@@ -63,7 +63,7 @@ class Subscribe(Base):
|
||||
# 订阅用户
|
||||
username = Column(String)
|
||||
# 订阅站点
|
||||
sites = Column(String)
|
||||
sites = Column(JSON, default=list)
|
||||
# 是否洗版
|
||||
best_version = Column(Integer, default=0)
|
||||
# 当前优先级
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Column, Integer, String, Sequence
|
||||
from sqlalchemy import Column, Integer, String, Sequence, JSON
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db import db_query, db_update, Base
|
||||
@@ -12,7 +12,7 @@ class SystemConfig(Base):
|
||||
# 主键
|
||||
key = Column(String, index=True)
|
||||
# 值
|
||||
value = Column(String, nullable=True)
|
||||
value = Column(JSON)
|
||||
|
||||
@staticmethod
|
||||
@db_query
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import time
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Sequence, Boolean, func, or_
|
||||
from sqlalchemy import Column, Integer, String, Sequence, Boolean, func, or_, JSON
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db import db_query, db_update, Base
|
||||
@@ -16,13 +16,13 @@ class TransferHistory(Base):
|
||||
# 源存储
|
||||
src_storage = Column(String)
|
||||
# 源文件项
|
||||
src_fileitem = Column(String)
|
||||
src_fileitem = Column(JSON, default=dict)
|
||||
# 目标路径
|
||||
dest = Column(String)
|
||||
# 目标存储
|
||||
dest_storage = Column(String)
|
||||
# 目标文件项
|
||||
dest_fileitem = Column(String)
|
||||
dest_fileitem = Column(JSON, default=dict)
|
||||
# 转移模式 move/copy/link...
|
||||
mode = Column(String)
|
||||
# 类型 电影/电视剧
|
||||
@@ -52,7 +52,7 @@ class TransferHistory(Base):
|
||||
# 时间
|
||||
date = Column(String, index=True)
|
||||
# 文件清单,以JSON存储
|
||||
files = Column(String)
|
||||
files = Column(JSON, default=list)
|
||||
|
||||
@staticmethod
|
||||
@db_query
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Tuple, Any
|
||||
|
||||
from sqlalchemy import Boolean, Column, Integer, String, Sequence
|
||||
from sqlalchemy import Boolean, Column, Integer, String, Sequence, JSON
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.core.security import verify_password
|
||||
@@ -31,9 +31,9 @@ class User(Base):
|
||||
# otp秘钥
|
||||
otp_secret = Column(String, default=None)
|
||||
# 用户权限 json
|
||||
permissions = Column(String, default='')
|
||||
permissions = Column(JSON, default=dict)
|
||||
# 用户个性化设置 json
|
||||
settings = Column(String, default='')
|
||||
settings = Column(JSON, default=dict)
|
||||
|
||||
@staticmethod
|
||||
@db_query
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Column, Integer, String, Sequence, UniqueConstraint, Index
|
||||
from sqlalchemy import Column, Integer, String, Sequence, UniqueConstraint, Index, JSON
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db import db_query, db_update, Base
|
||||
@@ -14,7 +14,7 @@ class UserConfig(Base):
|
||||
# 配置键
|
||||
key = Column(String)
|
||||
# 值
|
||||
value = Column(String, nullable=True)
|
||||
value = Column(JSON)
|
||||
|
||||
__table_args__ = (
|
||||
# 用户名和配置键联合唯一
|
||||
|
||||
@@ -36,8 +36,6 @@ class PluginDataOper(DbOper):
|
||||
data = PluginData.get_plugin_data_by_key(self._db, plugin_id, key)
|
||||
if not data:
|
||||
return None
|
||||
if ObjectUtils.is_objstr(data.value):
|
||||
return json.loads(data.value)
|
||||
return data.value
|
||||
else:
|
||||
return PluginData.get_plugin_data(self._db, plugin_id)
|
||||
|
||||
@@ -7,7 +7,6 @@ from app.db.models import SiteIcon
|
||||
from app.db.models.site import Site
|
||||
from app.db.models.sitestatistic import SiteStatistic
|
||||
from app.db.models.siteuserdata import SiteUserData
|
||||
from app.utils.object import ObjectUtils
|
||||
|
||||
|
||||
class SiteOper(DbOper):
|
||||
@@ -126,9 +125,7 @@ class SiteOper(DbOper):
|
||||
else:
|
||||
# 不存在则插入
|
||||
for key, value in payload.items():
|
||||
if ObjectUtils.is_obj(value):
|
||||
payload[key] = json.dumps(value)
|
||||
SiteUserData(**payload).create(self._db)
|
||||
SiteUserData(**payload).create(self._db)
|
||||
return True, "更新站点用户数据成功"
|
||||
|
||||
def get_userdata(self) -> List[SiteUserData]:
|
||||
@@ -179,7 +176,7 @@ class SiteOper(DbOper):
|
||||
if sta:
|
||||
avg_seconds, note = None, {}
|
||||
if seconds is not None:
|
||||
note: dict = json.loads(sta.note or "{}")
|
||||
note: dict = sta.note or {}
|
||||
note[lst_date] = seconds or 1
|
||||
avg_times = len(note.keys())
|
||||
if avg_times > 10:
|
||||
@@ -205,7 +202,7 @@ class SiteOper(DbOper):
|
||||
seconds=seconds or 1,
|
||||
lst_state=0,
|
||||
lst_mod_date=lst_date,
|
||||
note=json.dumps(note)
|
||||
note=note
|
||||
).create(self._db)
|
||||
|
||||
def fail(self, domain: str):
|
||||
|
||||
@@ -18,10 +18,7 @@ class SystemConfigOper(DbOper, metaclass=Singleton):
|
||||
"""
|
||||
super().__init__()
|
||||
for item in SystemConfig.list(self._db):
|
||||
if ObjectUtils.is_objstr(item.value):
|
||||
self.__SYSTEMCONF[item.key] = json.loads(item.value)
|
||||
else:
|
||||
self.__SYSTEMCONF[item.key] = item.value
|
||||
self.__SYSTEMCONF[item.key] = item.value
|
||||
|
||||
def set(self, key: Union[str, SystemConfigKey], value: Any):
|
||||
"""
|
||||
@@ -38,10 +35,6 @@ class SystemConfigOper(DbOper, metaclass=Singleton):
|
||||
else:
|
||||
conf.delete(self._db, conf.id)
|
||||
else:
|
||||
if ObjectUtils.is_obj(value):
|
||||
value = json.dumps(value)
|
||||
elif value is None:
|
||||
value = ''
|
||||
conf = SystemConfig(key=key, value=value)
|
||||
conf.create(self._db)
|
||||
|
||||
|
||||
@@ -128,10 +128,10 @@ class TransferHistoryOper(DbOper):
|
||||
self.add_force(
|
||||
src=fileitem.path,
|
||||
src_storage=fileitem.storage,
|
||||
src_fileitem=json.dumps(fileitem.dict()),
|
||||
src_fileitem=fileitem.dict(),
|
||||
dest=transferinfo.target_item.path if transferinfo.target_item else None,
|
||||
dest_storage=transferinfo.target_item.storage if transferinfo.target_item else None,
|
||||
dest_fileitem=json.dumps(transferinfo.target_item.dict()) if transferinfo.target_item else None,
|
||||
dest_fileitem=transferinfo.target_item.dict() if transferinfo.target_item else None,
|
||||
mode=mode,
|
||||
type=mediainfo.type.value,
|
||||
category=mediainfo.category,
|
||||
@@ -146,7 +146,7 @@ class TransferHistoryOper(DbOper):
|
||||
image=mediainfo.get_poster_image(),
|
||||
download_hash=download_hash,
|
||||
status=1,
|
||||
files=json.dumps(transferinfo.file_list)
|
||||
files=transferinfo.file_list
|
||||
)
|
||||
|
||||
def add_fail(self, fileitem: FileItem, mode: str, meta: MetaBase, mediainfo: MediaInfo = None,
|
||||
@@ -158,10 +158,10 @@ class TransferHistoryOper(DbOper):
|
||||
his = self.add_force(
|
||||
src=fileitem.path,
|
||||
src_storage=fileitem.storage,
|
||||
src_fileitem=json.dumps(fileitem.dict()),
|
||||
src_fileitem=fileitem.dict(),
|
||||
dest=transferinfo.target_item.path if transferinfo.target_item else None,
|
||||
dest_storage=transferinfo.target_item.storage if transferinfo.target_item else None,
|
||||
dest_fileitem=json.dumps(transferinfo.target_item.dict()) if transferinfo.target_item else None,
|
||||
dest_fileitem=transferinfo.target_item.dict() if transferinfo.target_item else None,
|
||||
mode=mode,
|
||||
type=mediainfo.type.value,
|
||||
category=mediainfo.category,
|
||||
@@ -177,7 +177,7 @@ class TransferHistoryOper(DbOper):
|
||||
download_hash=download_hash,
|
||||
status=0,
|
||||
errmsg=transferinfo.message or '未知错误',
|
||||
files=json.dumps(transferinfo.file_list)
|
||||
files=transferinfo.file_list
|
||||
)
|
||||
else:
|
||||
his = self.add_force(
|
||||
@@ -185,7 +185,7 @@ class TransferHistoryOper(DbOper):
|
||||
year=meta.year,
|
||||
src=fileitem.path,
|
||||
src_storage=fileitem.storage,
|
||||
src_fileitem=json.dumps(fileitem.dict()),
|
||||
src_fileitem=fileitem.dict(),
|
||||
mode=mode,
|
||||
seasons=meta.season,
|
||||
episodes=meta.episode,
|
||||
|
||||
@@ -80,10 +80,7 @@ class UserOper(DbOper):
|
||||
"""
|
||||
user = User.get_by_name(self._db, name)
|
||||
if user:
|
||||
try:
|
||||
return json.loads(user.permissions)
|
||||
except json.JSONDecodeError:
|
||||
return {}
|
||||
return user.permissions or {}
|
||||
return {}
|
||||
|
||||
def get_settings(self, name: str) -> Optional[dict]:
|
||||
@@ -92,12 +89,7 @@ class UserOper(DbOper):
|
||||
"""
|
||||
user = User.get_by_name(self._db, name)
|
||||
if user:
|
||||
try:
|
||||
if user.settings:
|
||||
return json.loads(user.settings)
|
||||
return {}
|
||||
except json.JSONDecodeError:
|
||||
return {}
|
||||
return user.settings or {}
|
||||
return None
|
||||
|
||||
def get_setting(self, name: str, key: str) -> Optional[str]:
|
||||
|
||||
@@ -18,8 +18,7 @@ class UserConfigOper(DbOper, metaclass=Singleton):
|
||||
"""
|
||||
super().__init__()
|
||||
for item in UserConfig.list(self._db):
|
||||
value = json.loads(item.value) if ObjectUtils.is_objstr(item.value) else item.value
|
||||
self.__set_config_cache(username=item.username, key=item.key, value=value)
|
||||
self.__set_config_cache(username=item.username, key=item.key, value=item.value)
|
||||
|
||||
def set(self, username: str, key: Union[str, UserConfigKey], value: Any):
|
||||
"""
|
||||
@@ -30,10 +29,6 @@ class UserConfigOper(DbOper, metaclass=Singleton):
|
||||
# 更新内存
|
||||
self.__set_config_cache(username=username, key=key, value=value)
|
||||
# 写入数据库
|
||||
if ObjectUtils.is_obj(value):
|
||||
value = json.dumps(value)
|
||||
elif value is None:
|
||||
value = ''
|
||||
conf = UserConfig.get_by_key(db=self._db, username=username, key=key)
|
||||
if conf:
|
||||
if value:
|
||||
|
||||
@@ -116,7 +116,7 @@ class MediaServerItem(BaseModel):
|
||||
# 季集
|
||||
seasoninfo: Optional[Dict[int, list]] = None
|
||||
# 备注
|
||||
note: Optional[str] = None
|
||||
note: Optional[dict] = None
|
||||
# 同步时间
|
||||
lst_mod_date: Optional[str] = None
|
||||
user_state: Optional[MediaServerItemUserState] = None
|
||||
|
||||
@@ -63,7 +63,7 @@ class SiteStatistic(BaseModel):
|
||||
# 最后修改时间
|
||||
lst_mod_date: Optional[str]
|
||||
# 备注
|
||||
note: Optional[str] = None
|
||||
note: Optional[dict] = None
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
Reference in New Issue
Block a user