This commit is contained in:
pleb 2025-10-30 10:23:00 -07:00
parent 8f7e6dc01c
commit 2d8d6cae70
6 changed files with 163 additions and 18 deletions

27
flake.lock generated Normal file
View File

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1761597516,
"narHash": "sha256-wxX7u6D2rpkJLWkZ2E932SIvDJW8+ON/0Yy8+a5vsDU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "daf6dc47aa4b44791372d6139ab7b25269184d55",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-25.05",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

130
flake.nix Normal file
View File

@ -0,0 +1,130 @@
{
description = "plebsaber.stream SvelteKit application";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
};
outputs = { self, nixpkgs }: let
inherit (nixpkgs.lib) genAttrs;
systems = [ "x86_64-linux" "aarch64-linux" ];
forAllSystems = genAttrs systems;
mkPackage = pkgs:
pkgs.buildNpmPackage {
pname = "plebsaber-stream";
version = "0.0.1";
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter = path: type:
!(pkgs.lib.hasInfix "/.git/" path)
&& !(pkgs.lib.hasInfix "/node_modules/" path)
&& !(pkgs.lib.hasInfix "/.svelte-kit/" path);
};
nodejs = pkgs.nodejs_22;
npmDepsHash = "sha256-q2C2NBxjVoxA6XFEMjGZcHAujp5OTiz7llhq3aRFiY0=";
npmBuildScript = "build";
NODE_OPTIONS = "--dns-result-order=ipv4first";
nativeBuildInputs = [ pkgs.makeWrapper ];
installPhase = ''
runHook preInstall
mkdir -p $out/app
cp -r build $out/app/
makeWrapper ${pkgs.nodejs_22}/bin/node $out/bin/plebsaber-stream \
--set NODE_ENV production \
--add-flags "$out/app/build/index.js"
runHook postInstall
'';
meta = {
description = "plebsaber.stream SvelteKit application";
mainProgram = "plebsaber-stream";
};
};
in rec {
packages = forAllSystems (system: let
pkgs = import nixpkgs { inherit system; };
pkg = mkPackage pkgs;
in {
plebsaber-stream = pkg;
default = pkg;
});
overlays.default = final: prev: {
plebsaber-stream = self.packages.${prev.stdenv.hostPlatform.system}.plebsaber-stream;
};
nixosModules.default = { config, lib, pkgs, ... }:
let
inherit (lib) mkEnableOption mkIf mkOption types;
cfg = config.services.plebsaber-stream;
system = pkgs.stdenv.hostPlatform.system;
defaultPackage = self.packages.${system}.plebsaber-stream;
in {
options.services.plebsaber-stream = {
enable = mkEnableOption "plebsaber.stream SvelteKit service";
package = mkOption {
type = types.package;
default = defaultPackage;
defaultText = "self.packages.${system}.plebsaber-stream";
description = "Derivation that provides the plebsaber.stream server.";
};
port = mkOption {
type = types.port;
default = 8037;
description = "HTTP listen port for the Node server.";
};
stateDirectory = mkOption {
type = types.str;
default = "plebsaber-stream";
description = "Name of the state directory managed by systemd.";
};
environment = mkOption {
type = types.attrsOf types.str;
default = {};
description = "Additional environment variables for the service.";
};
environmentFile = mkOption {
type = types.nullOr types.path;
default = null;
description = "Optional environment file consumed by systemd.";
};
};
config = mkIf cfg.enable {
systemd.services.plebsaber-stream = {
description = "plebsaber.stream SvelteKit service";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
environment = {
NODE_ENV = "production";
PORT = builtins.toString cfg.port;
} // cfg.environment;
serviceConfig = {
Type = "simple";
ExecStart = "${cfg.package}/bin/plebsaber-stream";
DynamicUser = true;
StateDirectory = cfg.stateDirectory;
WorkingDirectory = "/var/lib/${cfg.stateDirectory}";
Restart = "on-failure";
RestartSec = 3;
} // lib.optionalAttrs (cfg.environmentFile != null) {
EnvironmentFile = cfg.environmentFile;
};
};
};
};
};
}

View File

@ -23,7 +23,7 @@
<img src="https://git.plebsaber.stream/assets/img/logo.svg" alt="Gitea" class="h-4 w-4" /> <img src="https://git.plebsaber.stream/assets/img/logo.svg" alt="Gitea" class="h-4 w-4" />
<span>Source code</span> <span>Source code</span>
</a> </a>
<a href="https://svelte.dev" class="hover:underline text-muted">Built with SvelteKit, and <span class="text-neon-fuchsia" style="text-shadow: 0 0 8px rgba(255,0,229,0.6);">joy</span></a> <a href="https://svelte.dev" class="hover:underline text-muted">Built with SvelteKit, and <span class="text-neon-fuchsia" style="text-shadow: 0 0 8px rgba(255,0,229,0.6);">❤️</span></a>
</div> </div>
</footer> </footer>
</div> </div>

View File

@ -16,9 +16,9 @@
<div class="absolute -inset-6 bg-gradient-to-tr from-neon/20 via-transparent to-neon-fuchsia/20 blur-2xl rounded-3xl"></div> <div class="absolute -inset-6 bg-gradient-to-tr from-neon/20 via-transparent to-neon-fuchsia/20 blur-2xl rounded-3xl"></div>
<div class="relative card-surface p-6 sm:p-8"> <div class="relative card-surface p-6 sm:p-8">
<div class="grid grid-cols-2 gap-4"> <div class="grid grid-cols-2 gap-4">
<a href="/tools/beatleader-compare" class="rounded-lg bg-black/30 ring-1 ring-white/10 p-4 block hover:ring-white/20 transition"> <a href="/tools/compare-histories" class="rounded-lg bg-black/30 ring-1 ring-white/10 p-4 block hover:ring-white/20 transition">
<div class="text-sm text-muted">Tool</div> <div class="text-sm text-muted">Tool</div>
<div class="mt-1 text-2xl font-mono">BeatLeader Compare</div> <div class="mt-1 text-2xl font-mono">Compare PlayerHistories</div>
<div class="mt-1 text-sm text-muted">A vs B: songs A played that B has not</div> <div class="mt-1 text-sm text-muted">A vs B: songs A played that B has not</div>
</a> </a>

View File

@ -1,12 +0,0 @@
import { dev } from '$app/environment';
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async () => {
if (!dev) {
throw error(404, 'Not found');
}
return {};
};

View File

@ -30,7 +30,7 @@
For this app, I explored three ways to access your BeatLeader data: Steam, OAuth, or a websitestyle session. For this app, I explored three ways to access your BeatLeader data: Steam, OAuth, or a websitestyle session.
</p> </p>
<p> <p>
I wanted tools like <a href="/tools/beatleader-compare">Compare Players</a> to show unranked star ratings when your BeatLeader account is a supporter and <code>ShowAllRatings</code> is enabled. That turns out to not be possible without implementing Steam ticket handling using the Steamworks SDK. <strong>The rest of the notes here were written before I realized that.</strong> I wanted tools like <a href="/tools/compare-histories">Compare Players</a> to show unranked star ratings when your BeatLeader account is a supporter and <code>ShowAllRatings</code> is enabled. That turns out to not be possible without implementing Steam ticket handling using the Steamworks SDK. <strong>The rest of the notes here were written before I realized that.</strong>
</p> </p>
@ -97,7 +97,7 @@
<li><code>scp:offline_access</code> to refresh your session without reprompting (optional).</li> <li><code>scp:offline_access</code> to refresh your session without reprompting (optional).</li>
</ul> </ul>
<p> <p>
You can still login with OAuth when needed: <a class="btn-neon" href="/auth/beatleader/login?redirect_uri=%2Ftools%2Fbeatleader-compare">Login with BeatLeader (OAuth)</a> You can still login with OAuth when needed: <a class="btn-neon" href="/auth/beatleader/login?redirect_uri=%2Ftools%2Fcompare-histories">Login with BeatLeader (OAuth)</a>
</p> </p>
<p> <p>
After OAuth login, we attempt to enable <code>ShowAllRatings</code> automatically. If your BL account is not a supporter, BL will ignore it. After OAuth login, we attempt to enable <code>ShowAllRatings</code> automatically. If your BL account is not a supporter, BL will ignore it.
@ -142,7 +142,7 @@
<h2 id="setup">OAuth App Setup (for developers)</h2> <h2 id="setup">OAuth App Setup (for developers)</h2>
<ol> <ol>
<li> <li>
Configure BeatLeader OAuth credentials here: <a href="/tools/beatleader-oauth">BL OAuth Setup</a>. Configure BeatLeader OAuth credentials here: <strike>BL OAuth Setup</strike>.
If you already have credentials, you can paste them there. If you already have credentials, you can paste them there.
</li> </li>
<li> <li>