From 9dd4ebec45d397326da098599211ca2fe4c88aef Mon Sep 17 00:00:00 2001 From: Zjamnik Date: Sat, 21 Feb 2026 02:43:50 +0100 Subject: [PATCH] partial upload initial not working --- ZiplineUploader.ahk | 1 + momentsTrimAutoUploader.ahk | 109 ++++++++++++++++++++++++++++++------ 2 files changed, 92 insertions(+), 18 deletions(-) diff --git a/ZiplineUploader.ahk b/ZiplineUploader.ahk index 6f8d3db..29b7abb 100644 --- a/ZiplineUploader.ahk +++ b/ZiplineUploader.ahk @@ -100,6 +100,7 @@ for fil in files { ; Build curl command cmd := 'curl -s -H "Authorization: ' Token '" ' cmd .= '-H "x-zipline-original-name: true" ' + cmd .= '-H "x-zipline-p-format: name" ' cmd .= '-F "file=@' fil ';type=' mime '" ' cmd .= '-F "filename=' name '" ' cmd .= '"' ZiplineURL '/api/upload"' diff --git a/momentsTrimAutoUploader.ahk b/momentsTrimAutoUploader.ahk index 76c4ac0..35afa97 100644 --- a/momentsTrimAutoUploader.ahk +++ b/momentsTrimAutoUploader.ahk @@ -1,6 +1,6 @@ #Requires AutoHotkey v2.0 -momentsPath := IniRead("trimUploader.ini", "location", "path", "") +momentsPath := IniRead("trimUploader.ini", "location", "momentsPath", "") if (momentsPath = "") { momentsPath := DirSelect() } @@ -8,45 +8,106 @@ trimPattern := IniRead("trimUploader.ini", "location", "trimPattern", "*_trim.mp ziplineURL := IniRead("trimUploader.ini", "location", "ziplineURL", "PROVIDE ZIPLINE URL") ziplineFolder := IniRead("trimUploader.ini", "location", "ziplineFolder", "PROVIDE FOLDER ID") ziplineToken := IniRead("trimUploader.ini", "location", "ziplineToken", "PROVIDE ZIPLINE TOKEN") +chunkSize := IniRead("trimUploader.ini", "location", "chunkSize", "26214400") +chunkThreshold := IniRead("trimUploader.ini", "location", "chunkThreshold", "99614720") -IniWrite(momentsPath, "trimUploader.ini", "location", "path") +IniWrite(momentsPath, "trimUploader.ini", "location", "momentsPath") IniWrite(trimPattern, "trimUploader.ini", "location", "trimPattern") IniWrite(ziplineURL, "trimUploader.ini", "location", "ziplineURL") IniWrite(ziplineFolder, "trimUploader.ini", "location", "ziplineFolder") IniWrite(ziplineToken, "trimUploader.ini", "location", "ziplineToken") +IniWrite(chunkSize, "trimUploader.ini", "location", "chunkSize") +IniWrite(chunkThreshold, "trimUploader.ini", "location", "chunkThreshold") loop { uploadedURLs := "" uploadedFiles := 0 Loop Files momentsPath "\" trimPattern, "F" { + ; Check file size to avoid upload mid export + fileSize := 0 + while (fileSize < FileGetSize()) { + fileSize := FileGetSize() + Sleep(200) + } - ; Build curl command - cmd := 'curl -s -H "Authorization: ' ziplineToken '" ' - cmd .= '-H "x-zipline-original-name: true" ' - cmd .= '-H "x-zipline-folder: ' ziplineFolder '" ' - cmd .= '-F "file=@' A_LoopFileFullPath ';type=video/mp4" ' - cmd .= '-F "filename=' A_LoopFileName '" ' - cmd .= '"' ZiplineURL '/api/upload"' + chunkNum := Floor(fileSize / chunkSize) + filePath := A_LoopFileFullPath + fileName := A_LoopFileName - ; MsgBox(cmd) + if (chunkNum > 0) { + ; ------------------------- + ; 2. UPLOAD CHUNKS + ; ------------------------- + fileToUpload := FileOpen(filePath, "r") + chunkIndex := 0 + partialIdentifier := "" + mime := "video/mp4" - ; Run curl and capture output - RunWait(A_ComSpec " /c " cmd " | clip", , "Hide") - output := A_Clipboard + while !fileToUpload.AtEOF { + chunk := fileToUpload.Read(chunkSize) + + tmpChunk := A_Temp "\chunk.tmp" + try { + FileDelete tmpChunk + } catch Error { + } + FileAppend chunk, tmpChunk, "RAW" + MsgBox FileGetSize(tmpChunk) + + uploadCmd := 'curl -s -X POST ' + ; uploadCmd .= '-H "content-type: multipart/form-data;" ' + uploadCmd .= Format('-H "Authorization: {1}" ', ziplineToken) + uploadCmd .= '-H "x-zipline-format: name" ' + uploadCmd .= '-H "x-zipline-original-name: true" ' + uploadCmd .= Format('-H "x-zipline-p-content-length: {1}" ', fileSize) + uploadCmd .= Format('-H "x-zipline-p-content-type: {1}" ', mime) + uploadCmd .= Format('-H "x-zipline-p-filename: {1}" ', fileName) + ; uploadCmd .= Format('-H "x-zipline-folder: {1}" ', ziplineFolder) + if (chunkIndex > 0) { + uploadCmd .= Format('-H "x-zipline-p-identifier: {1}" ', partialIdentifier) + } + if (chunkIndex = chunkNum) { + uploadCmd .= '-H "x-zipline-p-lastchunk: true" ' + } else { + uploadCmd .= '-H "x-zipline-p-lastchunk: false" ' + } + uploadCmd .= Format('-F "file=@{1}" ', tmpChunk) + uploadCmd .= Format('"{1}/api/upload/partial"', ziplineURL,) + + MsgBox uploadCmd + resp := RunWaitGet(uploadCmd) + partialResult := JsonExtract(resp, "partialSuccess") + + if (chunkIndex = 0) { + partialIdentifier := JsonExtract(resp, "partialIdentifier") + } + + if !partialResult { + MsgBox "Chunk upload failed at index " chunkIndex "`nResponse:`n" resp + return + } + + chunkIndex++ + } + + fileToUpload.Close() + + finishResp := RunWaitGet(resp) + finalUrl := JsonExtract(finishResp, "url") + } ; Extract URL from JSON - if RegExMatch(output, '"url":"(.*?)"', &m) { - url := m[1] - uploadedURLs .= url "`n" + if ( not finalUrl = "") { + uploadedURLs .= finalUrl "`n" uploadedFiles++ - FileDelete(A_LoopFileFullPath) try { + FileDelete(A_LoopFileFullPath) } catch Error { } } else { - MsgBox "Failed to extract URL.`nResponse:`n" output + MsgBox "Failed to extract URL.`nResponse:`n" finishResp } } @@ -56,4 +117,16 @@ loop { } Sleep(5000) +} + +RunWaitGet(cmd, options := "Hide") { + tmp := A_Temp "\curl_out.txt" + RunWait(A_ComSpec ' /c ' cmd ' > "' tmp '"', , options) + return FileRead(tmp) +} + +JsonExtract(json, key) { + if RegExMatch(json, '"' key '":"(.*?)"', &m) + return m[1] + return "" } \ No newline at end of file