service.py 2.4 KB
Newer Older
H
hjdhnx 已提交
1 2 3 4 5 6 7 8
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File  : service.py.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date  : 2022/9/6

from base.R import copy_utils
from models.storage import Storage
H
hjdhnx 已提交
9
from utils.cfg import cfg
H
hjdhnx 已提交
10 11 12 13 14 15 16 17 18 19

class storage_service(object):

    @staticmethod
    def query_all():
        # 查询所有
        res = Storage.query.all()
        return copy_utils.obj_to_list(res)

    def __init__(self):
H
hjdhnx 已提交
20 21 22 23 24 25
        conf_list = ['LIVE_URL', 'USE_PY', 'PLAY_URL', 'PLAY_DISABLE', 'LAZYPARSE_MODE', 'WALL_PAPER_ENABLE',
                     'WALL_PAPER', 'UNAME', 'PWD', 'LIVE_MODE', 'CATE_EXCLUDE', 'TAB_EXCLUDE']
        for conf in conf_list:
            if not self.hasItem(conf):
                print(f'开始初始化{conf}')
                self.setItem(conf, cfg.get(conf))
H
hjdhnx 已提交
26

H
hjdhnx 已提交
27 28
    @classmethod
    def getStoreConf(self):
H
hjdhnx 已提交
29
        # MAX_CONTENT_LENGTH 最大上传和端口ip一样是顶级配置,无法外部修改的
H
hjdhnx 已提交
30 31 32 33
        conf_list = ['LIVE_URL', 'LIVE_MODE','PLAY_URL', 'PID_URL','USE_PY', 'PLAY_DISABLE', 'LAZYPARSE_MODE', 'WALL_PAPER_ENABLE',
                     'WALL_PAPER', 'UNAME', 'PWD',  'CATE_EXCLUDE', 'TAB_EXCLUDE']
        conf_name_list = ['直播地址', '直播模式','远程地址', '进程管理链接','启用py源', '禁用免嗅', '免嗅模式', '启用壁纸', '壁纸链接', '管理账号',
                          '管理密码',  '分类排除', '线路排除']
H
hjdhnx 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
        conf_lists = []
        for i in range(len(conf_list)):
            conf = conf_list[i]
            conf_lists.append({
                'key': conf,
                'value': self.getItem(conf),
                'name': conf_name_list[i]
            })
        return conf_lists

    @classmethod
    def getStoreConfDict(self):
        store_conf = self.getStoreConf()
        store_conf_dict = {}
        for stc in store_conf:
            store_conf_dict[stc['key']] = stc['value']
        return store_conf_dict
H
hjdhnx 已提交
51

H
hjdhnx 已提交
52 53
    @classmethod
    def getItem(self, key, value=''):
H
hjdhnx 已提交
54 55 56 57 58 59 60 61
        res = Storage.getItem(key,value)
        if str(res) == '0' or str(res) == 'false' or str(res) == 'False':
            return 0
        return res

    @classmethod
    def hasItem(self, key):
        return Storage.hasItem(key)
H
hjdhnx 已提交
62 63 64 65 66 67 68 69

    @classmethod
    def setItem(self,key, value):
        return Storage.setItem(key, value)

    @classmethod
    def clearItem(self,key):
        return Storage.clearItem(key)