mirror of
https://github.com/CHN-beta/nixpkgs.git
synced 2026-01-12 02:40:31 +08:00
tusd: init at 2.8.0
This commit is contained in:
@@ -1389,6 +1389,7 @@ in
|
||||
tuptime = handleTest ./tuptime.nix { };
|
||||
turbovnc-headless-server = handleTest ./turbovnc-headless-server.nix { };
|
||||
turn-rs = handleTest ./turn-rs.nix { };
|
||||
tusd = runTest ./tusd/default.nix;
|
||||
tuxguitar = runTest ./tuxguitar.nix;
|
||||
twingate = runTest ./twingate.nix;
|
||||
typesense = handleTest ./typesense.nix { };
|
||||
|
||||
50
nixos/tests/tusd/default.nix
Normal file
50
nixos/tests/tusd/default.nix
Normal file
@@ -0,0 +1,50 @@
|
||||
{ pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
port = 1080;
|
||||
|
||||
client =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
environment.systemPackages = [ pkgs.curl ];
|
||||
};
|
||||
|
||||
server =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
# tusd does not have a NixOS service yet.
|
||||
systemd.services.tusd = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
ExecStart = ''${pkgs.tusd}/bin/tusd -port "${toString port}" -upload-dir=/data'';
|
||||
};
|
||||
};
|
||||
networking.firewall.allowedTCPPorts = [ port ];
|
||||
};
|
||||
in
|
||||
{
|
||||
name = "tusd";
|
||||
meta.maintainers = with lib.maintainers; [
|
||||
nh2
|
||||
kalbasit
|
||||
];
|
||||
|
||||
nodes = {
|
||||
inherit server;
|
||||
inherit client;
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
server.wait_for_unit("tusd.service")
|
||||
server.wait_for_open_port(${toString port})
|
||||
|
||||
# Create large file.
|
||||
client.succeed("${pkgs.coreutils}/bin/truncate --size=100M file-100M.bin")
|
||||
|
||||
# Upload it.
|
||||
client.succeed("${./tus-curl-upload.sh} file-100M.bin http://server:${toString port}/files/")
|
||||
|
||||
print("Upload succeeded")
|
||||
'';
|
||||
}
|
||||
50
nixos/tests/tusd/tus-curl-upload.sh
Executable file
50
nixos/tests/tusd/tus-curl-upload.sh
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Adapted from:
|
||||
# - https://github.com/tus/tus.io/issues/96
|
||||
|
||||
if [ ! -f "${1}" ]; then
|
||||
echo -e "\n\033[1;31m✘\033[0m First argument needs to be an existing file.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "${2}" ]; then
|
||||
echo -e "\n\033[1;31m✘\033[0m Second argument needs to be the TUS server's URL.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
file=${1}
|
||||
TUS_URL=${2}
|
||||
filename=$(basename "${file}" | base64)
|
||||
filesize="$(wc -c <"${file}")"
|
||||
|
||||
# Apparently 'Location: ..' is terminated by CRLF. grep and awk faithfully
|
||||
# preserve the line ending, and the shell's $() substitution strips off the
|
||||
# final LF leaving you with a string that just ends with a CR.
|
||||
#
|
||||
# When the CR is printed, the cursor moves to the beginning of the line and
|
||||
# whatever gets printed next overwrites what was there.
|
||||
# ... | tr -d '\015'
|
||||
location=$(curl \
|
||||
--silent --show-error \
|
||||
-I \
|
||||
-X POST \
|
||||
-H "Tus-Resumable: 1.0.0" \
|
||||
-H "Content-Length: 0" \
|
||||
-H "Upload-Length: ${filesize}" \
|
||||
-H "Upload-Metadata: name ${filename}" \
|
||||
"${TUS_URL}" | grep 'Location:' | awk '{print $2}' | tr -d '\015')
|
||||
|
||||
if [ -n "${location}" ]; then
|
||||
curl \
|
||||
-X PATCH \
|
||||
-H "Tus-Resumable: 1.0.0" \
|
||||
-H "Upload-Offset: 0" \
|
||||
-H "Content-Length: ${filesize}" \
|
||||
-H "Content-Type: application/offset+octet-stream" \
|
||||
--data-binary "@${file}" \
|
||||
"${location}" -v
|
||||
else
|
||||
echo -e "\n\033[1;31m✘\033[0m File creation failed..\n"
|
||||
exit 1
|
||||
fi
|
||||
38
pkgs/by-name/tu/tusd/package.nix
Normal file
38
pkgs/by-name/tu/tusd/package.nix
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
lib,
|
||||
buildGoModule,
|
||||
fetchFromGitHub,
|
||||
nixosTests,
|
||||
}:
|
||||
|
||||
buildGoModule rec {
|
||||
pname = "tusd";
|
||||
version = "2.8.0";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "tus";
|
||||
repo = "tusd";
|
||||
tag = "v${version}";
|
||||
hash = "sha256-OzXBeLDjaJk4NVgsauR/NUATh7qHbuEfWNdhytZmd0A=";
|
||||
};
|
||||
|
||||
vendorHash = "sha256-YununGyB72zE0tmqO3BREJeMTjCuy/1fhPHC5r8OLjg=";
|
||||
|
||||
# Tests need the path to the binary:
|
||||
# https://github.com/tus/tusd/blob/0e52ad650abed02ec961353bb0c3c8bc36650d2c/internal/e2e/e2e_test.go#L37
|
||||
preCheck = ''
|
||||
export TUSD_BINARY=$PWD/../go/bin/tusd
|
||||
'';
|
||||
|
||||
passthru.tests.tusd = nixosTests.tusd;
|
||||
|
||||
meta = {
|
||||
description = "Reference server implementation in Go of tus: the open protocol for resumable file uploads";
|
||||
license = lib.licenses.mit;
|
||||
homepage = "https://tus.io/";
|
||||
maintainers = with lib.maintainers; [
|
||||
nh2
|
||||
kalbasit
|
||||
];
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user