mirror of
https://github.com/AmanTahiliani/PeerNotes.git
synced 2026-08-07 11:55:12 -04:00
Added peer to existing file peers
This commit is contained in:
@@ -5,136 +5,136 @@ from django.db import migrations
|
|||||||
|
|
||||||
def load_data_from_json(apps, schema_editor):
|
def load_data_from_json(apps, schema_editor):
|
||||||
topics = [
|
topics = [
|
||||||
"Introduction to Computer Science",
|
"Introduction to Computer Science",
|
||||||
"Programming Fundamentals",
|
"Programming Fundamentals",
|
||||||
"Data Structures",
|
"Data Structures",
|
||||||
"Algorithms",
|
"Algorithms",
|
||||||
"Computer Architecture",
|
"Computer Architecture",
|
||||||
"Operating Systems",
|
"Operating Systems",
|
||||||
"Database Systems",
|
"Database Systems",
|
||||||
"Networking",
|
"Networking",
|
||||||
"Software Engineering",
|
"Software Engineering",
|
||||||
"Artificial Intelligence",
|
"Artificial Intelligence",
|
||||||
"Theory of Computation",
|
"Theory of Computation",
|
||||||
"Compiler Design",
|
"Compiler Design",
|
||||||
"Distributed Systems",
|
"Distributed Systems",
|
||||||
"Computer Graphics",
|
"Computer Graphics",
|
||||||
"Cryptography",
|
"Cryptography",
|
||||||
"Parallel and Concurrent Programming",
|
"Parallel and Concurrent Programming",
|
||||||
"Human-Computer Interaction",
|
"Human-Computer Interaction",
|
||||||
"Computer Vision",
|
"Computer Vision",
|
||||||
"Web Technologies",
|
"Web Technologies",
|
||||||
"Embedded Systems",
|
"Embedded Systems",
|
||||||
"Data Mining and Analytics",
|
"Data Mining and Analytics",
|
||||||
"Software Quality Assurance",
|
"Software Quality Assurance",
|
||||||
"Ethical and Social Implications of Computing",
|
"Ethical and Social Implications of Computing",
|
||||||
"Advanced Topics",
|
"Advanced Topics",
|
||||||
"Automata Theory",
|
"Automata Theory",
|
||||||
"Formal Languages and Automata",
|
"Formal Languages and Automata",
|
||||||
"Computational Complexity",
|
"Computational Complexity",
|
||||||
"Graph Theory",
|
"Graph Theory",
|
||||||
"Computational Geometry",
|
"Computational Geometry",
|
||||||
"Numerical Analysis",
|
"Numerical Analysis",
|
||||||
"Machine Learning",
|
"Machine Learning",
|
||||||
"Deep Learning",
|
"Deep Learning",
|
||||||
"Natural Language Processing",
|
"Natural Language Processing",
|
||||||
"Reinforcement Learning",
|
"Reinforcement Learning",
|
||||||
"Computer Security",
|
"Computer Security",
|
||||||
"Network Security",
|
"Network Security",
|
||||||
"Information Retrieval",
|
"Information Retrieval",
|
||||||
"Cloud Computing",
|
"Cloud Computing",
|
||||||
"IoT (Internet of Things)",
|
"IoT (Internet of Things)",
|
||||||
"Virtual Reality",
|
"Virtual Reality",
|
||||||
"Augmented Reality",
|
"Augmented Reality",
|
||||||
"Mobile Application Development",
|
"Mobile Application Development",
|
||||||
"Game Development",
|
"Game Development",
|
||||||
"Computer Animation",
|
"Computer Animation",
|
||||||
"Operating System Design",
|
"Operating System Design",
|
||||||
"Real-Time Systems",
|
"Real-Time Systems",
|
||||||
"Concurrency Control",
|
"Concurrency Control",
|
||||||
"Transaction Processing",
|
"Transaction Processing",
|
||||||
"Data Warehousing",
|
"Data Warehousing",
|
||||||
"Big Data Technologies",
|
"Big Data Technologies",
|
||||||
"Data Science",
|
"Data Science",
|
||||||
"Business Intelligence",
|
"Business Intelligence",
|
||||||
"Quantum Computing",
|
"Quantum Computing",
|
||||||
"Bioinformatics",
|
"Bioinformatics",
|
||||||
"Computational Biology",
|
"Computational Biology",
|
||||||
"Robotics",
|
"Robotics",
|
||||||
"Computer Ethics",
|
"Computer Ethics",
|
||||||
"Privacy and Security in Computing",
|
"Privacy and Security in Computing",
|
||||||
"Digital Forensics",
|
"Digital Forensics",
|
||||||
"Cryptocurrency and Blockchain",
|
"Cryptocurrency and Blockchain",
|
||||||
"Social Network Analysis",
|
"Social Network Analysis",
|
||||||
"Cloud Security",
|
"Cloud Security",
|
||||||
"Edge Computing",
|
"Edge Computing",
|
||||||
"Compiler Optimization",
|
"Compiler Optimization",
|
||||||
"High-Performance Computing",
|
"High-Performance Computing",
|
||||||
"Grid Computing",
|
"Grid Computing",
|
||||||
"Fuzzy Logic and Systems",
|
"Fuzzy Logic and Systems",
|
||||||
"Expert Systems",
|
"Expert Systems",
|
||||||
"Pattern Recognition",
|
"Pattern Recognition",
|
||||||
"Knowledge Representation and Reasoning",
|
"Knowledge Representation and Reasoning",
|
||||||
"Semantic Web",
|
"Semantic Web",
|
||||||
"Computer Algebra Systems",
|
"Computer Algebra Systems",
|
||||||
"Geographic Information Systems",
|
"Geographic Information Systems",
|
||||||
"Wireless Sensor Networks",
|
"Wireless Sensor Networks",
|
||||||
"Biometric Authentication",
|
"Biometric Authentication",
|
||||||
"Internet Security Protocols",
|
"Internet Security Protocols",
|
||||||
"Software Testing and Debugging",
|
"Software Testing and Debugging",
|
||||||
"Agile Methodologies",
|
"Agile Methodologies",
|
||||||
"DevOps",
|
"DevOps",
|
||||||
"Continuous Integration and Continuous Deployment (CI/CD)",
|
"Continuous Integration and Continuous Deployment (CI/CD)",
|
||||||
"Model-Driven Engineering",
|
"Model-Driven Engineering",
|
||||||
"User Interface Design",
|
"User Interface Design",
|
||||||
"Accessibility in Computing",
|
"Accessibility in Computing",
|
||||||
"User Experience (UX) Design",
|
"User Experience (UX) Design",
|
||||||
"Game Theory",
|
"Game Theory",
|
||||||
"Social Computing",
|
"Social Computing",
|
||||||
"Computational Sociology",
|
"Computational Sociology",
|
||||||
"Computational Linguistics",
|
"Computational Linguistics",
|
||||||
"Music Information Retrieval",
|
"Music Information Retrieval",
|
||||||
"Ethics in Artificial Intelligence",
|
"Ethics in Artificial Intelligence",
|
||||||
"Algorithmic Game Theory",
|
"Algorithmic Game Theory",
|
||||||
"Behavioral Economics and Computing",
|
"Behavioral Economics and Computing",
|
||||||
"Neuroinformatics",
|
"Neuroinformatics",
|
||||||
"Health Informatics",
|
"Health Informatics",
|
||||||
"Geometric Modeling",
|
"Geometric Modeling",
|
||||||
"Scientific Computing",
|
"Scientific Computing",
|
||||||
"Information Theory",
|
"Information Theory",
|
||||||
"System Modeling and Simulation",
|
"System Modeling and Simulation",
|
||||||
"Decision Support Systems",
|
"Decision Support Systems",
|
||||||
"Database Security and Privacy",
|
"Database Security and Privacy",
|
||||||
"Knowledge Management Systems",
|
"Knowledge Management Systems",
|
||||||
"Information Visualization",
|
"Information Visualization",
|
||||||
"Geospatial Data Analysis",
|
"Geospatial Data Analysis",
|
||||||
"Enterprise Architecture",
|
"Enterprise Architecture",
|
||||||
"Supply Chain Management Systems",
|
"Supply Chain Management Systems",
|
||||||
"Data Integration and Interoperability",
|
"Data Integration and Interoperability",
|
||||||
"Software Reuse and Component-Based Development",
|
"Software Reuse and Component-Based Development",
|
||||||
"Legal and Regulatory Issues in Computing",
|
"Legal and Regulatory Issues in Computing",
|
||||||
"Information Assurance",
|
"Information Assurance",
|
||||||
"Systems Analysis and Design",
|
"Systems Analysis and Design",
|
||||||
"E-commerce Systems",
|
"E-commerce Systems",
|
||||||
"E-learning Systems",
|
"E-learning Systems",
|
||||||
"Human-Robot Interaction",
|
"Human-Robot Interaction",
|
||||||
"Biologically Inspired Computing",
|
"Biologically Inspired Computing",
|
||||||
"Social Robotics",
|
"Social Robotics",
|
||||||
"Humanoid Robotics",
|
"Humanoid Robotics",
|
||||||
"Computational Neuroscience",
|
"Computational Neuroscience",
|
||||||
"Affective Computing",
|
"Affective Computing",
|
||||||
"Explainable AI",
|
"Explainable AI",
|
||||||
"Robot Ethics",
|
"Robot Ethics",
|
||||||
"Cyber-Physical Systems",
|
"Cyber-Physical Systems",
|
||||||
"Internet of Medical Things (IoMT)",
|
"Internet of Medical Things (IoMT)",
|
||||||
"Quantum Information Science",
|
"Quantum Information Science",
|
||||||
"Quantum Cryptography",
|
"Quantum Cryptography",
|
||||||
"Quantum Algorithms",
|
"Quantum Algorithms",
|
||||||
"Quantum Machine Learning",
|
"Quantum Machine Learning",
|
||||||
"Quantum Error Correction",
|
"Quantum Error Correction",
|
||||||
"Quantum Networking"
|
"Quantum Networking",
|
||||||
]
|
]
|
||||||
|
|
||||||
Topic = apps.get_model("api", "Topic")
|
Topic = apps.get_model("api", "Topic")
|
||||||
Topic.objects.all().delete()
|
Topic.objects.all().delete()
|
||||||
for topic in topics:
|
for topic in topics:
|
||||||
@@ -145,6 +145,7 @@ def load_data_from_json(apps, schema_editor):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Error:", str(e))
|
print("Error:", str(e))
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
@@ -64,6 +64,11 @@ urlpatterns = [
|
|||||||
views.DownvoteFile.as_view(),
|
views.DownvoteFile.as_view(),
|
||||||
name="downvote-file",
|
name="downvote-file",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"api/files/<int:file_id>/add-peer/",
|
||||||
|
views.AddPeerToFile.as_view(),
|
||||||
|
name="add-peer",
|
||||||
|
),
|
||||||
path("api/files/<int:pk>/", views.FileDetailAPIView.as_view(), name="file-detail"),
|
path("api/files/<int:pk>/", views.FileDetailAPIView.as_view(), name="file-detail"),
|
||||||
path("api/report_user/", views.ReportUserView.as_view(), name="report-user"),
|
path("api/report_user/", views.ReportUserView.as_view(), name="report-user"),
|
||||||
path("api/register/", views.RegisterFile.as_view(), name="file-register"),
|
path("api/register/", views.RegisterFile.as_view(), name="file-register"),
|
||||||
|
|||||||
@@ -235,6 +235,31 @@ class RegisterFile(APIView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AddPeerToFile(APIView):
|
||||||
|
authentication_classes = [TokenAuthentication]
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
|
def post(self, request, file_id):
|
||||||
|
try:
|
||||||
|
user = request.user
|
||||||
|
file = File.objects.get(id=file_id)
|
||||||
|
print("File fetched")
|
||||||
|
print(file)
|
||||||
|
print(file.peer_users)
|
||||||
|
if not file.peer_users.filter(id=user.id).exists():
|
||||||
|
file.peer_users.add(user)
|
||||||
|
file.save()
|
||||||
|
return Response(
|
||||||
|
f"User added to file with id {file.id}", status=status.HTTP_200_OK
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error occured while adding peer to file: {e}")
|
||||||
|
return Response(
|
||||||
|
"Unable to register peer to given file id",
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class FileFilterView(APIView):
|
class FileFilterView(APIView):
|
||||||
authentication_classes = [TokenAuthentication]
|
authentication_classes = [TokenAuthentication]
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
@@ -282,7 +307,6 @@ class FileFilterView(APIView):
|
|||||||
queryset = queryset.filter(course__id=course_id)
|
queryset = queryset.filter(course__id=course_id)
|
||||||
if semester_id:
|
if semester_id:
|
||||||
queryset = queryset.filter(semester__id=semester_id)
|
queryset = queryset.filter(semester__id=semester_id)
|
||||||
|
|
||||||
|
|
||||||
queryset = queryset.annotate(
|
queryset = queryset.annotate(
|
||||||
upvote_count=Count("upvotes"), downvote_count=Count("downvotes")
|
upvote_count=Count("upvotes"), downvote_count=Count("downvotes")
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ def copy_file():
|
|||||||
print(id)
|
print(id)
|
||||||
if "file" not in files:
|
if "file" not in files:
|
||||||
return "File must be sent in request", 400
|
return "File must be sent in request", 400
|
||||||
file = request.files['file']
|
file = request.files["file"]
|
||||||
filename = file.filename.replace(" ", "_")
|
filename = file.filename.replace(" ", "_")
|
||||||
# id = data["file_id"]
|
# id = data["file_id"]
|
||||||
# if not os.path.exists(source_file):
|
# if not os.path.exists(source_file):
|
||||||
@@ -93,6 +93,7 @@ def request_file():
|
|||||||
print("Error:", error)
|
print("Error:", error)
|
||||||
return error, response.status_code
|
return error, response.status_code
|
||||||
|
|
||||||
|
|
||||||
@app.route("/files", methods=["GET"])
|
@app.route("/files", methods=["GET"])
|
||||||
def list_files():
|
def list_files():
|
||||||
files = os.listdir("./uploads")
|
files = os.listdir("./uploads")
|
||||||
@@ -101,6 +102,7 @@ def list_files():
|
|||||||
newFiles.append("_".join(file.split("_", 1)[1:]))
|
newFiles.append("_".join(file.split("_", 1)[1:]))
|
||||||
return {"files": newFiles}, 200
|
return {"files": newFiles}, 200
|
||||||
|
|
||||||
|
|
||||||
@app.route("/request-tests", methods=["GET"])
|
@app.route("/request-tests", methods=["GET"])
|
||||||
def request_test_():
|
def request_test_():
|
||||||
data = request.json
|
data = request.json
|
||||||
|
|||||||
30
test1.py
30
test1.py
@@ -2,39 +2,43 @@ import requests
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
def request_tests():
|
def request_tests():
|
||||||
url = "http://localhost:8080/request-tests"
|
url = "http://localhost:8080/request-tests"
|
||||||
downloaded_files = []
|
downloaded_files = []
|
||||||
print("past url")
|
print("past url")
|
||||||
for i in range(100):
|
for i in range(100):
|
||||||
filename = f"TestFileTransfer.pdf"
|
filename = f"TestFileTransfer.pdf"
|
||||||
|
|
||||||
payload = json.dumps({
|
payload = json.dumps(
|
||||||
"id": 5,
|
{
|
||||||
"filename": filename,
|
"id": 5,
|
||||||
"ip": "143.215.87.54",
|
"filename": filename,
|
||||||
"new_filename":f"TestFileTransfer_{i}.pdf"
|
"ip": "143.215.87.54",
|
||||||
})
|
"new_filename": f"TestFileTransfer_{i}.pdf",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'Content-Type': 'application/json',
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.get(url, headers=headers, data=payload)
|
response = requests.get(url, headers=headers, data=payload)
|
||||||
print("response received")
|
print("response received")
|
||||||
print(payload)
|
print(payload)
|
||||||
print(response)
|
print(response)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
print(f"Request {i+1} successful")
|
print(f"Request {i+1} successful")
|
||||||
downloaded_files.append(f"bcdef_{i}.txt")
|
downloaded_files.append(f"bcdef_{i}.txt")
|
||||||
else:
|
else:
|
||||||
print(f"Request {i+1} failed with status code {response.status_code}")
|
print(f"Request {i+1} failed with status code {response.status_code}")
|
||||||
|
|
||||||
if downloaded_files:
|
if downloaded_files:
|
||||||
file_paths = ', '.join(['./uploads/' + file for file in downloaded_files])
|
file_paths = ", ".join(["./uploads/" + file for file in downloaded_files])
|
||||||
return f"1000 files have been downloaded to {file_paths}", 200
|
return f"1000 files have been downloaded to {file_paths}", 200
|
||||||
else:
|
else:
|
||||||
return "No files downloaded", 200
|
return "No files downloaded", 200
|
||||||
|
|
||||||
request_tests()
|
|
||||||
|
request_tests()
|
||||||
|
|||||||
Reference in New Issue
Block a user