From fb6522895586ba640d1e86f27e2865b19d5e65b7 Mon Sep 17 00:00:00 2001 From: Glory Omosomwan <80617508+asvpglory@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:27:08 -0700 Subject: [PATCH] Trying to test image urls --- backend/inbox/views.py | 2 ++ backend/node/node_functions.py | 20 +++++++++++--------- backend/posts/models.py | 1 + backend/posts/serializers.py | 1 + frontend/src/pages/MakePost.js | 25 ++++++++++++++----------- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/backend/inbox/views.py b/backend/inbox/views.py index 290825d..b9c96a6 100644 --- a/backend/inbox/views.py +++ b/backend/inbox/views.py @@ -136,7 +136,9 @@ def _add_follow_request_to_inbox(self, follow_data, inbox): inbox.follow_request.add(follow_request) # print("Follow request added to inbox", inbox) + print("Object...", identify_localauthor(object)) if not identify_localauthor(object): + print("identifying local...", object) send_request_to_remoteInbox(follow_request, object) return Response({"detail": "Follow request added to inbox"}, status=status.HTTP_201_CREATED) diff --git a/backend/node/node_functions.py b/backend/node/node_functions.py index 07ecffa..5d26b9a 100644 --- a/backend/node/node_functions.py +++ b/backend/node/node_functions.py @@ -165,16 +165,18 @@ def identify_localauthor(author: AppUser): """ will tell u if user is a local author """ - return author.host in LOCALHOSTS + return author.isForeign == False def send_request_to_remoteInbox(follow_request: FriendRequest, object: AppUser): - print('am here for rmeote requests') - try: - node = Node.objects.get(host=object.host) - except: - print(f"[ERROR]: no node for user {object.displayName, object.url }") - return + print('am here for rmeote requests', object.host) + # try: + # node = Node.objects.get(host=object.host) + # except: + # print(f"[ERROR]: no node for user {object.displayName, object.url }") + # return + username = "admin" + password = "admin" base, author_id = object.url.rsplit('authors', 1) request_url = f'{base}service/authors{author_id}/inbox/' @@ -184,12 +186,12 @@ def send_request_to_remoteInbox(follow_request: FriendRequest, object: AppUser): print('friend remote request data', friendReqData_toSend) try: response = requests.post( - request_url, json=friendReqData_toSend, auth=(node.username, node.password)) + request_url, json=friendReqData_toSend, auth=(username, password)) print('status code response', response.status_code) if response.status_code == 200: print('succeeded sent friend requests') except requests.exceptions.RequestException as e: - print(f"couldnt sent friend request to remote inbox{node.host}: {e}") + print(f"couldnt sent friend request to remote inbox: {e}") def send_remoteUser(user: AppUser): diff --git a/backend/posts/models.py b/backend/posts/models.py index bff05f0..71fba59 100644 --- a/backend/posts/models.py +++ b/backend/posts/models.py @@ -38,6 +38,7 @@ class Post(models.Model): visibility = models.CharField(max_length=100, default='PUBLIC') unlisted = models.BooleanField() url = models.URLField(max_length=500, editable=False, null=True) + image_url = models.URLField(max_length=500, editable=False, null=True) # comments = models.URLField(max_length=500,editable=False,default=str(url) + '/comments') def save(self, *args, **kwargs): diff --git a/backend/posts/serializers.py b/backend/posts/serializers.py index 64a82d5..38dd05e 100644 --- a/backend/posts/serializers.py +++ b/backend/posts/serializers.py @@ -80,6 +80,7 @@ def update(self, instance, validated_data): instance.visibility = validated_data.get( 'visibility', instance.visibility) instance.unlisted = validated_data.get('unlisted', instance.unlisted) + instance.image_url = validated_data.get('image_url', instance.image_url) instance.save() return instance diff --git a/frontend/src/pages/MakePost.js b/frontend/src/pages/MakePost.js index 6e82da7..0244bac 100644 --- a/frontend/src/pages/MakePost.js +++ b/frontend/src/pages/MakePost.js @@ -1,14 +1,14 @@ -import React, { useState} from "react"; +import React, { useState } from "react"; import "../css/MakePost.css"; import axiosInstance from "../axiosInstance"; export default function MakePost({ onClose }) { - const [visibility, setVisibility] = useState("PUBLIC") + const [visibility, setVisibility] = useState("PUBLIC"); const storedUser_val = JSON.parse(localStorage.getItem('user')); - const storedUser = storedUser_val.user - const userId = storedUser.id.split("/").pop() - const addPost = (title, body) => { + const storedUser = storedUser_val.user; + const userId = storedUser.id.split("/").pop(); + const addPost = (title, body, image_url) => { // TODO: add POST to backend here if (title === "") { alert("Please add a title to your post "); @@ -18,7 +18,7 @@ export default function MakePost({ onClose }) { // TODO: add author details, etc. here - const url = "authors/" + userId + "/posts/" + const url = "authors/" + userId + "/posts/"; const postSent = { type: "post", @@ -28,9 +28,10 @@ export default function MakePost({ onClose }) { content: body ? body : null, visibility: visibility, unlisted: false, - } + image_url: image_url + }; - console.log('post dataa', postSent) + console.log('post dataa', postSent); axiosInstance.post(url, postSent).then(response => { console.log('post created', response); }).catch(error => { @@ -74,8 +75,10 @@ export default function MakePost({ onClose }) { -