mirror of
https://github.com/sky-systems/sky_phone.git
synced 2026-09-03 16:01:05 +00:00
FIX - match FiveManage memo upload flow
This commit is contained in:
@@ -170,6 +170,7 @@ local function validate_upload(data)
|
||||
local title_length = title and utf8.len(title) or nil
|
||||
local note_length = note and utf8.len(note) or nil
|
||||
local duration_ms = tonumber(data.durationMs)
|
||||
local size_bytes = tonumber(data.sizeBytes)
|
||||
local normalized_mime = allowed_audio_mimes[data.mimeType]
|
||||
local waveform = normalize_waveform(data.waveform)
|
||||
if not title_length or title_length < 1 or title_length > Config.Memos.TitleMaxLength
|
||||
@@ -177,6 +178,8 @@ local function validate_upload(data)
|
||||
or not duration_ms or duration_ms ~= duration_ms
|
||||
or duration_ms == math.huge or duration_ms == -math.huge
|
||||
or duration_ms < 300 or duration_ms > Config.Memos.MaximumDurationMs
|
||||
or not size_bytes or size_bytes ~= math.floor(size_bytes)
|
||||
or size_bytes < 1 or size_bytes > Config.Memos.MaximumBytes
|
||||
or not normalized_mime or not waveform or type(data.pinned) ~= "boolean"
|
||||
then
|
||||
return nil
|
||||
@@ -188,6 +191,7 @@ local function validate_upload(data)
|
||||
mime_type = normalized_mime,
|
||||
note = note,
|
||||
pinned = data.pinned,
|
||||
size_bytes = size_bytes,
|
||||
title = title,
|
||||
waveform = waveform,
|
||||
}
|
||||
@@ -361,7 +365,7 @@ RegisterNetEvent("sky_phone:memos:request-upload", function(data)
|
||||
upload_result(src, memo.correlation_id, false, "operation_in_progress")
|
||||
return
|
||||
end
|
||||
local presigned_url, presigned_error, provider_base_url = SkyPhoneMedia.RequestPresignedUrl()
|
||||
local presigned_url, presigned_error = SkyPhoneMedia.RequestPresignedUrl()
|
||||
if not presigned_url then
|
||||
Bridge.Debug(
|
||||
"error",
|
||||
@@ -373,23 +377,19 @@ RegisterNetEvent("sky_phone:memos:request-upload", function(data)
|
||||
upload_result(src, memo.correlation_id, false, presigned_error)
|
||||
return
|
||||
end
|
||||
local ids = Bridge.Database.Query("SELECT UUID() AS `request_id`, UUID() AS `capture_token`", {})
|
||||
local ids = Bridge.Database.Query("SELECT UUID() AS `request_id`", {})
|
||||
local request_id = ids[1] and ids[1].request_id
|
||||
local capture_token = ids[1] and ids[1].capture_token
|
||||
if type(request_id) ~= "string" or type(capture_token) ~= "string" then
|
||||
error("[sky_phone] Database did not generate a voice memo upload token.")
|
||||
if type(request_id) ~= "string" then
|
||||
error("[sky_phone] Database did not generate a voice memo upload request ID.")
|
||||
end
|
||||
pending_uploads[request_id] = {
|
||||
capture_token = capture_token,
|
||||
media_type = "audio",
|
||||
mime_type = memo.mime_type,
|
||||
memo = memo,
|
||||
owner = owner,
|
||||
owner_key = pending_owner_key,
|
||||
provider_base_url = provider_base_url,
|
||||
purpose = "memo",
|
||||
size_bytes = memo.size_bytes,
|
||||
source = src,
|
||||
upload_path = "sky_phone-" .. capture_token,
|
||||
}
|
||||
SetTimeout(Config.Memos.UploadSessionTimeoutMs, function()
|
||||
expire_upload(request_id)
|
||||
@@ -397,9 +397,7 @@ RegisterNetEvent("sky_phone:memos:request-upload", function(data)
|
||||
TriggerClientEvent("sky_phone:memos:upload-ready", src, {
|
||||
requestId = request_id,
|
||||
correlationId = memo.correlation_id,
|
||||
captureToken = capture_token,
|
||||
presignedUrl = presigned_url,
|
||||
uploadPath = pending_uploads[request_id].upload_path,
|
||||
uploadTimeoutMs = Config.Media.FiveManage.UploadTimeoutMs,
|
||||
})
|
||||
end)
|
||||
@@ -418,8 +416,7 @@ RegisterNetEvent("sky_phone:memos:complete-upload", function(data)
|
||||
local rejected, _, trusted_remote = SkyPhoneMedia.VerifyRemoteUpload(
|
||||
state,
|
||||
data.remoteId,
|
||||
data.url,
|
||||
data.originalUrl
|
||||
data.url
|
||||
)
|
||||
if rejected or trusted_remote then
|
||||
discard_verified_upload(data.remoteId)
|
||||
@@ -430,8 +427,7 @@ RegisterNetEvent("sky_phone:memos:complete-upload", function(data)
|
||||
local verified, verify_error, trusted_remote = SkyPhoneMedia.VerifyRemoteUpload(
|
||||
state,
|
||||
data.remoteId,
|
||||
data.url,
|
||||
data.originalUrl
|
||||
data.url
|
||||
)
|
||||
if not verified then
|
||||
pending_uploads[request_id] = nil
|
||||
|
||||
Reference in New Issue
Block a user