Browse Source

Update attachements to send back filename not link

pull/3/head
Tovi Jaeschke-Rogers 2 years ago
parent
commit
eb0bf8a06f
9 changed files with 44 additions and 20 deletions
  1. +1
    -5
      Backend/Api/Auth/Login.go
  2. +1
    -5
      Backend/Api/Messages/Conversations.go
  3. +1
    -5
      Backend/Api/Messages/MessageThread.go
  4. +29
    -0
      Backend/Database/Seeder/FriendSeeder.go
  5. BIN
      Backend/Database/Seeder/profile_image_enc.dat
  6. +3
    -2
      Backend/Models/Friends.go
  7. +2
    -1
      mobile/lib/models/image_message.dart
  8. +5
    -1
      mobile/lib/models/my_profile.dart
  9. +2
    -1
      mobile/lib/utils/storage/conversations.dart

+ 1
- 5
Backend/Api/Auth/Login.go View File

@ -3,7 +3,6 @@ package Auth
import ( import (
"database/sql/driver" "database/sql/driver"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"time" "time"
@ -78,10 +77,7 @@ func Login(w http.ResponseWriter, r *http.Request) {
}) })
if user.AttachmentID != nil { 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() messageExpiryRaw, _ = user.MessageExpiryDefault.Value()


+ 1
- 5
Backend/Api/Messages/Conversations.go View File

@ -2,7 +2,6 @@ package Messages
import ( import (
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
@ -80,10 +79,7 @@ func EncryptedConversationDetailsList(w http.ResponseWriter, r *http.Request) {
continue 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, "", " ") returnJSON, err = json.MarshalIndent(conversationDetails, "", " ")


+ 1
- 5
Backend/Api/Messages/MessageThread.go View File

@ -2,7 +2,6 @@ package Messages
import ( import (
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database" "git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
@ -42,10 +41,7 @@ func Messages(w http.ResponseWriter, r *http.Request) {
continue 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, "", " ") returnJSON, err = json.MarshalIndent(messages, "", " ")


+ 29
- 0
Backend/Database/Seeder/FriendSeeder.go View File

@ -2,6 +2,8 @@ package Seeder
import ( import (
"encoding/base64" "encoding/base64"
"io"
"os"
"time" "time"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database" "git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
@ -56,6 +58,28 @@ func seedFriend(userRequestTo, userRequestFrom Models.User, accepted bool) error
return Database.CreateFriendRequest(&friendRequest) 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 // SeedFriends creates dummy friends for testing/development
func SeedFriends() { func SeedFriends() {
var ( var (
@ -66,6 +90,11 @@ func SeedFriends() {
err error err error
) )
err = copyProfileImage()
if err != nil {
panic(err)
}
primaryUser, err = Database.GetUserByUsername("testUser") primaryUser, err = Database.GetUserByUsername("testUser")
if err != nil { if err != nil {
panic(err) panic(err)


BIN
Backend/Database/Seeder/profile_image_enc.dat View File


+ 3
- 2
Backend/Models/Friends.go View File

@ -11,8 +11,9 @@ type FriendRequest struct {
Base Base
UserID uuid.UUID `gorm:"type:uuid;column:user_id;not null;" json:"user_id"` UserID uuid.UUID `gorm:"type:uuid;column:user_id;not null;" json:"user_id"`
User User ` json:"user"` 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 FriendPublicAsymmetricKey string ` json:"asymmetric_public_key"` // Stored encrypted
SymmetricKey string `gorm:"not null" json:"symmetric_key"` // Stored encrypted SymmetricKey string `gorm:"not null" json:"symmetric_key"` // Stored encrypted
AcceptedAt sql.NullTime ` json:"accepted_at"` AcceptedAt sql.NullTime ` json:"accepted_at"`


+ 2
- 1
mobile/lib/models/image_message.dart View File

@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:Envelope/models/my_profile.dart';
import 'package:Envelope/utils/storage/get_file.dart'; import 'package:Envelope/utils/storage/get_file.dart';
import 'package:Envelope/utils/storage/write_file.dart'; import 'package:Envelope/utils/storage/write_file.dart';
import 'package:mime/mime.dart'; import 'package:mime/mime.dart';
@ -55,7 +56,7 @@ class ImageMessage extends Message {
); );
File file = await getFile( File file = await getFile(
json['message_data']['attachment']['image_link'],
'$defaultServerUrl/files/${json['message_data']['attachment']['image_link']}',
'${json['id']}', '${json['id']}',
symmetricKey, symmetricKey,
); );


+ 5
- 1
mobile/lib/models/my_profile.dart View File

@ -22,6 +22,7 @@ class MyProfile {
String? symmetricKey; String? symmetricKey;
DateTime? loggedInAt; DateTime? loggedInAt;
File? image; File? image;
String? imageLink;
String messageExpiryDefault = 'no_expiry'; String messageExpiryDefault = 'no_expiry';
MyProfile({ MyProfile({
@ -33,6 +34,7 @@ class MyProfile {
this.symmetricKey, this.symmetricKey,
this.loggedInAt, this.loggedInAt,
this.image, this.image,
this.imageLink,
required this.messageExpiryDefault, required this.messageExpiryDefault,
}); });
@ -54,6 +56,7 @@ class MyProfile {
loggedInAt: loggedInAt, loggedInAt: loggedInAt,
messageExpiryDefault: json['message_expiry_default'], messageExpiryDefault: json['message_expiry_default'],
image: json['file'] != null ? File(json['file']) : null, image: json['file'] != null ? File(json['file']) : null,
imageLink: json['image_link'],
); );
} }
@ -82,6 +85,7 @@ class MyProfile {
'logged_in_at': loggedInAt?.toIso8601String(), 'logged_in_at': loggedInAt?.toIso8601String(),
'message_expiry_default': messageExpiryDefault, 'message_expiry_default': messageExpiryDefault,
'file': image?.path, 'file': image?.path,
'image_link': imageLink,
}); });
} }
@ -98,7 +102,7 @@ class MyProfile {
if (json['image_link'] != '') { if (json['image_link'] != '') {
File profileIcon = await getFile( File profileIcon = await getFile(
json['image_link'],
'$defaultServerUrl/files/${['image_link']}',
json['user_id'], json['user_id'],
json['symmetric_key'], json['symmetric_key'],
); );


+ 2
- 1
mobile/lib/utils/storage/conversations.dart View File

@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:Envelope/exceptions/update_data_exception.dart'; import 'package:Envelope/exceptions/update_data_exception.dart';
import 'package:Envelope/utils/storage/get_file.dart'; import 'package:Envelope/utils/storage/get_file.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:pointycastle/export.dart'; import 'package:pointycastle/export.dart';
import 'package:sqflite/sqflite.dart'; import 'package:sqflite/sqflite.dart';
@ -146,7 +147,7 @@ Future<void> updateConversations() async {
// TODO: Handle exception here // TODO: Handle exception here
if (conversationDetailJson['attachment_id'] != null) { if (conversationDetailJson['attachment_id'] != null) {
conversation.icon = await getFile( conversation.icon = await getFile(
conversationDetailJson['attachment']['image_link'],
'$defaultServerUrl/files/${conversationDetailJson['attachment']['image_link']}',
conversation.id, conversation.id,
conversation.symmetricKey, conversation.symmetricKey,
); );


Loading…
Cancel
Save