lol

tusd: init at 2.8.0

+139
+1
nixos/tests/all-tests.nix
··· 1389 1389 tuptime = handleTest ./tuptime.nix { }; 1390 1390 turbovnc-headless-server = handleTest ./turbovnc-headless-server.nix { }; 1391 1391 turn-rs = handleTest ./turn-rs.nix { }; 1392 + tusd = runTest ./tusd/default.nix; 1392 1393 tuxguitar = runTest ./tuxguitar.nix; 1393 1394 twingate = runTest ./twingate.nix; 1394 1395 typesense = handleTest ./typesense.nix { };
+50
nixos/tests/tusd/default.nix
··· 1 + { pkgs, lib, ... }: 2 + 3 + let 4 + port = 1080; 5 + 6 + client = 7 + { pkgs, ... }: 8 + { 9 + environment.systemPackages = [ pkgs.curl ]; 10 + }; 11 + 12 + server = 13 + { pkgs, ... }: 14 + { 15 + # tusd does not have a NixOS service yet. 16 + systemd.services.tusd = { 17 + wantedBy = [ "multi-user.target" ]; 18 + 19 + serviceConfig = { 20 + ExecStart = ''${pkgs.tusd}/bin/tusd -port "${toString port}" -upload-dir=/data''; 21 + }; 22 + }; 23 + networking.firewall.allowedTCPPorts = [ port ]; 24 + }; 25 + in 26 + { 27 + name = "tusd"; 28 + meta.maintainers = with lib.maintainers; [ 29 + nh2 30 + kalbasit 31 + ]; 32 + 33 + nodes = { 34 + inherit server; 35 + inherit client; 36 + }; 37 + 38 + testScript = '' 39 + server.wait_for_unit("tusd.service") 40 + server.wait_for_open_port(${toString port}) 41 + 42 + # Create large file. 43 + client.succeed("${pkgs.coreutils}/bin/truncate --size=100M file-100M.bin") 44 + 45 + # Upload it. 46 + client.succeed("${./tus-curl-upload.sh} file-100M.bin http://server:${toString port}/files/") 47 + 48 + print("Upload succeeded") 49 + ''; 50 + }
+50
nixos/tests/tusd/tus-curl-upload.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + # Adapted from: 4 + # - https://github.com/tus/tus.io/issues/96 5 + 6 + if [ ! -f "${1}" ]; then 7 + echo -e "\n\033[1;31m✘\033[0m First argument needs to be an existing file.\n" 8 + exit 1 9 + fi 10 + 11 + if [ -z "${2}" ]; then 12 + echo -e "\n\033[1;31m✘\033[0m Second argument needs to be the TUS server's URL.\n" 13 + exit 1 14 + fi 15 + 16 + file=${1} 17 + TUS_URL=${2} 18 + filename=$(basename "${file}" | base64) 19 + filesize="$(wc -c <"${file}")" 20 + 21 + # Apparently 'Location: ..' is terminated by CRLF. grep and awk faithfully 22 + # preserve the line ending, and the shell's $() substitution strips off the 23 + # final LF leaving you with a string that just ends with a CR. 24 + # 25 + # When the CR is printed, the cursor moves to the beginning of the line and 26 + # whatever gets printed next overwrites what was there. 27 + # ... | tr -d '\015' 28 + location=$(curl \ 29 + --silent --show-error \ 30 + -I \ 31 + -X POST \ 32 + -H "Tus-Resumable: 1.0.0" \ 33 + -H "Content-Length: 0" \ 34 + -H "Upload-Length: ${filesize}" \ 35 + -H "Upload-Metadata: name ${filename}" \ 36 + "${TUS_URL}" | grep 'Location:' | awk '{print $2}' | tr -d '\015') 37 + 38 + if [ -n "${location}" ]; then 39 + curl \ 40 + -X PATCH \ 41 + -H "Tus-Resumable: 1.0.0" \ 42 + -H "Upload-Offset: 0" \ 43 + -H "Content-Length: ${filesize}" \ 44 + -H "Content-Type: application/offset+octet-stream" \ 45 + --data-binary "@${file}" \ 46 + "${location}" -v 47 + else 48 + echo -e "\n\033[1;31m✘\033[0m File creation failed..\n" 49 + exit 1 50 + fi
+38
pkgs/by-name/tu/tusd/package.nix
··· 1 + { 2 + lib, 3 + buildGoModule, 4 + fetchFromGitHub, 5 + nixosTests, 6 + }: 7 + 8 + buildGoModule rec { 9 + pname = "tusd"; 10 + version = "2.8.0"; 11 + 12 + src = fetchFromGitHub { 13 + owner = "tus"; 14 + repo = "tusd"; 15 + tag = "v${version}"; 16 + hash = "sha256-OzXBeLDjaJk4NVgsauR/NUATh7qHbuEfWNdhytZmd0A="; 17 + }; 18 + 19 + vendorHash = "sha256-YununGyB72zE0tmqO3BREJeMTjCuy/1fhPHC5r8OLjg="; 20 + 21 + # Tests need the path to the binary: 22 + # https://github.com/tus/tusd/blob/0e52ad650abed02ec961353bb0c3c8bc36650d2c/internal/e2e/e2e_test.go#L37 23 + preCheck = '' 24 + export TUSD_BINARY=$PWD/../go/bin/tusd 25 + ''; 26 + 27 + passthru.tests.tusd = nixosTests.tusd; 28 + 29 + meta = { 30 + description = "Reference server implementation in Go of tus: the open protocol for resumable file uploads"; 31 + license = lib.licenses.mit; 32 + homepage = "https://tus.io/"; 33 + maintainers = with lib.maintainers; [ 34 + nh2 35 + kalbasit 36 + ]; 37 + }; 38 + }