mirror of
https://github.com/wahyd4/links.git
synced 2026-08-08 21:04:53 +10:00
Add logic to display thumbnails
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import os
|
||||
from celery import Celery
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
|
||||
|
||||
app = Celery('core')
|
||||
app.config_from_object('django.conf:settings', namespace='CELERY')
|
||||
app.autodiscover_tasks()
|
||||
@@ -0,0 +1,14 @@
|
||||
from django.conf import settings
|
||||
from django.urls import resolve
|
||||
from django.utils import translation
|
||||
from django.middleware.locale import LocaleMiddleware
|
||||
|
||||
class CustomLocaleMiddleware(LocaleMiddleware):
|
||||
def process_request(self, request):
|
||||
url_path = request.path_info.lstrip('/')
|
||||
|
||||
# 检查是否是 API 路径
|
||||
if url_path.startswith('api/'):
|
||||
return None
|
||||
|
||||
return super().process_request(request)
|
||||
@@ -0,0 +1,221 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
import links.patches # 添加这一行在文件最上方
|
||||
from django.urls import re_path
|
||||
|
||||
# 构建路径,如 BASE_DIR / 'subdir'
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles', # Make sure this is here only once
|
||||
'widget_tweaks',
|
||||
'links',
|
||||
'tailwind',
|
||||
'new_theme',
|
||||
'simplemde',
|
||||
'markdown', # 只需要基本的markdown包
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'core.urls'
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'core.middleware.CustomLocaleMiddleware', # 替换原来的 LocaleMiddleware
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
'whitenoise.middleware.WhiteNoiseMiddleware',
|
||||
]
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [os.path.join(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',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
# ... 其他设置 ...
|
||||
|
||||
# 添加以下基本设置(如果尚未存在)
|
||||
SECRET_KEY = 'your-secret-key-here' # 请更改为一个安全的随机值
|
||||
DEBUG = True
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
# 数据库设置(使用默认的SQLite配置)
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
# 'NAME': '/app/data/db.sqlite3', # Updated path
|
||||
'NAME': BASE_DIR / 'data/db.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
# 静态文件设置
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||
STATICFILES_DIRS = [
|
||||
os.path.join(BASE_DIR, 'static'),
|
||||
]
|
||||
|
||||
# 默认自动字段类型
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
# ... 其他设置 ...
|
||||
|
||||
LANGUAGES = [
|
||||
('en', _('English')),
|
||||
('zh-hans', _('Simplified Chinese')),
|
||||
]
|
||||
|
||||
LOCALE_PATHS = [
|
||||
BASE_DIR / 'locale',
|
||||
]
|
||||
|
||||
LANGUAGE_CODE = 'en' # 设置默认语言为英语
|
||||
|
||||
USE_I18N = True
|
||||
USE_L10N = True
|
||||
USE_TZ = True
|
||||
|
||||
# ... 其他设置 ...
|
||||
|
||||
ROOT_URLCONF = 'core.urls'
|
||||
|
||||
# ... 其他设置 ...
|
||||
|
||||
TAILWIND_APP_NAME = 'new_theme'
|
||||
|
||||
INTERNAL_IPS = [
|
||||
"127.0.0.1",
|
||||
]
|
||||
|
||||
|
||||
# Add this at the end of the file
|
||||
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
||||
|
||||
CSRF_TRUSTED_ORIGINS = os.environ.get('CSRF_TRUSTED_ORIGINS', 'http://localhost:8000').split(',')
|
||||
|
||||
# SimpleMDE 配置
|
||||
SIMPLEMDE_OPTIONS = {
|
||||
'placeholder': 'Type here...',
|
||||
'status': False,
|
||||
'autosave': {
|
||||
'enabled': True,
|
||||
'delay': 10000,
|
||||
},
|
||||
}
|
||||
|
||||
MEDIA_URL = '/media/'
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'handlers': {
|
||||
'console': {
|
||||
'class': 'logging.StreamHandler',
|
||||
},
|
||||
},
|
||||
'root': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
},
|
||||
'loggers': {
|
||||
'django': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_RENDERER_CLASSES': [
|
||||
'rest_framework.renderers.JSONRenderer',
|
||||
],
|
||||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
||||
'PAGE_SIZE': 10,
|
||||
'UNAUTHENTICATED_USER': None, # 添加这行
|
||||
}
|
||||
|
||||
LANGUAGE_URL_MAP = {
|
||||
'en': 'en',
|
||||
'zh-hans': 'zh',
|
||||
}
|
||||
|
||||
# 添加这个配置来排除 API URLs 的语言重定向
|
||||
LOCALE_PATHS = [
|
||||
os.path.join(BASE_DIR, 'locale'),
|
||||
]
|
||||
|
||||
PREFIX_DEFAULT_LANGUAGE = True
|
||||
|
||||
# 修改这里,使用简单的字符串模式而不是 re_path
|
||||
LOCALE_INDEPENDENT_PATHS = [
|
||||
'api/', # 只需要一个简单的字符串前缀
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'core.middleware.CustomLocaleMiddleware', # 使用自定义中间件
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_RENDERER_CLASSES': [
|
||||
'rest_framework.renderers.JSONRenderer',
|
||||
],
|
||||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
||||
'PAGE_SIZE': 10,
|
||||
'UNAUTHENTICATED_USER': None,
|
||||
}
|
||||
|
||||
# Time zone setting
|
||||
TIME_ZONE = 'UTC'
|
||||
USE_TZ = True
|
||||
|
||||
# Celery Configuration
|
||||
CELERY_BROKER_URL = os.environ.get('CELERY_BROKER_URL', 'redis://localhost:6379/0')
|
||||
CELERY_RESULT_BACKEND = os.environ.get('CELERY_RESULT_BACKEND', 'redis://localhost:6379/0')
|
||||
CELERY_ACCEPT_CONTENT = ['json']
|
||||
CELERY_TASK_SERIALIZER = 'json'
|
||||
CELERY_RESULT_SERIALIZER = 'json'
|
||||
CELERY_TIMEZONE = TIME_ZONE # Now TIME_ZONE is defined
|
||||
|
||||
# Celery Beat Schedule
|
||||
CELERY_BEAT_SCHEDULE = {
|
||||
'check-pending-pages': {
|
||||
'task': 'links.tasks.schedule_pending_pages',
|
||||
'schedule': 60.0, # 每60秒运行一次
|
||||
},
|
||||
}
|
||||
|
||||
# Media files configuration
|
||||
MEDIA_URL = '/media/'
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||
|
||||
# Ensure media files are served in all environments
|
||||
SERVE_MEDIA = True
|
||||
@@ -0,0 +1,12 @@
|
||||
module.exports = {
|
||||
content: [
|
||||
'./templates/**/*.html',
|
||||
'./links/templates/**/*.html',
|
||||
'./**/*.js',
|
||||
// 添加其他需要扫描的文件路径
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include, re_path
|
||||
from django.conf.urls.i18n import i18n_patterns
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from links.views import LinkDetailView, LinkUpdateView, CustomLinkView
|
||||
from django.views.static import serve
|
||||
|
||||
urlpatterns = [
|
||||
path('i18n/', include('django.conf.urls.i18n')),
|
||||
path('search/', include('links.search_urls')),
|
||||
path('link/<int:pk>/', LinkDetailView.as_view(), name='link_detail'),
|
||||
path('link/<int:pk>/edit/', LinkUpdateView.as_view(), name='link_update'),
|
||||
path('custom/<slug:alias>/', CustomLinkView.as_view(), name='custom_link'),
|
||||
# Serve media files directly
|
||||
re_path(r'^media/(?P<path>.*)$', serve, {
|
||||
'document_root': settings.MEDIA_ROOT,
|
||||
}),
|
||||
]
|
||||
urlpatterns += i18n_patterns(
|
||||
path('admin/', admin.site.urls),
|
||||
path('', include('links.urls')),
|
||||
)
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
@@ -0,0 +1,6 @@
|
||||
import os
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
Reference in New Issue
Block a user