diff --git a/frontend/src/stores/localchat.ts b/frontend/src/stores/localchat.ts
index fcee975..2f6a902 100644
--- a/frontend/src/stores/localchat.ts
+++ b/frontend/src/stores/localchat.ts
@@ -39,6 +39,7 @@ export const useLocalChatStore = defineStore('localChatStore', () => {
setUserList(ips);
}
if(data.messages){
+ const apiUrl = `${config.apiUrl}/localchat/viewimage?img=`
for(let ip in data.messages){
const msgList:any = data.messages[ip]
if(!msgList || msgList.length < 1)return;
@@ -49,11 +50,13 @@ export const useLocalChatStore = defineStore('localChatStore', () => {
//console.log(msg)
addText(msg)
}
- if (msg.type === "image"){
- console.log(msg)
+ else if (msg.type === "image"){
+ msg.message = msg.message.map((d: any) => `${apiUrl}${encodeURIComponent(d)}`)
+ //console.log(msg)
+ addText(msg)
}
- if (msg.type === "fileSending"){
-
+ else if (msg.type === "fileSending"){
+ addText(msg)
}
})
}
@@ -313,7 +316,7 @@ export const useLocalChatStore = defineStore('localChatStore', () => {
const targetUser: any = await getTargetUser(data)
const saveMsg: any = {
- type: 'text',
+ type: data.type,
targetId: targetUser.id,
targetIp: targetUser.ip,
content: data.message,
@@ -326,8 +329,8 @@ export const useLocalChatStore = defineStore('localChatStore', () => {
isRead: false,
status: 'reciped'
}
- console.log(saveMsg)
- console.log(chatTargetId.value)
+ // console.log(saveMsg)
+ // console.log(chatTargetId.value)
if (targetUser.ip === chatTargetIp.value) {
saveMsg.readAt = Date.now()
saveMsg.isRead = true
@@ -362,6 +365,7 @@ export const useLocalChatStore = defineStore('localChatStore', () => {
isRead: false,
status: 'sending'
}
+ console.log(saveMsg)
const msgId = await db.addOne('chatmsg', saveMsg)
//await getMsgList()
msgList.value.push(saveMsg)
@@ -393,9 +397,9 @@ export const useLocalChatStore = defineStore('localChatStore', () => {
saveMsg.status = 'sended'
saveMsg.readAt = Date.now()
await db.update('chatmsg', msgId, saveMsg)
- if(type === 'applyfile'){
- notifySuccess("发送成功!")
- }
+ // if(type === 'applyfile'){
+ // notifySuccess("发送成功!")
+ // }
}
}
diff --git a/godo/localchat/image.go b/godo/localchat/image.go
index 3d3e32c..9e2900e 100644
--- a/godo/localchat/image.go
+++ b/godo/localchat/image.go
@@ -119,7 +119,7 @@ func ReceiveImg(msg UdpMessage) ([]string, error) {
if !ok {
continue
}
- imgUrl := fmt.Sprintf("http://%s/viewimg?img=%s", msg.IP, url.QueryEscape(p))
+ imgUrl := fmt.Sprintf("http://%s:56780/localchat/viewimage?img=%s", msg.IP, url.QueryEscape(p))
resp, err := http.Get(imgUrl)
if err != nil {
log.Printf("Failed to download image from URL %s: %v", imgUrl, err)
@@ -145,7 +145,8 @@ func ReceiveImg(msg UdpMessage) ([]string, error) {
log.Printf("Failed to save image to %s: %v", filePath, err)
continue
}
- savedPaths = append(savedPaths, filePath)
+ receviePath := filepath.Join(resPath, fileName)
+ savedPaths = append(savedPaths, receviePath)
}
if len(savedPaths) > 0 {
@@ -158,13 +159,13 @@ func ReceiveImg(msg UdpMessage) ([]string, error) {
// 生成随机文件名并保留扩展名
func generateRandomFileNameWithExtension(originalFileName string) (string, error) {
- fileNameWithoutExt, fileExt := filepath.Split(originalFileName)
+ _, fileExt := filepath.Split(originalFileName)
fileExt = strings.TrimPrefix(fileExt, ".")
if fileExt == "" {
fileExt = "png"
}
- randomFileName := fmt.Sprintf("%s_%s.%s", fileNameWithoutExt, strconv.FormatInt(time.Now().UnixNano(), 10), fileExt)
+ randomFileName := fmt.Sprintf("%s.%s", strconv.FormatInt(time.Now().UnixNano(), 10), fileExt)
return randomFileName, nil
}