Skip to content

[Documentation Request] Provide Scripts for automation. #411

Description

@Speiger

Is your feature request related to a problem?

I really enjoy the GokAPI.
It has been a really application.
Really loving it.

But we ran into an issue when we wanted to use it to do server to server transfer.
Yes the API exists but the documentation on it is not that good.

We ended up solving it by reading the swagger documentation and using LLMs.
Are there better ways? Yes but we wanted to make it work with GokAPI instead of SFTP and the whole permission thing.

So my suggestion here is, please provide some command line scripts that automate the API hassle a when trying to use download/upload parts. You don't need to cover all of it but the essentials. That would have saved us 1-2 hours of manually figuring it out.
Especially as the current documentation doesn't even highlight that you could have upload functionality with server to server transfer.

Describe the solution you'd like

My example solution would be something like this.
Provide a copyable file either on the wiki or on github that provides just a core functionality.

This is what i just generated using an local LLM.

Bash Script

#!/bin/bash

# Input
read -p "Enter the upload link: " LINK
read -p "Enter the file path: " FILE_PATH

if [[ ! -f "$FILE_PATH" ]]; then
    echo "Error: File not found."
    exit 1
fi

# Extracting information from URL
BASE_URL=$(echo "$LINK" | cut -d'?' -f1)
FILE_ID=$(echo "$LINK" | sed -n 's/.*id=\([^&]*\).*/\1/p')
API_KEY=$(echo "$LINK" | sed -n 's/.*key=\([^&]*\).*/\1/p')

echo "Base URL: $BASE_URL"
echo "File ID: $FILE_ID"
echo "API Key: $API_KEY"

# 1. Reserve Chunk
echo "Reserving upload slot..."
RESERVE_RESPONSE=$(curl -s -X POST "$BASE_URL/uploadrequest/chunk/reserve" \
    -H "fileRequestId: $FILE_ID" \
    -H "apikey: $API_KEY")

# Extract UUID using jq (or grep if jq is missing)
UUID=$(echo "$RESERVE_RESPONSE" | jq -r '.uuid')

if [ "$UUID" == "null" ] || [ -z "$UUID" ]; then
    echo "Error: Failed to reserve chunk. Response: $RESERVE_RESPONSE"
    exit 1
fi

echo "Reserved UUID: $UUID"

# 2. Chunking and Uploading
# Chunk size: 45MB (47185920 bytes)
CHUNK_SIZE=47185920
FILENAME=$(basename "$FILE_PATH")
TEMP_DIR=$(mktemp -d)
echo "Splitting file into 45MB chunks..."

# Split the file into chunks
split -b $CHUNK_SIZE "$FILE_PATH" "$TEMP_DIR/chunk_"

# Loop through chunks and upload
COUNT=0
for chunk in "$TEMP_DIR"/chunk_*; do
    echo "Uploading chunk $(($COUNT + 1))..."
    
    RESPONSE=$(curl -s -X POST "$BASE_URL/uploadrequest/chunk/add" \
        -H "fileRequestId: $FILE_ID" \
        -H "uuid: $UUID" \
        -H "apikey: $API_KEY" \
        -F "file=@$chunk")

    if [ $? -ne 0 ]; then
        echo "Error occurred during upload of chunk $(($COUNT + 1))"
        rm -rf "$TEMP_DIR"
        exit 1
    fi
    
    ((COUNT++))
done

# 3. Complete Upload
echo "Finalizing upload..."
curl -s -X POST "$BASE_URL/uploadrequest/chunk/complete" \
    -H "fileRequestId: $FILE_ID" \
    -H "uuid: $UUID" \
    -H "apikey: $API_KEY"

echo "Upload process finished."

# Cleanup
rm -rf "$TEMP_DIR"

While my bash experience is novice at best, the code i looked at is at least sound and passes the sniff test.
I don't expect you to upload this code to the wiki. But it is more of a demonstration of what a script like that could look like :)

Describe alternatives you've considered

Not using GokAPI.

Additional Context

Overall i think this is a pretty good tool, it would be nice that the more elaborate systems could use a command line tool be provided by the repo/wiki to make it even better.

Thank you for reading my Request and have a nice weekend!

Impact

  • This would be a breaking change to existing setups.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions