mirror of
https://github.com/ngfchl/ptools
synced 2023-07-10 13:41:22 +08:00
1. 重新初始化
This commit is contained in:
2
ptools/__init__.py
Normal file
2
ptools/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This will make sure the app is always imported when
|
||||
# Django starts so that shared_task will use this app.
|
||||
16
ptools/asgi.py
Normal file
16
ptools/asgi.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for djangoProject project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ptools.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
149
ptools/base.py
Normal file
149
ptools/base.py
Normal file
@@ -0,0 +1,149 @@
|
||||
from enum import Enum
|
||||
|
||||
from django.db import models
|
||||
|
||||
|
||||
# 基类
|
||||
class BaseEntity(models.Model):
|
||||
created_at = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
|
||||
updated_at = models.DateTimeField(verbose_name='更新时间', auto_now=True)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class StatusCodeEnum(Enum):
|
||||
"""状态码枚举类"""
|
||||
|
||||
OK = (0, '成功')
|
||||
ERROR = (-1, '错误')
|
||||
SERVER_ERR = (500, '服务器异常')
|
||||
|
||||
# OCR 1
|
||||
OCR_NO_CONFIG = (1001, 'OCR未配置')
|
||||
OCR_ACCESS_ERR = (1002, '在线OCR接口访问错误')
|
||||
# 签到
|
||||
SUCCESS_SIGN_IN = (2000, '签到成功!')
|
||||
FAILED_SIGN_IN = (2001, '签到失败!')
|
||||
IS_SIGN_IN = (2002, '请勿重复签到!')
|
||||
ALL_SIGN_IN = (2003, '已全部签到哦!')
|
||||
# 验证码 4
|
||||
IMAGE_CODE_ERR = (4001, '验证码错误(Wrong CAPTCHA)!')
|
||||
THROTTLING_ERR = (4002, '访问过于频繁')
|
||||
# 网络
|
||||
WEB_CONNECT_ERR = (4404, '网站访问错误!')
|
||||
WEB_CLOUD_FLARE = (4503, '我遇到CF盾咯!')
|
||||
NECESSARY_PARAM_ERR = (4003, '缺少必传参数')
|
||||
USER_ERR = (4004, '用户名错误')
|
||||
PWD_ERR = (4005, '密码错误')
|
||||
CPWD_ERR = (4006, '密码不一致')
|
||||
MOBILE_ERR = (4007, '手机号错误')
|
||||
SMS_CODE_ERR = (4008, '短信验证码有误')
|
||||
ALLOW_ERR = (4009, '未勾选协议')
|
||||
SESSION_ERR = (4010, '用户未登录')
|
||||
|
||||
DB_ERR = (5000, '数据错误')
|
||||
EMAIL_ERR = (5001, '邮箱错误')
|
||||
TEL_ERR = (5002, '固定电话错误')
|
||||
NODATA_ERR = (5003, '无数据')
|
||||
NEW_PWD_ERR = (5004, '新密码错误')
|
||||
OPENID_ERR = (5005, '无效的openid')
|
||||
PARAM_ERR = (5006, '参数错误')
|
||||
STOCK_ERR = (5007, '库存不足')
|
||||
|
||||
@property
|
||||
def code(self):
|
||||
"""获取状态码"""
|
||||
return self.value[0]
|
||||
|
||||
@property
|
||||
def errmsg(self):
|
||||
"""获取状态码信息"""
|
||||
return self.value[1]
|
||||
|
||||
|
||||
class CommonResponse:
|
||||
"""
|
||||
统一的json返回格式
|
||||
"""
|
||||
|
||||
def __init__(self, data, status: StatusCodeEnum, msg):
|
||||
self.data = data
|
||||
self.code = status.code
|
||||
if msg is None:
|
||||
self.msg = status.errmsg
|
||||
else:
|
||||
self.msg = msg
|
||||
|
||||
@classmethod
|
||||
def success(cls, data=None, status=StatusCodeEnum.OK, msg=None):
|
||||
return cls(data, status, msg)
|
||||
|
||||
@classmethod
|
||||
def error(cls, data=None, status=StatusCodeEnum.ERROR, msg=None):
|
||||
return cls(data, status, msg)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"code": self.code,
|
||||
"msg": self.msg,
|
||||
"data": self.data
|
||||
}
|
||||
|
||||
|
||||
# 支持的下载器种类
|
||||
class DownloaderCategory(models.TextChoices):
|
||||
# 下载器名称
|
||||
# Deluge = 'De', 'Deluge'
|
||||
# Transmission = 'Tr', 'Transmission'
|
||||
qBittorrent = 'Qb', 'qBittorrent'
|
||||
|
||||
|
||||
class TorrentBaseInfo:
|
||||
category_list = {
|
||||
0: "空类型",
|
||||
1: "电影Movies",
|
||||
2: "电视剧TV Series",
|
||||
3: "综艺TV Shows",
|
||||
4: "纪录片Documentaries",
|
||||
5: "动漫Animations",
|
||||
6: "音乐视频Music Videos",
|
||||
7: "体育Sports",
|
||||
8: "音乐Music",
|
||||
9: "电子书Ebook",
|
||||
10: "软件Software",
|
||||
11: "游戏Game",
|
||||
12: "资料Education",
|
||||
13: "旅游Travel",
|
||||
14: "美食Food",
|
||||
15: "其他Misc",
|
||||
}
|
||||
sale_list = {
|
||||
1: '无优惠',
|
||||
2: 'Free',
|
||||
3: '2X',
|
||||
4: '2XFree',
|
||||
5: '50%',
|
||||
6: '2X50%',
|
||||
7: '30%',
|
||||
8: '6xFree'
|
||||
}
|
||||
|
||||
|
||||
class Trigger(models.TextChoices):
|
||||
# date = 'date', '单次任务'
|
||||
interval = 'interval', '间隔任务'
|
||||
cron = 'cron', 'cron任务'
|
||||
|
||||
|
||||
class PushConfig(models.TextChoices):
|
||||
# date = 'date', '单次任务'
|
||||
wechat_work_push = 'wechat_work_push', '企业微信通知'
|
||||
wxpusher_push = 'wxpusher_push', 'WxPusher通知'
|
||||
pushdeer_push = 'pushdeer_push', 'PushDeer通知'
|
||||
bark_push = 'bark_push', 'Bark通知'
|
||||
|
||||
|
||||
class OCRConfig(models.TextChoices):
|
||||
# date = 'date', '单次任务'
|
||||
baidu_aip = 'baidu_aip', '百度OCR'
|
||||
206
ptools/settings.py
Normal file
206
ptools/settings.py
Normal file
@@ -0,0 +1,206 @@
|
||||
"""
|
||||
Django settings for djangoProject project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 4.0.6.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.0/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.0/ref/settings/
|
||||
"""
|
||||
import os
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
from pathlib import Path
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-6wrh^t$@gbb^s^=79@%cv=%yhq6gl^kane#g@-n-*n6+s1lo2f'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'simpleui',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'import_export',
|
||||
'django_apscheduler',
|
||||
'pt_site',
|
||||
'auto_pt',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
# 'django.middleware.cache.UpdateCacheMiddleware', # redis1
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
# 'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
# 'django.middleware.cache.FetchFromCacheMiddleware', # redis2
|
||||
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'ptools.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [BASE_DIR / 'templates']
|
||||
,
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'ptools.wsgi.application'
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db/db.sqlite3',
|
||||
'OPTIONS': {
|
||||
'timeout': 60,
|
||||
'check_same_thread': False
|
||||
}
|
||||
},
|
||||
# 'default': {
|
||||
# 'ENGINE': 'django.db.backends.mysql', # 数据库引擎
|
||||
# 'NAME': 'pt', # 数据库名,先前创建的
|
||||
# 'USER': 'pt', # 用户名,可以自己创建用户
|
||||
# 'PASSWORD': 'bfmAjPysaFkmWsfs', # 密码
|
||||
# 'HOST': 'docker_db_1', # mysql服务所在的主机ip
|
||||
# 'PORT': '3306', # mysql服务端口
|
||||
# },
|
||||
# 'default': {
|
||||
# 'ENGINE': 'django.db.backends.mysql', # 数据库引擎
|
||||
# 'NAME': 'pt', # 数据库名,先前创建的
|
||||
# 'USER': 'pt', # 用户名,可以自己创建用户
|
||||
# 'PASSWORD': 'bfmAjPysaFkmWsfs', # 密码
|
||||
# 'HOST': 'bt.9oho.cn', # mysql服务所在的主机ip
|
||||
# 'PORT': '3306', # mysql服务端口
|
||||
# }
|
||||
}
|
||||
|
||||
CACHES = {
|
||||
'default': {
|
||||
'BACKEND': 'django_redis.cache.RedisCache',
|
||||
# 'LOCATION': "redis://127.0.0.1:6333",
|
||||
'LOCATION': "redis://127.0.0.1:6379/0",
|
||||
'TIMEOUT': 200, # NONE 永不超时
|
||||
'OPTIONS': {
|
||||
# "PASSWORD": "", # 密码,没有可不设置
|
||||
'CLIENT_CLASS': 'django_redis.client.DefaultClient', # redis-py 客户端
|
||||
'PICKLE_VERSION': -1, # 插件使用PICKLE进行序列化,-1表示最新版本
|
||||
'CONNECTION_POOL_KWARGS': {"max_connections": 100}, # 连接池最大连接数
|
||||
'SOCKET_CONNECT_TIMEOUT': 5, # 连接超时
|
||||
'SOCKET_TIMEOUT': 5, # 读写超时
|
||||
}
|
||||
# "KEY_PREFIX ":"test",#前缀
|
||||
}
|
||||
}
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/4.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'zh-Hans'
|
||||
|
||||
TIME_ZONE = 'Asia/Shanghai'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = False
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.0/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
# STATIC_ROOT = os.path.join(BASE_DIR, 'static')
|
||||
STATICFILES_DIRS = (
|
||||
os.path.join(os.path.join(BASE_DIR, 'static')),
|
||||
)
|
||||
MEDIA_URL = 'media/'
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
APSCHEDULER_DATETIME_FORMAT = 'Y-m-d H:i:s' # Default
|
||||
# 自定义配置
|
||||
SIMPLEUI_HOME_TITLE = 'PT一下你就知道'
|
||||
SIMPLEUI_HOME_ICON = 'fa fa-optin-monster'
|
||||
SIMPLEUI_HOME_INFO = False
|
||||
SIMPLEUI_LOGO = '/static/logo1.png'
|
||||
# SIMPLEUI配置
|
||||
SIMPLEUI_CONFIG = {
|
||||
'system_keep': True,
|
||||
# 'menu_display': ['下载管理', ], # 开启排序和过滤功能, 不填此字段为默认排序和全部显示, 空列表[] 为全部不显示.
|
||||
'dynamic': True, # 设置是否开启动态菜单, 默认为False. 如果开启, 则会在每次用户登陆时动态展示菜单内容
|
||||
'menus': [{
|
||||
'app': 'downloader',
|
||||
'name': '下载管理',
|
||||
'icon': 'fas fa-user-shield',
|
||||
'models': [{
|
||||
'name': '任务管理',
|
||||
'icon': 'fa fa-user',
|
||||
'url': '/downloader/downloading/index'
|
||||
}, {
|
||||
'name': '查询种子',
|
||||
'icon': 'fa fa-user',
|
||||
'url': '/downloader/ptspider/index'
|
||||
}]
|
||||
}, {
|
||||
'app': 'update',
|
||||
'name': '更新',
|
||||
'icon': 'fas fa-shield',
|
||||
'models': [{
|
||||
'name': '重启更新',
|
||||
'icon': 'fa fa-refresh',
|
||||
'url': '/tasks/restart'
|
||||
}, ]
|
||||
}]
|
||||
}
|
||||
33
ptools/urls.py
Normal file
33
ptools/urls.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""djangoProject URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/4.0/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import path, include
|
||||
|
||||
from pt_site.views import *
|
||||
|
||||
|
||||
def index(request):
|
||||
return redirect(to='/admin')
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('', index),
|
||||
path(r'admin/', admin.site.urls),
|
||||
path(r'tasks/', include("auto_pt.urls"), name='tasks'), #
|
||||
path(r'site/', include("pt_site.urls"), name='tasks') #
|
||||
|
||||
]
|
||||
16
ptools/wsgi.py
Normal file
16
ptools/wsgi.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for djangoProject project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ptools.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
Reference in New Issue
Block a user