update new struct

This commit is contained in:
2026-02-13 21:23:38 +07:00
parent e7f50e899d
commit 51e1a065ad
2 changed files with 171 additions and 53 deletions

117
etc.jl
View File

@@ -1,42 +1,95 @@
""" fileServerURL = "http://192.168.88.104:8080"
filepath = "/home/ton/docker-apps/sendreceive/image/test.zip"
filename = basename(filepath)
filebytes = read(filepath)
plik_oneshot_upload - Upload a single file to a plik server using one-shot mode
This function uploads a raw byte array to a plik server in one-shot mode (no upload session).
It first creates a one-shot upload session by sending a POST request with `{"OneShot": true}`,
retrieves an upload ID and token, then uploads the file data as multipart form data using the token.
const DEFAULT_NATS_URL = "nats://localhost:4222"
The function handles the entire flow:
1. Obtains an upload ID and token from the server
2. Uploads the provided binary data as a file using the `X-UploadToken` header
3. Returns identifiers and download URL for the uploaded file
struct msgPayload_v1
id::String # id of this payload
dataname::String # name of this payload
type::String # "text | json | table | image | audio | video | binary"
transport::String # "direct | link"
encoding::String # "none | json | base64 | arrow-ipc"
size::Integer # data size in bytes e.g. 15433
data::Any # payload data in case of direct transport or URL in case of link
metadata::Dict{String, Any} # Dict("checksum=> "sha256_hash", ...)
end
# Arguments:
- `fileServerURL::String` - Base URL of the plik server (e.g., `"http://192.168.88.104:8080"`)
- `filename::String` - Name of the file being uploaded
- `data::Vector{UInt8}` - Raw byte data of the file content
# constructor
function msgPayload_v1(
id::String = "";
dataname::String = "",
type::String = "text",
transport::String = "direct",
encoding::String = "none",
size::Integer = 0,
data::Any = nothing,
metadata::Dict{String, Any} = Dict{String, Any}()
)
return msgPayload_v1(
id,
dataname,
type,
transport,
encoding,
size,
data,
metadata
)
end
# Return:
- A named tuple with fields:
- `uploadid::String` - ID of the one-shot upload session
- `fileid::String` - ID of the uploaded file within the session
- `downloadurl::String` - Full URL to download the uploaded file
# Example
```jldoctest
using HTTP, JSON
struct msgEnvelope_v1
correlationId::String # Unique identifier to track messages across systems. Many senders can talk about the same topic.
msgId::String # this message id
timestamp::String # message published timestamp. string(Dates.now())
# Example data: "Hello" as bytes
data = collect("Hello World!" |> collect |> CodeUnits |> collect)
sendTo::String # topic/subject the sender sends to e.g. "/agent/wine/api/v1/prompt"
msgPurpose::String # purpose of this message e.g. "ACK | NACK | updateStatus | shutdown | ..."
senderName::String # sender name (String) e.g. "agent-wine-web-frontend"
senderId::String # sender id e.g. uuid4snakecase()
receiverName::String # msg receiver name (String) e.g. "agent-backend"
receiverId::String # msg receiver id, nothing means everyone in the topic e.g. uuid4snakecase()
# Upload to local plik server
result = plik_oneshot_upload("http://192.168.88.104:8080", "hello.txt", data)
replyTo::String # sender ask receiver to reply to this topic
replyToMsgId::String # the message id this message is replying to
BrokerURL::String # mqtt/NATS server address
note::Dict{String, Any} # used to store additional info
payloads::AbstractArray{msgPayload_v1} # multiple payload store here
end
# constructor
function msgEnvelope_v1(
correlationId::String = "";
msgId::String = "",
timestamp::String = "",
sendTo::String = "",
msgPurpose::String = "",
senderName::String = "",
senderId::String = "",
receiverName::String = "",
receiverId::String = "",
replyTo::String = "",
replyToMsgId::String = "",
BrokerURL::String = DEFAULT_NATS_URL,
note::Dict{String, Any} = Dict{String, Any}(),
payloads::AbstractArray{msgPayload_v1} = msgPayload_v1[]
)
return msgEnvelope_v1(
correlationId,
msgId,
timestamp,
sendTo,
msgPurpose,
senderName,
senderId,
receiverName,
receiverId,
replyTo,
replyToMsgId,
BrokerURL,
note,
payloads
)
end
# Download URL for the uploaded file
println(result.downloadurl)
```
"""

View File

@@ -15,27 +15,6 @@ const DEFAULT_NATS_URL = "nats://localhost:4222" # Default NATS server URL
const DEFAULT_FILESERVER_URL = "http://localhost:8080/upload" # Default HTTP file server URL for link transport
struct msgEnvelope_v1
correlationId::String # Unique identifier to track messages across systems. Many senders can talk about the same topic.
msgId::String # this message id
timestamp::String # message published timestamp. string(Dates.now())
sendTo::String # topic/subject the sender sends to e.g. "/agent/wine/api/v1/prompt"
msgPurpose::Sting # purpose of this message e.g. "ACK | NACK | updateStatus | shutdown | ..."
senderName::Sting # sender name (String) e.g. "agent-wine-web-frontend"
senderId::String # sender id e.g. uuid4snakecase()
receiverName::String # msg receiver name (String) e.g. "agent-backend"
receiverId::String # msg receiver id, nothing means everyone in the topic e.g. uuid4snakecase()
replyTo::String # sender ask receiver to reply to this topic
replyToMsgId::String # the message id this message is replying to
BrokerURL::String # mqtt/NATS server address
note::Dict{String, Any} # used to store additional info
payloads::Dict{String, Any} #
end
#[WORKING]
struct msgPayload_v1
id::String # id of this payload
dataname::String # name of this payload
@@ -47,6 +26,92 @@ struct msgPayload_v1
metadata::Dict{String, Any} # Dict("checksum=> "sha256_hash", ...)
end
# constructor
function msgPayload_v1(
id::String = "";
dataname::String = "",
type::String = "text",
transport::String = "direct",
encoding::String = "none",
size::Integer = 0,
data::Any = nothing,
metadata::Dict{String, Any} = Dict{String, Any}()
)
return msgPayload_v1(
id,
dataname,
type,
transport,
encoding,
size,
data,
metadata
)
end
struct msgEnvelope_v1
correlationId::String # Unique identifier to track messages across systems. Many senders can talk about the same topic.
msgId::String # this message id
timestamp::String # message published timestamp. string(Dates.now())
sendTo::String # topic/subject the sender sends to e.g. "/agent/wine/api/v1/prompt"
msgPurpose::String # purpose of this message e.g. "ACK | NACK | updateStatus | shutdown | ..."
senderName::String # sender name (String) e.g. "agent-wine-web-frontend"
senderId::String # sender id e.g. uuid4snakecase()
receiverName::String # msg receiver name (String) e.g. "agent-backend"
receiverId::String # msg receiver id, nothing means everyone in the topic e.g. uuid4snakecase()
replyTo::String # sender ask receiver to reply to this topic
replyToMsgId::String # the message id this message is replying to
BrokerURL::String # mqtt/NATS server address
note::Dict{String, Any} # used to store additional info
payloads::AbstractArray{msgPayload_v1} # multiple payload store here
end
# constructor
function msgEnvelope_v1(
correlationId::String = "";
msgId::String = "",
timestamp::String = "",
sendTo::String = "",
msgPurpose::String = "",
senderName::String = "",
senderId::String = "",
receiverName::String = "",
receiverId::String = "",
replyTo::String = "",
replyToMsgId::String = "",
BrokerURL::String = DEFAULT_NATS_URL,
note::Dict{String, Any} = Dict{String, Any}(),
payloads::AbstractArray{msgPayload_v1} = msgPayload_v1[]
)
return msgEnvelope_v1(
correlationId,
msgId,
timestamp,
sendTo,
msgPurpose,
senderName,
senderId,
receiverName,
receiverId,
replyTo,
replyToMsgId,
BrokerURL,
note,
payloads
)
end