partial upload initial not working
This commit is contained in:
@@ -100,6 +100,7 @@ for fil in files {
|
|||||||
; Build curl command
|
; Build curl command
|
||||||
cmd := 'curl -s -H "Authorization: ' Token '" '
|
cmd := 'curl -s -H "Authorization: ' Token '" '
|
||||||
cmd .= '-H "x-zipline-original-name: true" '
|
cmd .= '-H "x-zipline-original-name: true" '
|
||||||
|
cmd .= '-H "x-zipline-p-format: name" '
|
||||||
cmd .= '-F "file=@' fil ';type=' mime '" '
|
cmd .= '-F "file=@' fil ';type=' mime '" '
|
||||||
cmd .= '-F "filename=' name '" '
|
cmd .= '-F "filename=' name '" '
|
||||||
cmd .= '"' ZiplineURL '/api/upload"'
|
cmd .= '"' ZiplineURL '/api/upload"'
|
||||||
|
|||||||
+91
-18
@@ -1,6 +1,6 @@
|
|||||||
#Requires AutoHotkey v2.0
|
#Requires AutoHotkey v2.0
|
||||||
|
|
||||||
momentsPath := IniRead("trimUploader.ini", "location", "path", "")
|
momentsPath := IniRead("trimUploader.ini", "location", "momentsPath", "")
|
||||||
if (momentsPath = "") {
|
if (momentsPath = "") {
|
||||||
momentsPath := DirSelect()
|
momentsPath := DirSelect()
|
||||||
}
|
}
|
||||||
@@ -8,45 +8,106 @@ trimPattern := IniRead("trimUploader.ini", "location", "trimPattern", "*_trim.mp
|
|||||||
ziplineURL := IniRead("trimUploader.ini", "location", "ziplineURL", "PROVIDE ZIPLINE URL")
|
ziplineURL := IniRead("trimUploader.ini", "location", "ziplineURL", "PROVIDE ZIPLINE URL")
|
||||||
ziplineFolder := IniRead("trimUploader.ini", "location", "ziplineFolder", "PROVIDE FOLDER ID")
|
ziplineFolder := IniRead("trimUploader.ini", "location", "ziplineFolder", "PROVIDE FOLDER ID")
|
||||||
ziplineToken := IniRead("trimUploader.ini", "location", "ziplineToken", "PROVIDE ZIPLINE TOKEN")
|
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(trimPattern, "trimUploader.ini", "location", "trimPattern")
|
||||||
IniWrite(ziplineURL, "trimUploader.ini", "location", "ziplineURL")
|
IniWrite(ziplineURL, "trimUploader.ini", "location", "ziplineURL")
|
||||||
IniWrite(ziplineFolder, "trimUploader.ini", "location", "ziplineFolder")
|
IniWrite(ziplineFolder, "trimUploader.ini", "location", "ziplineFolder")
|
||||||
IniWrite(ziplineToken, "trimUploader.ini", "location", "ziplineToken")
|
IniWrite(ziplineToken, "trimUploader.ini", "location", "ziplineToken")
|
||||||
|
IniWrite(chunkSize, "trimUploader.ini", "location", "chunkSize")
|
||||||
|
IniWrite(chunkThreshold, "trimUploader.ini", "location", "chunkThreshold")
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
uploadedURLs := ""
|
uploadedURLs := ""
|
||||||
uploadedFiles := 0
|
uploadedFiles := 0
|
||||||
Loop Files momentsPath "\" trimPattern, "F" {
|
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
|
chunkNum := Floor(fileSize / chunkSize)
|
||||||
cmd := 'curl -s -H "Authorization: ' ziplineToken '" '
|
filePath := A_LoopFileFullPath
|
||||||
cmd .= '-H "x-zipline-original-name: true" '
|
fileName := A_LoopFileName
|
||||||
cmd .= '-H "x-zipline-folder: ' ziplineFolder '" '
|
|
||||||
cmd .= '-F "file=@' A_LoopFileFullPath ';type=video/mp4" '
|
|
||||||
cmd .= '-F "filename=' A_LoopFileName '" '
|
|
||||||
cmd .= '"' ZiplineURL '/api/upload"'
|
|
||||||
|
|
||||||
; MsgBox(cmd)
|
if (chunkNum > 0) {
|
||||||
|
; -------------------------
|
||||||
|
; 2. UPLOAD CHUNKS
|
||||||
|
; -------------------------
|
||||||
|
fileToUpload := FileOpen(filePath, "r")
|
||||||
|
chunkIndex := 0
|
||||||
|
partialIdentifier := ""
|
||||||
|
mime := "video/mp4"
|
||||||
|
|
||||||
; Run curl and capture output
|
while !fileToUpload.AtEOF {
|
||||||
RunWait(A_ComSpec " /c " cmd " | clip", , "Hide")
|
chunk := fileToUpload.Read(chunkSize)
|
||||||
output := A_Clipboard
|
|
||||||
|
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
|
; Extract URL from JSON
|
||||||
if RegExMatch(output, '"url":"(.*?)"', &m) {
|
if ( not finalUrl = "") {
|
||||||
url := m[1]
|
uploadedURLs .= finalUrl "`n"
|
||||||
uploadedURLs .= url "`n"
|
|
||||||
uploadedFiles++
|
uploadedFiles++
|
||||||
FileDelete(A_LoopFileFullPath)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
FileDelete(A_LoopFileFullPath)
|
||||||
} catch Error {
|
} catch Error {
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MsgBox "Failed to extract URL.`nResponse:`n" output
|
MsgBox "Failed to extract URL.`nResponse:`n" finishResp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,4 +117,16 @@ loop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Sleep(5000)
|
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 ""
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user