Skip to content

Commit

Permalink
Merge pull request eee555#54 from putianyi889/patch-39
Browse files Browse the repository at this point in the history
深色模式、状态码、录像上传行为
  • Loading branch information
eee555 authored Jun 29, 2024
2 parents 057a946 + 4744ef2 commit 4b9a230
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 188 deletions.
2 changes: 1 addition & 1 deletion back_end/saolei/userprofile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class UserProfile(AbstractUser):
},)

realname = models.CharField(
max_length=10, unique=False, blank=True, default='请修改为实名', null=False)
max_length=10, unique=False, blank=True, default='匿名', null=False)
# 头像
avatar = RestrictedImageField(upload_to='avatar/%Y%m%d/', max_length=100,
max_upload_size=MaxSizes.avatar, blank=True, null=True)
Expand Down
107 changes: 36 additions & 71 deletions back_end/saolei/videomanager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .models import VideoModel, ExpandVideoModel
from .view_utils import update_personal_record, update_personal_record_stock, video_all_fields
from userprofile.models import UserProfile
from django.http import HttpResponse, JsonResponse, FileResponse
from django.http import HttpResponse, JsonResponse, FileResponse, HttpResponseForbidden, HttpResponseBadRequest, HttpResponseNotAllowed, HttpResponseNotFound
import json, urllib
from utils import ComplexEncoder
from django.core.paginator import Paginator
Expand All @@ -32,9 +32,9 @@
def video_upload(request):
if request.method == 'POST':
if request.user.is_banned:
return JsonResponse({"status": 101, "msg": "用户被封禁!"})
return HttpResponseForbidden() # 用户被封禁
if request.user.userms.video_num_total >= request.user.userms.video_num_limit:
return JsonResponse({"status": 188, "msg": "用户录像仓库已满!"})
return HttpResponse(status = 402) # 录像仓库已满

# response = {'status': 100, 'msg': None}
# request.POST['file'] = request.FILES
Expand All @@ -52,7 +52,7 @@ def video_upload(request):
# 查重
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"]))
if collisions:
return JsonResponse({"status": 200, "msg": "录像已存在"})
return HttpResponse(status = 409)

# 表中添加数据
e_video = ExpandVideoModel.objects.create(designator=data["designator"],
Expand Down Expand Up @@ -101,73 +101,56 @@ def video_upload(request):
# print(review_video_ids)

# update_personal_record(request, data, e_video)
return JsonResponse({"status": 100, "msg": None})
return HttpResponse()
else:
# print(video_form.errors)
return JsonResponse({"status": 666, "msg": "小型网站,请勿攻击!"})
elif request.method == 'GET':
return HttpResponse("别瞎玩")
return HttpResponseBadRequest()
else:
return HttpResponse("别瞎玩")
return HttpResponseNotAllowed()

# 根据id向后台请求软件类型(适配flop播放器用)
def get_software(request):
if request.method != 'GET':
return HttpResponse("别瞎玩")
try:
video = VideoModel.objects.get(id=request.GET["id"])
# print({"status": 100, "msg": video.software})
return JsonResponse({"status": 100, "msg": video.software})
except Exception:
return JsonResponse({"status": 104, "msg": "file not exist!"})
return HttpResponseNotAllowed()
video = VideoModel.objects.get(id=request.GET["id"])
# print({"status": 100, "msg": video.software})
return JsonResponse({"msg": video.software})

# 给预览用的接口,区别是结尾是文件后缀
# 坑:如果做成必须登录才能下载,由于Django的某种特性,会重定向资源,
# 然而flop播放器不能处理此状态码,因此会请求到空文件,导致解码失败
@ratelimit(key='ip', rate='20/m')
def video_preview(request):
if request.method != 'GET':
return HttpResponse("别瞎玩")
return HttpResponseNotAllowed()
# 这里性能可能有问题
try:
video = VideoModel.objects.get(id=int(request.GET["id"][:-4]))
# video.file.name是相对路径(含upload_to),video.file.path是绝对路径
# print(settings.MEDIA_ROOT / "assets" / video.file.name)
file_path = settings.MEDIA_ROOT / video.file.name
response =FileResponse(open(file_path, 'rb'))
response['Content-Type']='application/octet-stream'
# response['Content-Disposition']=f'attachment;filename="{video.file.name.split("/")[2]}"'
file_name = video.file.name.split("/")[2]
file_name_uri = urllib.parse.quote(file_name)
response['Content-Disposition'] = f'attachment; filename="{file_name_uri}"'
response['Access-Control-Expose-Headers']='Content-Disposition'

return response
except Exception:
return JsonResponse({"status": 104, "msg": "file not exist!"})
video = VideoModel.objects.get(id=int(request.GET["id"][:-4]))
# video.file.name是相对路径(含upload_to),video.file.path是绝对路径
# print(settings.MEDIA_ROOT / "assets" / video.file.name)
file_path = settings.MEDIA_ROOT / video.file.name
response =FileResponse(open(file_path, 'rb'))
response['Content-Type']='application/octet-stream'
# response['Content-Disposition']=f'attachment;filename="{video.file.name.split("/")[2]}"'
file_name = video.file.name.split("/")[2]
file_name_uri = urllib.parse.quote(file_name)
response['Content-Disposition'] = f'attachment; filename="{file_name_uri}"'
response['Access-Control-Expose-Headers']='Content-Disposition'
return response

# 给下载用的接口,区别是结尾没有文件后缀
# @login_required(login_url='/')
@ratelimit(key='ip', rate='20/m')
def video_download(request):
if request.method != 'GET':
return HttpResponse("别瞎玩")
return HttpResponseNotAllowed()
try:
video = VideoModel.objects.get(id=request.GET["id"])
response =FileResponse(open(video.file.path, 'rb'))
response['Content-Type']='application/octet-stream'
response['Content-Disposition']=f'attachment;filename="{video.file.name.split("/")[2]}"'
return response
except VideoModel.DoesNotExist:
return JsonResponse({"status": 104, "msg": "录像不存在!"})
# try:
# video = VideoModel.objects.get(id=request.GET["id"])
# response =FileResponse(open(video.file.path, 'rb'))
# response['Content-Type']='application/octet-stream'
# response['Content-Disposition']=f'attachment;filename="{video.file.name.split("/")[2]}"'
# return response
# except Exception:
# return JsonResponse({"status": 104, "msg": "file not exist!"})
return HttpResponseNotFound()

# 录像查询(无需登录)
# 按任何基础指标+难度+模式,排序,分页
Expand Down Expand Up @@ -207,11 +190,8 @@ def video_query(request):
# t=json.dumps(response, cls=ComplexEncoder)
# print(t)
return JsonResponse(json.dumps(response, cls=ComplexEncoder), safe=False)

elif request.method == 'POST':
return HttpResponse("别瞎玩")
else:
return HttpResponse("别瞎玩")
return HttpResponseNotAllowed()


# 按id查询这个用户的所有录像
Expand All @@ -225,22 +205,7 @@ def video_query_by_id(request):

return JsonResponse(json.dumps({"videos": list(videos)}, cls=ComplexEncoder), safe=False)
else:
return HttpResponse("别瞎玩")


# {
# "1": "{\"time\": \"2023-12-16 14:52:40\", \"player\": \"\\u5b9e\\u540d\", \"level\": \"b\", \"mode\": \"00\", \"timems\": \"4770\", \"bv\": 23, \"bvs\": 4.821802935010482}",
# "3": "{\"time\": \"2023-12-16 14:52:52\", \"player\": \"\\u5b9e\\u540d\", \"level\": \"i\", \"mode\": \"00\", \"timems\": \"20390\", \"bv\": 71, \"bvs\": 3.4330554193231975}",
# "4": "{\"time\": \"2023-12-16 15:17:58\", \"player\": \"\\u5b9e\\u540d\", \"level\": \"b\", \"mode\": \"12\", \"timems\": \"1530\", \"bv\": 4, \"bvs\": 2.6143790849673203}",
# "8": "{\"time\": \"2023-12-16 15:26:22\", \"player\": \"www333\", \"level\": \"e\", \"mode\": \"00\", \"timems\": \"51940\", \"bv\": 149, \"bvs\": 2.849441663457836}",
# "9": "{\"time\": \"2023-12-16 15:26:26\", \"player\": \"www333\", \"level\": \"b\", \"mode\": \"00\", \"timems\": \"3250\", \"bv\": 18, \"bvs\": 5.538461538461538}",
# "10": "{\"time\": \"2023-12-16 15:26:30\", \"player\": \"www333\", \"level\": \"i\", \"mode\": \"00\", \"timems\": \"20110\", \"bv\": 69, \"bvs\": 3.431128791645947}",
# "7": "{\"time\": \"2023-12-16 15:24:07\", \"player\": \"\\u5b9e\\u540d\", \"level\": \"i\", \"mode\": \"00\", \"timems\": \"15280\", \"bv\": 31, \"bvs\": 2.0287958115183247}",
# "6": "{\"time\": \"2023-12-16 15:24:02\", \"player\": \"\\u5b9e\\u540d\", \"level\": \"e\", \"mode\": \"00\", \"timems\": \"59450\", \"bv\": 193, \"bvs\": 3.2127838519764507}",
# "2": "{\"time\": \"2023-12-16 14:52:48\", \"player\": \"\\u5b9e\\u540d\", \"level\": \"e\", \"mode\": \"00\", \"timems\": \"61710\", \"bv\": 193, \"bvs\": 3.0789175174201913}",
# "5": "{\"time\": \"2023-12-16 15:23:59\", \"player\": \"\\u5b9e\\u540d\", \"level\": \"b\", \"mode\": \"12\", \"timems\": \"1580\", \"bv\": 6, \"bvs\": 3.7974683544303796}"
# }

return HttpResponseNotAllowed()

# 上传的录像进入数据库后,更新用户的录像数目
def update_video_num(video: VideoModel, add = True):
Expand Down Expand Up @@ -291,7 +256,7 @@ def review_queue(request):
review_video_ids.update({str(key, encoding="utf-8"): review_video_ids.pop(key)})
return JsonResponse(review_video_ids, encoder=ComplexEncoder)
else:
return HttpResponse("别瞎玩")
return HttpResponseNotAllowed()

# 获取最新录像
# http://127.0.0.1:8000/video/newest_queue
Expand All @@ -302,7 +267,7 @@ def newest_queue(request):
newest_queue_ids.update({str(key, encoding="utf-8"): newest_queue_ids.pop(key)})
return JsonResponse(newest_queue_ids, encoder=ComplexEncoder)
else:
return HttpResponse("别瞎玩")
return HttpResponseNotAllowed()


# 获取谁破纪录的消息
Expand All @@ -312,7 +277,7 @@ def news_queue(request):
news_queue = cache.lrange("news_queue", 0, -1)
return JsonResponse(news_queue, encoder=ComplexEncoder, safe=False)
else:
return HttpResponse("别瞎玩")
return HttpResponseNotAllowed()


# 获取全网被冻结的录像
Expand All @@ -324,7 +289,7 @@ def freeze_queue(request):
freeze_queue_ids.update({str(key, encoding="utf-8"): freeze_queue_ids.pop(key)})
return JsonResponse(freeze_queue_ids, encoder=ComplexEncoder)
else:
return HttpResponse("别瞎玩")
return HttpResponseNotAllowed()


# 【管理员】审核通过队列里的录像,未审核或冻结状态的录像可以审核通过
Expand All @@ -337,7 +302,7 @@ def approve(request):
res = []
for _id in ids:
if not isinstance(_id, int):
return HttpResponse("审核录像的id应为正整数。")
return HttpResponseNotFound() # id应为正整数
video_i = VideoModel.objects.filter(id=_id)
if not video_i:
res.append("Null")
Expand Down Expand Up @@ -365,7 +330,7 @@ def approve(request):
# logger.info(f'{request.user.id} approve {json.dumps(ids)} response {json.dumps(res)}')
return JsonResponse(res, safe=False)
else:
return HttpResponse("别瞎玩")
return HttpResponseNotAllowed()

# 【管理员】冻结队列里的录像,未审核或审核通过的录像可以冻结
# 两种用法,冻结指定的录像id,或冻结某用户的所有录像
Expand All @@ -392,7 +357,7 @@ def freeze(request):
res = []
for _id in ids:
if not isinstance(_id, int) or _id < 1:
return HttpResponse("冻结录像的id应为正整数。")
return HttpResponseNotFound() # id应为正整数
video_i = VideoModel.objects.filter(id=_id)
if not video_i:
res.append("Null")
Expand Down Expand Up @@ -424,7 +389,7 @@ def freeze(request):
logger.info(f'{request.user.id} freeze {json.dumps(ids)} response {json.dumps(res)}')
return JsonResponse(json.dumps(res), safe=False)
else:
return HttpResponse("别瞎玩")
return HttpResponseNotAllowed()



Expand Down
2 changes: 2 additions & 0 deletions front_end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"@types/js-cookie": "^3.0.3",
"@types/lowdb": "^1.0.11",
"@types/node": "^20.5.1",
"@vueuse/components": "^10.11.0",
"@vueuse/core": "^10.11.0",
"axios": "^1.7.2",
"echarts": "^5.5.0",
"element-plus": "^2.7.0",
Expand Down
4 changes: 4 additions & 0 deletions front_end/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ import logo_2 from "@/assets/logo2.png";
import { useRouter } from "vue-router";
const router = useRouter();
import { useDark, useToggle } from '@vueuse/core';
const isDark = useDark()
useToggle(isDark)
// const player_visible = ref(false)
const notice_visible = ref(false);
const never_show_notice = ref(false);
Expand Down
25 changes: 9 additions & 16 deletions front_end/src/components/PreviewNumber.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<el-dialog v-model="preview_visible"
style="background-color: rgba(240, 240, 240, 0.48); backdrop-filter: blur(1px);" draggable align-center
destroy-on-close :modal="false" :lock-scroll="false">
<iframe v-if="preview_visible" class="flop-player-iframe flop-player-display-none" style="width: 100%; height: 500px; border: 0px"
src="/flop/index.html" ref="video_iframe"></iframe>
<iframe v-if="preview_visible" class="flop-player-iframe flop-player-display-none"
style="width: 100%; height: 500px; border: 0px" src="/flop/index.html" ref="video_iframe"></iframe>
</el-dialog>
</Teleport>
<span v-if="data.id" @click="preview(data.id);" class="clickable">{{ data.text }}</span>
Expand All @@ -15,8 +15,11 @@
// 某个数字或字符串,点击后预览
import { onMounted, watch, ref, toRefs } from "vue";
import useCurrentInstance from "@/utils/common/useCurrentInstance";
import { generalNotification } from "@/utils/system/status";
import { useI18n } from "vue-i18n";
const { proxy } = useCurrentInstance();
const preview_visible = ref(false);
const t = useI18n();
const data = defineProps({
id: {
Expand Down Expand Up @@ -59,13 +62,9 @@ const preview = (id: Number | undefined) => {
},
}
}
}).catch(
(res) => {
// console.log("报错");
// console.log(res);
}
)
}).catch((error: any) => {
generalNotification(t, error.response.status, t.t('common.action.getSoftware'))
})
}
const playVideo = function (uri: string) {
Expand All @@ -87,13 +86,7 @@ const playVideo = function (uri: string) {
});
}
onMounted(() => {
});
</script>

<style>
</style>
<style></style>
13 changes: 7 additions & 6 deletions front_end/src/components/VideoList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ import { useUserStore } from '@/store';
const store = useUserStore()
import { ms_to_s, approve, freeze, simple_formatter } from '@/utils';
import { generalNotification } from '@/utils/system/status';
import { useI18n } from 'vue-i18n';
const { proxy } = useCurrentInstance();
const t = useI18n();
const data = defineProps({
videos: {
type: Array,
Expand Down Expand Up @@ -142,12 +146,9 @@ const preview = (row: any, column: any, event: Event) => {
},
}
}
}).catch(
(res) => {
// console.log("报错");
// console.log(res);
}
)
}).catch((error: any) => {
generalNotification(t, error.response.status, t.t('common.action.getSoftware'));
})
}
Expand Down
1 change: 1 addition & 0 deletions front_end/src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default createI18n({
fallbackLocale: dev.local,
fallbackWarn: false,
missingWarn: false,
warnHtmlMessage: false,
locale: getDefaultLocale(),
messages: getMessages(),
})
13 changes: 12 additions & 1 deletion front_end/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const en = {
login: 'Login',
logout: 'Logout',
register: 'Register',
setting: 'Settings',
downloads: 'Downloads',
links: 'Links',
team: 'Team'
Expand All @@ -99,7 +100,7 @@ export const en = {
dragOrClick: `Drag files here or <em>click here to select</em>`,
uploadAll: 'Upload All ({0})',
cancelAll: 'Clear All',
constraintNote: '*File size maximum is 5MB. File count maximum is 99.',
constraintNote: '*File size maximum is 5MB.',
error: {
collision: 'Video already exist',
custom: 'Custom level is currently not supported',
Expand All @@ -114,4 +115,14 @@ export const en = {
}
}
},
setting: {
appearance: 'Appearance',
darkMode: 'Dark Mode',
languageSwitch: 'Language Switch',
menuFontSize: 'Menu Font Size',
menuHeight: 'Menu Height',
menuLayout: 'Menu Layout',
menuLayoutAbstract: 'Abstract',
menuLayoutDefault: 'Default',
},
}
Loading

0 comments on commit 4b9a230

Please sign in to comment.