Skip to content

Commit

Permalink
Trying to test image urls
Browse files Browse the repository at this point in the history
  • Loading branch information
gloryomosomwan committed Dec 9, 2023
1 parent 46c92b8 commit fb65228
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
2 changes: 2 additions & 0 deletions backend/inbox/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 11 additions & 9 deletions backend/node/node_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/'

Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions backend/posts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions backend/posts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 14 additions & 11 deletions frontend/src/pages/MakePost.js
Original file line number Diff line number Diff line change
@@ -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 ");
Expand All @@ -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",
Expand All @@ -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 => {
Expand Down Expand Up @@ -74,16 +75,18 @@ export default function MakePost({ onClose }) {
<button className={visibility === "UNLISTED" ? "selected" : ""} onClick={() => setVisibility("UNLISTED")}>Unlisted</button>
</div>
</div>
<h2>Title</h2>
<input type="text" id="title" name="title" class="single-line-input" maxLength={80} />
<h2>Image URL</h2>
<input type="text" id="image_url" name="image_url" class="single-line-input" maxLength={50} />
{/* <h2>Title</h2>
<input type="text" id="title" name="title" class="single-line-input" maxLength={80} /> */}
<h2>Body</h2>
<textarea id="body" name="body" rows="4" cols="50" class="single-line-input"></textarea>


<br />
<div className="postfooter-container">
<input type="file" accept="image/*" onChange={handleImageUpload} />
<button onClick={() => addPost(document.getElementById("title").value, document.getElementById("body").value)}>Post</button>
<button onClick={() => addPost(document.getElementById("title").value, document.getElementById("body").value, document.getElementById("image_url"))}>Post</button>
</div>


Expand Down

0 comments on commit fb65228

Please sign in to comment.