diff --git a/Server01/__pycache__/models.cpython-39.pyc b/Server01/__pycache__/models.cpython-39.pyc index 15d356a..d2d2d24 100644 Binary files a/Server01/__pycache__/models.cpython-39.pyc and b/Server01/__pycache__/models.cpython-39.pyc differ diff --git a/Server01/models.py b/Server01/models.py index ae428ae..e17b2af 100644 --- a/Server01/models.py +++ b/Server01/models.py @@ -32,7 +32,7 @@ def delete(self, *args, **kwargs): self.imgs.all().delete() # 删除帖子的图片的存储 path = SYSTEM_PATH + 'post/' - check_and_delete(path, self.id) + check_and_delete(mainPath=path, id=self.id) # 删除帖子本身 super().delete(*args, **kwargs) diff --git "a/Server01/static/img/post/14-\351\207\221\346\231\272\347\247\200.jpg" "b/Server01/static/img/post/14-\351\207\221\346\231\272\347\247\200.jpg" deleted file mode 100644 index 81c2c29..0000000 Binary files "a/Server01/static/img/post/14-\351\207\221\346\231\272\347\247\200.jpg" and /dev/null differ diff --git a/Server01/static/img/post/23-img4.jpg b/Server01/static/img/post/23-img4.jpg deleted file mode 100644 index a7a0d2d..0000000 Binary files a/Server01/static/img/post/23-img4.jpg and /dev/null differ diff --git a/Server01/static/img/post/28-img3.jpg b/Server01/static/img/post/28-img3.jpg deleted file mode 100644 index 4163639..0000000 Binary files a/Server01/static/img/post/28-img3.jpg and /dev/null differ diff --git "a/Server01/static/img/post/34-\345\274\240\345\250\234\350\213\261.jpg" "b/Server01/static/img/post/34-\345\274\240\345\250\234\350\213\261.jpg" deleted file mode 100644 index 8ebbfc2..0000000 Binary files "a/Server01/static/img/post/34-\345\274\240\345\250\234\350\213\261.jpg" and /dev/null differ diff --git a/Server01/static/img/post/35-search.png b/Server01/static/img/post/35-search.png deleted file mode 100644 index 1b7b14f..0000000 Binary files a/Server01/static/img/post/35-search.png and /dev/null differ diff --git "a/Server01/static/img/post/36-\346\261\240\347\247\200\345\252\233.jpg" "b/Server01/static/img/post/36-\346\261\240\347\247\200\345\252\233.jpg" deleted file mode 100644 index a77b691..0000000 Binary files "a/Server01/static/img/post/36-\346\261\240\347\247\200\345\252\233.jpg" and /dev/null differ diff --git a/Server01/static/img/post/37-02.jpg b/Server01/static/img/post/37-02.jpg deleted file mode 100644 index b5e7bfd..0000000 Binary files a/Server01/static/img/post/37-02.jpg and /dev/null differ diff --git a/Server01/static/img/post/38-01.jpg b/Server01/static/img/post/38-01.jpg deleted file mode 100644 index 1ef271c..0000000 Binary files a/Server01/static/img/post/38-01.jpg and /dev/null differ diff --git a/Server01/static/img/post/39-03.gif b/Server01/static/img/post/39-03.gif deleted file mode 100644 index 142c7d7..0000000 Binary files a/Server01/static/img/post/39-03.gif and /dev/null differ diff --git a/Server01/util/__pycache__/auxiliaryFuction.cpython-39.pyc b/Server01/util/__pycache__/auxiliaryFuction.cpython-39.pyc index a2fbc21..d257264 100644 Binary files a/Server01/util/__pycache__/auxiliaryFuction.cpython-39.pyc and b/Server01/util/__pycache__/auxiliaryFuction.cpython-39.pyc differ diff --git a/Server01/util/auxiliaryFuction.py b/Server01/util/auxiliaryFuction.py index 0c65a68..3beceb7 100644 --- a/Server01/util/auxiliaryFuction.py +++ b/Server01/util/auxiliaryFuction.py @@ -35,7 +35,7 @@ def combine_index_post(posts): # 检查和删除图片,用于删除帖子时删除文件,以及删除用户上一次上传的头像 -def check_and_delete(id, mainPath): +def check_and_delete(*, id, mainPath): # 获取目录下的文件 file_list = os.listdir(mainPath) # 遍历文件列表,检查是否有对应的文件,如果有就删除 diff --git a/Server01/views/__pycache__/post.cpython-39.pyc b/Server01/views/__pycache__/post.cpython-39.pyc index c798fdb..4971993 100644 Binary files a/Server01/views/__pycache__/post.cpython-39.pyc and b/Server01/views/__pycache__/post.cpython-39.pyc differ diff --git a/Server01/views/__pycache__/user.cpython-39.pyc b/Server01/views/__pycache__/user.cpython-39.pyc index cdfc069..d2ec179 100644 Binary files a/Server01/views/__pycache__/user.cpython-39.pyc and b/Server01/views/__pycache__/user.cpython-39.pyc differ diff --git a/Server01/views/post.py b/Server01/views/post.py index ea64b14..1f9cd60 100644 --- a/Server01/views/post.py +++ b/Server01/views/post.py @@ -60,6 +60,7 @@ def get_post_detail(request): 'likeCount': post.favoritePosts.all().count(), 'collectCount': post.collectedPosts.all().count(), 'commentCount': post.comments.all().count(), + 'content': post.content } return JsonResponse({'info': info}, status=200) return JsonResponse({'error': '错误的访问'}, status=404) @@ -108,3 +109,14 @@ def control_like_collect(request, payload): user.collected.remove(post) return JsonResponse({'info': '成功取消收藏'}, status=200) return JsonResponse({'error': '错误的操作'}, status=404) + + +@authenticate_request +def post_delete(request, payload): + data = json.loads(request.body) + id = data['id'] + post = models.Post.objects.filter(id=id).first() + if post.user.id == payload['user_id']: + post.delete() + return JsonResponse({'success': '帖子删除成功'}, status=200) + return JsonResponse({'error': '错误操作'}, status=404) \ No newline at end of file diff --git a/Server01/views/user.py b/Server01/views/user.py index 63a773a..895ad6c 100644 --- a/Server01/views/user.py +++ b/Server01/views/user.py @@ -3,9 +3,10 @@ from django.http import JsonResponse import Server01.models as models -from Server01.util.auxiliaryFuction import check_email, combine_index_post, check_and_delete, filter_querySet +from Server01.util.auxiliaryFuction import check_email, combine_index_post, check_and_delete, filter_querySet, \ + convert_to_timezone from Server01.util.verifyJWT import create_token, authenticate_request -from webServer.settings import SYSTEM_PATH +from webServer.settings import SYSTEM_PATH, TIME_ZONE # 用户登录 @@ -145,7 +146,7 @@ def update_avatar(request, payload): file = request.FILES['file'] id = payload['user_id'] file_path = SYSTEM_PATH + 'avatar/' + str(id) + '-' + file.name - check_and_delete(id, SYSTEM_PATH + 'avatar/') + check_and_delete(id=id, mainPath=SYSTEM_PATH + 'avatar/') with open(file_path, 'wb') as destination: for chunk in file.chunks(): destination.write(chunk) @@ -157,3 +158,22 @@ def update_avatar(request, payload): user.avatar = 'http://localhost:8000/static/img/avatar/' + str(id) + '-' + file.name user.save() return JsonResponse({'info': result}, status=200) + + +@authenticate_request +def user_post_control_index(request, payload): + user_id = payload['user_id'] + user = models.User.objects.filter(id=user_id).first() + if user: + user_post = user.posts.all() + info = [{ + 'date': convert_to_timezone(post.created_at, TIME_ZONE), + 'title': post.title, + 'likeCount': post.favoritePosts.all().count(), + 'collectCount': post.collectedPosts.all().count(), + 'commentCount': post.comments.all().count(), + 'content': post.content, + 'id': post.id + } for post in user_post if post] + return JsonResponse({'info': info}, status=200) + return JsonResponse({'error': '错误的操作'}, status=404) \ No newline at end of file diff --git a/webServer/__pycache__/settings.cpython-39.pyc b/webServer/__pycache__/settings.cpython-39.pyc index 931433d..16061ff 100644 Binary files a/webServer/__pycache__/settings.cpython-39.pyc and b/webServer/__pycache__/settings.cpython-39.pyc differ diff --git a/webServer/__pycache__/urls.cpython-39.pyc b/webServer/__pycache__/urls.cpython-39.pyc index 0018f49..4aa858a 100644 Binary files a/webServer/__pycache__/urls.cpython-39.pyc and b/webServer/__pycache__/urls.cpython-39.pyc differ diff --git a/webServer/urls.py b/webServer/urls.py index 04aa2dd..b70bf1e 100644 --- a/webServer/urls.py +++ b/webServer/urls.py @@ -29,12 +29,14 @@ path('user/update/', user.update_user_info), path('user/avatar/', user.update_avatar), path('user/post/', user.query_user_index_post), + path('user/post/control/', user.user_post_control_index), # 帖子相关 path('upload/', post.upload_post), path('upload/info/', post.upload_post_info), path('post/detail/', post.get_post_detail), path('post/', post.query_post_index), path('post/control/', post.control_like_collect), + path('post/delete/', post.post_delete), # 评论相关 path('comment/', comment.do_comment), path('comment/main/', comment.get_comment)