Implemented right-click menu to remove or download loot (files/screenshots).
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import times, json, base64, parsetoml, strformat
|
||||
import times, json, base64, parsetoml, strformat, pixie
|
||||
import stb_image/write as stbiw
|
||||
import ./logger
|
||||
import ../../common/[types, utils, event]
|
||||
export sendHeartbeat, recvEvent
|
||||
@@ -144,7 +145,38 @@ proc sendBuildlogItem*(client: WsConnection, logType: LogType, message: string)
|
||||
if client != nil:
|
||||
client.ws.sendEvent(event, client.sessionKey)
|
||||
|
||||
proc createThumbnail(data: string, maxWidth: int = 1024, quality: int = 90): string =
|
||||
let img: Image = decodeImage(data)
|
||||
|
||||
let aspectRatio = img.height.float / img.width.float
|
||||
let
|
||||
width = min(maxWidth, img.width)
|
||||
height = int(width.float * aspectRatio)
|
||||
|
||||
# Resize image
|
||||
let thumbnail = img.resize(width, height)
|
||||
|
||||
# Convert to JPEG image for smaller file size
|
||||
var rgbaData = newSeq[byte](width * height * 4)
|
||||
var i = 0
|
||||
for y in 0..<height:
|
||||
for x in 0..<width:
|
||||
let color = thumbnail[x, y]
|
||||
rgbaData[i] = color.r
|
||||
rgbaData[i + 1] = color.g
|
||||
rgbaData[i + 2] = color.b
|
||||
rgbaData[i + 3] = color.a
|
||||
i += 4
|
||||
|
||||
return Bytes.toString(stbiw.writeJPG(width, height, 4, rgbaData, quality))
|
||||
|
||||
proc sendLoot*(client: WsConnection, loot: LootItem) =
|
||||
var data: string
|
||||
if loot.itemType == SCREENSHOT:
|
||||
loot.data = createThumbnail(readFile(loot.path)) # Create a smaller thumbnail version of the screenshot for better transportability
|
||||
elif loot.itemType == DOWNLOAD:
|
||||
loot.data = readFile(loot.path) # Read downloaded file
|
||||
|
||||
let event = Event(
|
||||
eventType: CLIENT_LOOT_ADD,
|
||||
timestamp: now().toTime().toUnix(),
|
||||
@@ -152,3 +184,15 @@ proc sendLoot*(client: WsConnection, loot: LootItem) =
|
||||
)
|
||||
if client != nil:
|
||||
client.ws.sendEvent(event, client.sessionKey)
|
||||
|
||||
proc sendLootSync*(client: WsConnection, path: string, file: string) =
|
||||
let event = Event(
|
||||
eventType: CLIENT_LOOT_SYNC,
|
||||
timestamp: now().toTime().toUnix(),
|
||||
data: %*{
|
||||
"path": path,
|
||||
"loot": encode(file)
|
||||
}
|
||||
)
|
||||
if client != nil:
|
||||
client.ws.sendEvent(event, client.sessionKey)
|
||||
Reference in New Issue
Block a user