41 lines
1.0 KiB
Bash
Executable File
41 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
get_raw_links() {
|
|
local url=$1
|
|
local token=$2
|
|
|
|
local response=$(curl -s -X 'GET' "$url" -H 'accept: application/json' -H "Authorization: token $token")
|
|
local entries=$(echo "$response" | jq -c '.[]')
|
|
|
|
while IFS= read -r entry; do
|
|
local entry_type=$(echo "$entry" | jq -r '.type')
|
|
|
|
if [[ "$entry_type" == "file" ]]; then
|
|
local download_url=$(echo "$entry" | jq -r '.download_url')
|
|
echo "$download_url"
|
|
elif [[ "$entry_type" == "dir" ]]; then
|
|
local dir_url=$(echo "$entry" | jq -r '.url')
|
|
get_raw_links "$dir_url" "$token"
|
|
fi
|
|
done <<<"$entries"
|
|
}
|
|
|
|
if [ $# -lt 1 ]; then
|
|
echo "Usage: ./gitea_raw_links.sh <repository_url> [token]"
|
|
exit 1
|
|
fi
|
|
|
|
repository_url=$1
|
|
token=$2
|
|
|
|
# Extract username and repository name from the repository URL
|
|
username=$(basename "$(dirname "$repository_url")")
|
|
reponame=$(basename "$repository_url")
|
|
|
|
api_url="https://git.evers.sh/api/v1/repos/${username}/${reponame}/contents"
|
|
if [ -n "$token" ]; then
|
|
api_url="${api_url}?token=${token}"
|
|
fi
|
|
|
|
get_raw_links "$api_url" "$token"
|