From 4d7c0a0f69f930e6f95ee464152d3fce10214be1 Mon Sep 17 00:00:00 2001 From: Slendi Date: Fri, 1 Aug 2025 04:03:41 +0300 Subject: [PATCH] version bump Signed-off-by: Slendi --- flake.nix | 154 +++++++++++++++++++++++++++++------------------------- main.go | 13 +++-- 2 files changed, 92 insertions(+), 75 deletions(-) diff --git a/flake.nix b/flake.nix index 3d29ef7..34751a7 100644 --- a/flake.nix +++ b/flake.nix @@ -2,85 +2,97 @@ description = "A simple pastebin service"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { nixpkgs, flake-utils, ... }@inputs: - flake-utils.lib.eachDefaultSystem (system: + outputs = + { nixpkgs, flake-utils, ... }@inputs: + flake-utils.lib.eachDefaultSystem ( + system: let pkgs = import nixpkgs { inherit system; }; in - { - packages = rec { - slenpaste = pkgs.buildGoModule { - pname = "slenpaste"; - version = "0.1.3"; - src = ./.; - goPackagePath = "github.com/slendidev/slenpaste"; - vendorHash = "sha256-MUvodL6K71SCfxu51T/Ka2/w32Kz+IXem1bYqXQLSaU="; - }; - default = slenpaste; - }; + { + packages = rec { + slenpaste = pkgs.buildGoModule { + pname = "slenpaste"; + version = "0.1.4"; + src = ./.; + goPackagePath = "github.com/slendidev/slenpaste"; + vendorHash = "sha256-MUvodL6K71SCfxu51T/Ka2/w32Kz+IXem1bYqXQLSaU="; + }; + default = slenpaste; + }; - devShells.default = pkgs.mkShell { - buildInputs = [ pkgs.go pkgs.gopls ]; - }; + devShells.default = pkgs.mkShell { + buildInputs = [ + pkgs.go + pkgs.gopls + ]; + }; - nixosModules.slenpaste = { lib, pkgs, config, ... }: { - # module function - options.services.slenpaste.enable = lib.mkEnableOption "Enable slenpaste service"; - options.services.slenpaste.domain = lib.mkOption { - type = lib.types.str; - default = "localhost"; - description = "Domain to serve pastes from"; - }; - options.services.slenpaste.listen = lib.mkOption { - type = lib.types.str; - default = "0.0.0.0:8080"; - description = "Listen address (host:port)"; - }; - options.services.slenpaste.staticDir = lib.mkOption { - type = lib.types.str; - default = "/var/lib/slenpaste"; - description = "Directory which contains the actual paste data"; - }; - options.services.slenpaste.expireDur = lib.mkOption { - type = lib.types.str; - default = "0"; - description = "Expiry duration (Go syntax, e.g. \"5m\", \"1h\" or \"0\" for none)"; - }; - options.services.slenpaste.expireOnView = lib.mkOption { - type = lib.types.bool; - default = false; - description = "Whether to expire on first view"; - }; - options.services.slenpaste.https = lib.mkOption { - type = lib.types.bool; - default = false; - description = "Whether to use https:// in generated URLs"; - }; + nixosModules.slenpaste = + { + lib, + pkgs, + config, + ... + }: + { + # module function + options.services.slenpaste.enable = lib.mkEnableOption "Enable slenpaste service"; + options.services.slenpaste.domain = lib.mkOption { + type = lib.types.str; + default = "localhost"; + description = "Domain to serve pastes from"; + }; + options.services.slenpaste.listen = lib.mkOption { + type = lib.types.str; + default = "0.0.0.0:8080"; + description = "Listen address (host:port)"; + }; + options.services.slenpaste.staticDir = lib.mkOption { + type = lib.types.str; + default = "/var/lib/slenpaste"; + description = "Directory which contains the actual paste data"; + }; + options.services.slenpaste.expireDur = lib.mkOption { + type = lib.types.str; + default = "0"; + description = "Expiry duration (Go syntax, e.g. \"5m\", \"1h\" or \"0\" for none)"; + }; + options.services.slenpaste.expireOnView = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Whether to expire on first view"; + }; + options.services.slenpaste.https = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Whether to use https:// in generated URLs"; + }; - config = lib.mkIf config.services.slenpaste.enable { - systemd.services.slenpaste = { - description = "slenpaste HTTP paste service"; - after = [ "network.target" ]; - wants = [ "network.target" ]; - serviceConfig = { - ExecStart = '' - ${inputs.self.packages.${system}.slenpaste}/bin/slenpaste \ - -domain "${config.services.slenpaste.domain}" \ - -listen "${config.services.slenpaste.listen}" \ - -expire "${config.services.slenpaste.expireDur}" \ - ${lib.optionalString config.services.slenpaste.expireOnView "-expire-on-view=false"} - ${lib.optionalString config.services.slenpaste.https "-https"} - ''; - Restart = "on-failure"; - }; - wantedBy = [ "multi-user.target" ]; - }; - }; - }; - } + config = lib.mkIf config.services.slenpaste.enable { + systemd.services.slenpaste = { + description = "slenpaste HTTP paste service"; + after = [ "network.target" ]; + wants = [ "network.target" ]; + serviceConfig = { + ExecStart = '' + ${inputs.self.packages.${system}.slenpaste}/bin/slenpaste \ + -domain "${config.services.slenpaste.domain}" \ + -listen "${config.services.slenpaste.listen}" \ + -expire "${config.services.slenpaste.expireDur}" \ + ${lib.optionalString config.services.slenpaste.expireOnView "-expire-on-view=false"} + ${lib.optionalString config.services.slenpaste.https "-https"} + ''; + Restart = "on-failure"; + }; + wantedBy = [ "multi-user.target" ]; + }; + }; + }; + } ); } diff --git a/main.go b/main.go index cc7aa53..ea3a9ff 100644 --- a/main.go +++ b/main.go @@ -69,16 +69,21 @@ func randomID(n int) string { func indexHandler(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-Type", "text/html") + scheme := "http" + if useHTTPS { + scheme = "https" + } + d := fmt.Sprintf("%s://%s", scheme, domain) fmt.Fprintf(w, `
Welcome to slenpaste!
 
 Upload a file:
-  curl -F 'file=@yourfile.txt' -F 'expiry=1h' http://%s/
+  curl -F 'file=@yourfile.txt' -F 'expiry=1h' %s/
 
 Upload from stdin (no file param, expire after 5m):
-  curl --data-binary @- http://%s/?expiry=5m < yourfile.txt
+  curl --data-binary @- %s/?expiry=5m < yourfile.txt
 
 Upload from stdin and expire on first view:
-  cat yourfile.txt | curl --data-binary @- "http://%s/?expiry=view"
+  cat yourfile.txt | curl --data-binary @- "%s/?expiry=view"
 
 
@@ -95,7 +100,7 @@ Upload from stdin and expire on first view:
-`, domain, domain, domain) +`, d, d, d) } func uploadHandler(w http.ResponseWriter, r *http.Request) {