Skip to content

Commit

Permalink
Merge pull request #53 from kochamaltki/image-support
Browse files Browse the repository at this point in the history
Image support
  • Loading branch information
Dromader2137 authored Apr 6, 2024
2 parents a9119bf + 587a1c5 commit 543cfc1
Show file tree
Hide file tree
Showing 19 changed files with 625 additions and 283 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ projekt-db
SECRET
/media/backround/*
/media/profile_pictures/*
/media/images/*
!/media/backround/default.*
!/media/profile_pictures/default.*
!/media/profile_pictures/default.*
!/media/images/default.*
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@
- Get: 200 (Profile) / 404 ("User not found")
- Note: Get user profile
#### /api/get/likes/from-post/{id}
- Get: 200 (LikeCountMap) / 404 ("Post not found")
- Get: 200 (LikeCount) / 404 ("Post not found")
- Note: Get (like, count) map from post {id}
#### /api/get/images/from-post/{id}
- Get: 200 (ImageList) / 404 ("Post not found")
- Note: Get a list of image names used to acces them via the call below
#### /api/get/image/{image-name}
- Get: Image
#### /api/post/add-post
- Post: PostCreateRequest
- Effect: Adds a post to the db
Expand Down Expand Up @@ -79,7 +84,8 @@
- Headers: 'Content-Type: application/json' 'Content-Type: text/plain'
#### /api/post/upload/image
- Post: Image (max 25MB)
- ALPHA FEATURE DO NOT USE
- Return: 200 (image-id) / 400 ("Invalid image format" / "File type error" / ) / 500 ("File read error")
- Headers: 'Content-Type: multipart/form-data'
### Types
```
Post {
Expand Down Expand Up @@ -109,6 +115,11 @@ TagList {
}
```
```
ImageList {
image_list: Vec<string (max 64 chars)>
}
```
```
LikeCount {
like_count: i64
}
Expand Down Expand Up @@ -161,3 +172,10 @@ DisplayNameChangeRequest {
token: string
}
```
```
AddImageToPostRequest {
token: string,
image_id: i64,
post_id: i64
}
```
12 changes: 12 additions & 0 deletions add-image-to-post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

path="$1/api/post/add-image-to-post"

curl --location --request POST "$path" \
--header 'Content-Type: application/json' \
--header 'Content-Type: text/plain' \
--data-raw '{
"token": "'"$4"'",
"image_id": '$2',
"post_id": '$3'
}'
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash

mkdir -p ./media/profile-pictures
mkdir -p ./media/images
touch SECRET
./setup-db.sh
Expand Down
5 changes: 5 additions & 0 deletions get-images-from-post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

path="$1/api/get/images/from-post/$2"

curl --location --request GET "$path"
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ CREATE TABLE posts_images(
);

CREATE TABLE images(
image_id INTEGER NOT NULL,
image_uuid VARCHAR(34) NOT NULL
image_id INTEGER PRIMARY KEY NOT NULL,
image_file VARCHAR(64) NOT NULL
);

-- ---------------- ----------- -------------- ____________
Expand All @@ -60,7 +60,7 @@ CREATE TABLE images(
-- | is_admin | | | ----------- | | posts_images | | images |
-- | is_banned | | | | ---------------- --------------
-- ---------------- | | |- many | post_id | |- 1 | image_id |
-- | ----------- | | image_id | many -| | image_uuid |
-- | ----------- | | image_id | many -| | image_file |
-- | | likes | | ---------------- --------------
-- | ----------- |
-- |- many | user_id | |
Expand Down
File renamed without changes.
Loading

0 comments on commit 543cfc1

Please sign in to comment.