Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Dev into patch-59 #7

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ front_end/public/flopold
front_end/src/assets/article
front_end/package-lock.json
front_end/yarn.lock
/back_end/saolei/designator/migrations
/back_end/saolei/identifier/migrations
/back_end/saolei/userprofile/migrations
/back_end/saolei/videomanager/migrations
/back_end/saolei/msuser/migrations


8 changes: 0 additions & 8 deletions back_end/saolei/designator/urls.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.apps import AppConfig


class DesignatorConfig(AppConfig):
class IdentifierConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "designator"
name = "identifier"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import models
from msuser.models import UserMS

class Designator(models.Model):
designator = models.CharField(max_length=128, unique=True)
class Identifier(models.Model):
identifier = models.CharField(max_length=128, unique=True)
userms = models.ForeignKey(UserMS, null=True, on_delete=models.CASCADE, db_index=True)
safe = models.BooleanField(default=False)
8 changes: 8 additions & 0 deletions back_end/saolei/identifier/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path

from . import views
app_name = 'identifier'
urlpatterns = [
path('del/', views.del_identifier),
path('add/', views.add_identifier),
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from videomanager.view_utils import update_personal_record_stock, update_state
from utils import verify_text

from .models import Designator
from .models import Identifier

# 审查标识
# 若未记录该标识则创建条目
def verify_designator(designator: str):
collision = Designator.objects.filter(designator=designator).first()
def verify_identifier(identifier: str):
collision = Identifier.objects.filter(identifier=identifier).first()
if collision:
return collision.safe
new_designator = Designator.objects.create(designator=designator, safe=verify_text(designator))
return new_designator.safe
new_identifier = Identifier.objects.create(identifier=identifier, safe=verify_text(identifier))
return new_identifier.safe
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from msuser.models import UserMS
from .models import Designator
from .models import Identifier
from userprofile.models import UserProfile
from django.http import HttpResponseNotAllowed, HttpResponseForbidden, HttpResponseBadRequest, JsonResponse, HttpResponse, HttpResponseNotFound
from django.views.decorators.http import require_GET, require_POST
Expand All @@ -9,68 +9,68 @@

# 请求修改自己的标识
@require_POST
def add_designator(request):
def add_identifier(request):
user = UserProfile.objects.filter(id=request.user.id).first()
if user == None:
return HttpResponseForbidden()
designator_text = request.POST.get('designator')
if designator_text == None:
identifier_text = request.POST.get('identifier')
if identifier_text == None:
return HttpResponseBadRequest()

designator = Designator.objects.filter(designator=designator_text).first()
if not designator or not designator.safe:
return JsonResponse({'type': 'error', 'object': 'designator', 'category': 'notFound'})
if designator.userms:
designator_user = designator.userms.parent
if designator_user.id == user.id:
identifier = Identifier.objects.filter(identifier=identifier_text).first()
if not identifier or not identifier.safe:
return JsonResponse({'type': 'error', 'object': 'identifier', 'category': 'notFound'})
if identifier.userms:
identifier_user = identifier.userms.parent
if identifier_user.id == user.id:
return HttpResponseConflict() # 本人已有该标识
return JsonResponse({'type': 'error', 'object': 'designator', 'category': 'conflict', 'value': designator_user.id}) # 返回标识冲突的用户
video_list = VideoModel.objects.filter(player=user, video__designator=designator_text)
return JsonResponse({'type': 'error', 'object': 'identifier', 'category': 'conflict', 'value': identifier_user.id}) # 返回标识冲突的用户
video_list = VideoModel.objects.filter(player=user, video__identifier=identifier_text)
if not video_list:
return JsonResponse({'type': 'error', 'object': 'designator', 'category': 'notFound'})
return JsonResponse({'type': 'error', 'object': 'identifier', 'category': 'notFound'})
for video in video_list:
if video.state == VideoModel.State.DESIGNATOR:
if video.state == VideoModel.State.IDENTIFIER:
update_state(video, VideoModel.State.OFFICIAL)
designator.userms = user.userms
designator.save()
user.userms.designators.append(designator_text)
identifier.userms = user.userms
identifier.save()
user.userms.identifiers.append(identifier_text)
user.userms.save()
# TODO: 日志
return JsonResponse({'type': 'success', 'object': 'designator', 'category': 'add', 'value': len(video_list)})
return JsonResponse({'type': 'success', 'object': 'identifier', 'category': 'add', 'value': len(video_list)})

# 请求删除自己的标识
@require_POST
def del_designator(request):
def del_identifier(request):
user = UserProfile.objects.filter(id=request.user.id).first()
if user == None:
return HttpResponseForbidden()
designator_text = request.POST.get('designator', None)
if designator_text == None:
identifier_text = request.POST.get('identifier', None)
if identifier_text == None:
return HttpResponseBadRequest()
designator = Designator.objects.filter(designator=designator_text).first()
if not designator:
identifier = Identifier.objects.filter(identifier=identifier_text).first()
if not identifier:
return HttpResponseNotFound()
if designator.userms.parent.id != user.id:
if identifier.userms.parent.id != user.id:
return HttpResponseForbidden()
designator.userms = None
designator.save()
user.userms.designators.remove(designator_text)
identifier.userms = None
identifier.save()
user.userms.identifiers.remove(identifier_text)
user.userms.save()
# TODO: 日志
video_list = VideoModel.objects.filter(player=user, video__designator=designator_text)
video_list = VideoModel.objects.filter(player=user, video__identifier=identifier_text)
for video in video_list:
if video.state == VideoModel.State.OFFICIAL:
update_state(video, VideoModel.State.DESIGNATOR, update_ranking=False)
update_state(video, VideoModel.State.IDENTIFIER, update_ranking=False)
if video_list:
update_personal_record_stock(user)
return JsonResponse({'type': 'success', 'object': 'designator', 'category': 'add', 'value': len(video_list)})
return JsonResponse({'type': 'success', 'object': 'identifier', 'category': 'add', 'value': len(video_list)})

# 管理员添加标识
def staff_add_designator(request):
def staff_add_identifier(request):
# TODO
return HttpResponse()

# 管理员删除标识
def staff_del_designator(request):
def staff_del_identifier(request):
# TODO
return HttpResponse()
4 changes: 2 additions & 2 deletions back_end/saolei/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def main():
# 1,[email protected],123456
# pip install django-simple-captcha
# python manage.py makemigrations --empty msuser
# ALTER TABLE videomanager_expandvideomodel CHANGE designator identifier varchar(255);
# ALTER TABLE msuser_userms CHANGE designators identifiers json;
# ALTER TABLE videomanager_expandvideomodel CHANGE identifier identifier varchar(255);
# ALTER TABLE msuser_userms CHANGE identifiers identifiers json;



Expand Down
2 changes: 1 addition & 1 deletion back_end/saolei/msuser/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
path('update_avatar/', views.update_avatar, name='update_avatar'),
path('update_signature/', views.update_signature, name='update_signature'),
path('player_rank/', views.player_rank, name='player_rank'),
path('designators/', views.get_designators, name='designators'),
path('identifiers/', views.get_identifiers, name='identifiers'),
]
4 changes: 2 additions & 2 deletions back_end/saolei/msuser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def get_info_abstract(request):
else:
return HttpResponse("别瞎玩")

def get_designators(request):
def get_identifiers(request):
if request.method != 'GET':
return HttpResponseNotAllowed()
id = request.GET.get('id')
Expand All @@ -143,7 +143,7 @@ def get_designators(request):
user = UserProfile.objects.filter(id=id).first()
if not user:
return HttpResponseNotFound()
return JsonResponse(user.userms.designators, safe=False)
return JsonResponse(user.userms.identifiers, safe=False)

# 上传或更新我的地盘里的头像、姓名、个性签名
# 应该写到用户的app里,而不是玩家
Expand Down
2 changes: 1 addition & 1 deletion back_end/saolei/saolei/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
'msuser',
'article',
"ranking",
'designator',
'identifier',
"monitor",
'django_cleanup.apps.CleanupConfig', # 必须放在最后(文档所言)
]
Expand Down
2 changes: 1 addition & 1 deletion back_end/saolei/saolei/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
path('msuser/', include('msuser.urls')),
path('monitor/', include('monitor.urls')),
path('article/', include('article.urls')),
path('designator/', include('designator.urls')),
path('identifier/', include('identifier.urls')),
path(r'', TemplateView.as_view(template_name="index.html")),
]

Expand Down
4 changes: 2 additions & 2 deletions back_end/saolei/videomanager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class State(models.TextChoices):
PLAIN = "a", ('已上传但未审核')
FROZEN = "b", ('审核未通过,被冻结')
OFFICIAL = "c", ('已通过审核')
DESIGNATOR = "d", ('标识不匹配')
IDENTIFIER = "d", ('标识不匹配')

class Level(models.TextChoices):
BEGINNER = "b", ('初级')
Expand Down Expand Up @@ -159,7 +159,7 @@ def push_redis(self, name: str):
"timems": self.timems,
"bv": self.bv,
"bvs": self.bvs,
"designator": self.video.designator}, cls=ComplexEncoder))
"identifier": self.video.identifier}, cls=ComplexEncoder))

def pop_redis(self, name: str):
cache.hdel(name, self.id)
Expand Down
4 changes: 2 additions & 2 deletions back_end/saolei/videomanager/view_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
state2redis = {
VideoModel.State.PLAIN: 'review_queue',
VideoModel.State.FROZEN: 'freeze_queue',
VideoModel.State.DESIGNATOR: 'newest_queue',
VideoModel.State.IDENTIFIER: 'newest_queue',
VideoModel.State.OFFICIAL: 'newest_queue',
}

Expand Down Expand Up @@ -203,7 +203,7 @@ def update_state(video: VideoModel, state: VideoModel.State, update_ranking = Tr

def new_video(data, user):
e_video = ExpandVideoModel.objects.create(
designator=data["designator"],
identifier=data["identifier"],
left=data["left"],
right=data["right"],
double=data["double"],
Expand Down
12 changes: 6 additions & 6 deletions back_end/saolei/videomanager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from django.utils import timezone
# import ms_toollib as ms
from django.conf import settings
from designator.utils import verify_designator
from identifier.utils import verify_identifier
from django.views.decorators.http import require_GET, require_POST

@login_required(login_url='/')
Expand All @@ -42,14 +42,14 @@ def video_upload(request):
if not video_form.is_valid():
return HttpResponseBadRequest()
data = video_form.cleaned_data
designator = data["designator"]
if not verify_designator(designator): # 标识不过审
return JsonResponse({'type': 'error', 'object': 'designator', 'category': 'censorship'})
if data['review_code'] == 0 and designator not in request.user.userms.designators:
identifier = data["identifier"]
if not verify_identifier(identifier): # 标识不过审
return JsonResponse({'type': 'error', 'object': 'identifier', 'category': 'censorship'})
if data['review_code'] == 0 and identifier not in request.user.userms.identifiers:
data['review_code'] = 2 # 标识不匹配

# 查重
collisions = list(VideoModel.objects.filter(timems=data["timems"], bv=data["bv"]).filter(video__cl=data["cl"], video__op=data["op"], video__isl=data["isl"], video__designator=data["designator"]))
collisions = list(VideoModel.objects.filter(timems=data["timems"], bv=data["bv"]).filter(video__cl=data["cl"], video__op=data["op"], video__isl=data["isl"], video__identifier=data["identifier"]))
if collisions:
return JsonResponse({'type': 'error', 'object': 'videomodel', 'category': 'conflict'})
new_video(data, request.user) # 表中添加数据
Expand Down
Loading