diff --git a/Backend/Api/Auth/Login.go b/Backend/Api/Auth/Login.go index eb8b516..d217493 100644 --- a/Backend/Api/Auth/Login.go +++ b/Backend/Api/Auth/Login.go @@ -3,7 +3,6 @@ package Auth import ( "database/sql/driver" "encoding/json" - "fmt" "net/http" "time" @@ -78,10 +77,7 @@ func Login(w http.ResponseWriter, r *http.Request) { }) if user.AttachmentID != nil { - imageLink = fmt.Sprintf( - "http://192.168.1.5:8080/files/%s", - user.Attachment.FilePath, - ) + imageLink = user.Attachment.FilePath } messageExpiryRaw, _ = user.MessageExpiryDefault.Value() diff --git a/Backend/Api/Messages/Conversations.go b/Backend/Api/Messages/Conversations.go index 4e7b0cc..a1681da 100644 --- a/Backend/Api/Messages/Conversations.go +++ b/Backend/Api/Messages/Conversations.go @@ -2,7 +2,6 @@ package Messages import ( "encoding/json" - "fmt" "net/http" "net/url" "strings" @@ -80,10 +79,7 @@ func EncryptedConversationDetailsList(w http.ResponseWriter, r *http.Request) { continue } - conversationDetails[i].Attachment.ImageLink = fmt.Sprintf( - "http://192.168.1.5:8080/files/%s", - detail.Attachment.FilePath, - ) + conversationDetails[i].Attachment.ImageLink = detail.Attachment.FilePath } returnJSON, err = json.MarshalIndent(conversationDetails, "", " ") diff --git a/Backend/Api/Messages/MessageThread.go b/Backend/Api/Messages/MessageThread.go index b9cb53e..686f1c1 100644 --- a/Backend/Api/Messages/MessageThread.go +++ b/Backend/Api/Messages/MessageThread.go @@ -2,7 +2,6 @@ package Messages import ( "encoding/json" - "fmt" "net/http" "git.tovijaeschke.xyz/tovi/Envelope/Backend/Database" @@ -42,10 +41,7 @@ func Messages(w http.ResponseWriter, r *http.Request) { continue } - messages[i].MessageData.Attachment.ImageLink = fmt.Sprintf( - "http://192.168.1.5:8080/files/%s", - message.MessageData.Attachment.FilePath, - ) + messages[i].MessageData.Attachment.ImageLink = message.MessageData.Attachment.FilePath } returnJSON, err = json.MarshalIndent(messages, "", " ") diff --git a/Backend/Database/Seeder/FriendSeeder.go b/Backend/Database/Seeder/FriendSeeder.go index f3b5203..e317d13 100644 --- a/Backend/Database/Seeder/FriendSeeder.go +++ b/Backend/Database/Seeder/FriendSeeder.go @@ -2,6 +2,8 @@ package Seeder import ( "encoding/base64" + "io" + "os" "time" "git.tovijaeschke.xyz/tovi/Envelope/Backend/Database" @@ -56,6 +58,28 @@ func seedFriend(userRequestTo, userRequestFrom Models.User, accepted bool) error return Database.CreateFriendRequest(&friendRequest) } +func copyProfileImage() error { + var ( + srcFile *os.File + dstFile *os.File + err error + ) + + srcFile, err = os.Open("./Database/Seeder/profile_image_enc.dat") + if err != nil { + return err + } + + dstFile, err = os.Create("./attachments/profile_image") + if err != nil { + return err + } + + defer dstFile.Close() + _, err = io.Copy(dstFile, srcFile) + return err +} + // SeedFriends creates dummy friends for testing/development func SeedFriends() { var ( @@ -66,6 +90,11 @@ func SeedFriends() { err error ) + err = copyProfileImage() + if err != nil { + panic(err) + } + primaryUser, err = Database.GetUserByUsername("testUser") if err != nil { panic(err) diff --git a/Backend/Database/Seeder/profile_image_enc.dat b/Backend/Database/Seeder/profile_image_enc.dat new file mode 100644 index 0000000..f82798a Binary files /dev/null and b/Backend/Database/Seeder/profile_image_enc.dat differ diff --git a/Backend/Models/Friends.go b/Backend/Models/Friends.go index 967af7d..9dc892d 100644 --- a/Backend/Models/Friends.go +++ b/Backend/Models/Friends.go @@ -11,8 +11,9 @@ type FriendRequest struct { Base UserID uuid.UUID `gorm:"type:uuid;column:user_id;not null;" json:"user_id"` User User ` json:"user"` - FriendID string `gorm:"not null" json:"friend_id"` // Stored encrypted - FriendUsername string ` json:"friend_username"` // Stored encrypted + FriendID string `gorm:"not null" json:"friend_id"` // Stored encrypted + FriendUsername string ` json:"friend_username"` // Stored encrypted + FriendImagePath string ` json:"friend_image_path"` FriendPublicAsymmetricKey string ` json:"asymmetric_public_key"` // Stored encrypted SymmetricKey string `gorm:"not null" json:"symmetric_key"` // Stored encrypted AcceptedAt sql.NullTime ` json:"accepted_at"` diff --git a/mobile/lib/models/image_message.dart b/mobile/lib/models/image_message.dart index 9d80dbf..ff11a8a 100644 --- a/mobile/lib/models/image_message.dart +++ b/mobile/lib/models/image_message.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; +import 'package:Envelope/models/my_profile.dart'; import 'package:Envelope/utils/storage/get_file.dart'; import 'package:Envelope/utils/storage/write_file.dart'; import 'package:mime/mime.dart'; @@ -55,7 +56,7 @@ class ImageMessage extends Message { ); File file = await getFile( - json['message_data']['attachment']['image_link'], + '$defaultServerUrl/files/${json['message_data']['attachment']['image_link']}', '${json['id']}', symmetricKey, ); diff --git a/mobile/lib/models/my_profile.dart b/mobile/lib/models/my_profile.dart index 9db8655..d5f80e7 100644 --- a/mobile/lib/models/my_profile.dart +++ b/mobile/lib/models/my_profile.dart @@ -22,6 +22,7 @@ class MyProfile { String? symmetricKey; DateTime? loggedInAt; File? image; + String? imageLink; String messageExpiryDefault = 'no_expiry'; MyProfile({ @@ -33,6 +34,7 @@ class MyProfile { this.symmetricKey, this.loggedInAt, this.image, + this.imageLink, required this.messageExpiryDefault, }); @@ -54,6 +56,7 @@ class MyProfile { loggedInAt: loggedInAt, messageExpiryDefault: json['message_expiry_default'], image: json['file'] != null ? File(json['file']) : null, + imageLink: json['image_link'], ); } @@ -82,6 +85,7 @@ class MyProfile { 'logged_in_at': loggedInAt?.toIso8601String(), 'message_expiry_default': messageExpiryDefault, 'file': image?.path, + 'image_link': imageLink, }); } @@ -98,7 +102,7 @@ class MyProfile { if (json['image_link'] != '') { File profileIcon = await getFile( - json['image_link'], + '$defaultServerUrl/files/${['image_link']}', json['user_id'], json['symmetric_key'], ); diff --git a/mobile/lib/utils/storage/conversations.dart b/mobile/lib/utils/storage/conversations.dart index b5fce2b..27ba927 100644 --- a/mobile/lib/utils/storage/conversations.dart +++ b/mobile/lib/utils/storage/conversations.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:Envelope/exceptions/update_data_exception.dart'; import 'package:Envelope/utils/storage/get_file.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:http/http.dart' as http; import 'package:pointycastle/export.dart'; import 'package:sqflite/sqflite.dart'; @@ -146,7 +147,7 @@ Future updateConversations() async { // TODO: Handle exception here if (conversationDetailJson['attachment_id'] != null) { conversation.icon = await getFile( - conversationDetailJson['attachment']['image_link'], + '$defaultServerUrl/files/${conversationDetailJson['attachment']['image_link']}', conversation.id, conversation.symmetricKey, );