diff --git a/.envrc b/.envrc new file mode 100644 index 000000000..618e5c095 --- /dev/null +++ b/.envrc @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Docs: https://direnv.net/ + +# https://github.com/nix-community/nix-direnv/?tab=readme-ov-file#installation +if ! has nix_direnv_version || ! nix_direnv_version 3.1.0; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.1.0/direnvrc" "sha256-yMJ2OVMzrFaDPn7q8nCBZFRYpL/f0RcHzhmw/i6btJM=" +fi + +watch_file devenv.nix + +use flake . --impure --accept-flake-config + +layout node # adds PATH entry node_modules/.bin - https://github.com/direnv/direnv/blob/master/stdlib.sh#L783 diff --git a/.gitignore b/.gitignore index ee659ba6c..bc55b8fa9 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,11 @@ aaa user-chart.svg test.log + +########## +# Devenv # +########## +/.direnv/ +/.devenv/ +# auto-generated by devenv +/.pre-commit-config.yaml \ No newline at end of file diff --git a/devenv.nix b/devenv.nix new file mode 100644 index 000000000..58c36d5b5 --- /dev/null +++ b/devenv.nix @@ -0,0 +1,50 @@ +# Docs: https://devenv.sh/basics/ +{ pkgs, inputs, ... }: +let + # https://devenv.sh/common-patterns/#getting-a-recent-version-of-a-package-from-nixpkgs-unstable + pkgs-latest = inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}; +in +{ + + languages = { + # Docs: https://devenv.sh/languages/ + nix.enable = true; + javascript = { + enable = true; # source: https://github.com/cachix/devenv/blob/main/src/modules/languages/javascript.nix + # TODO remove whichever you don't need: + npm.enable = true; + pnpm = { + enable = true; + package = pkgs-latest.nodePackages.pnpm; + }; + yarn.enable = true; + }; + typescript.enable = true; + deno.enable = true; + }; + + packages = with pkgs; [ + gcc # needed for some npm packages + nodePackages.typescript-language-server # many editors benefit from this + + # Search for packages: https://search.nixos.org/packages?channel=unstable&query=cowsay + # (note: this searches on unstable channel, you might need to use pkgs-latest for some): + #pkgs-latest.task-keeper + ]; + + scripts = { }; # Docs: https://devenv.sh/scripts/ + + git-hooks.hooks = { + # Docs: https://devenv.sh/pre-commit-hooks/ + # list of pre-configured hooks: https://devenv.sh/reference/options/#pre-commithooks + nil.enable = true; # nix lsp + nixpkgs-fmt.enable = true; # nix formatting + eslint = { + # enable = true; # TODO disabled by default as it fails if no eslint config exists + files = "\.(js|ts|vue|jsx|tsx)$"; + fail_fast = true; # skip other pre-commit hooks if this one fails + }; + }; + + difftastic.enable = true; # enable semantic diffs - https://devenv.sh/integrations/difftastic/ +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..5ed8b1258 --- /dev/null +++ b/flake.lock @@ -0,0 +1,327 @@ +{ + "nodes": { + "cachix": { + "inputs": { + "devenv": [ + "devenv" + ], + "flake-compat": [ + "devenv" + ], + "git-hooks": [ + "devenv" + ], + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1744206633, + "narHash": "sha256-pb5aYkE8FOoa4n123slgHiOf1UbNSnKe5pEZC+xXD5g=", + "owner": "cachix", + "repo": "cachix", + "rev": "8a60090640b96f9df95d1ab99e5763a586be1404", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "latest", + "repo": "cachix", + "type": "github" + } + }, + "devenv": { + "inputs": { + "cachix": "cachix", + "flake-compat": "flake-compat", + "git-hooks": "git-hooks", + "nix": "nix", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1749743313, + "narHash": "sha256-STxnRoD/LYUCCQDDTGdyIUo71vjd8a924FW6wJYmHM4=", + "owner": "cachix", + "repo": "devenv", + "rev": "7d2fab8f90ff435ec0ca656da2cbae4cb1a324de", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1733328505, + "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "devenv", + "nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1712014858, + "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-parts_2": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1749398372, + "narHash": "sha256-tYBdgS56eXYaWVW3fsnPQ/nFlgWi/Z2Ymhyu21zVM98=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9305fe4e5c2a6fcf5ba6a3ff155720fbe4076569", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": [ + "devenv" + ], + "gitignore": "gitignore", + "nixpkgs": [ + "devenv", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1746537231, + "narHash": "sha256-Wb2xeSyOsCoTCTj7LOoD6cdKLEROyFAArnYoS+noCWo=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "fa466640195d38ec97cf0493d6d6882bc4d14969", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "devenv", + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "libgit2": { + "flake": false, + "locked": { + "lastModified": 1697646580, + "narHash": "sha256-oX4Z3S9WtJlwvj0uH9HlYcWv+x1hqp8mhXl7HsLu2f0=", + "owner": "libgit2", + "repo": "libgit2", + "rev": "45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5", + "type": "github" + }, + "original": { + "owner": "libgit2", + "repo": "libgit2", + "type": "github" + } + }, + "nix": { + "inputs": { + "flake-compat": [ + "devenv" + ], + "flake-parts": "flake-parts", + "libgit2": "libgit2", + "nixpkgs": "nixpkgs_2", + "nixpkgs-23-11": [ + "devenv" + ], + "nixpkgs-regression": [ + "devenv" + ], + "pre-commit-hooks": [ + "devenv" + ] + }, + "locked": { + "lastModified": 1745930071, + "narHash": "sha256-bYyjarS3qSNqxfgc89IoVz8cAFDkF9yPE63EJr+h50s=", + "owner": "domenkozar", + "repo": "nix", + "rev": "b455edf3505f1bf0172b39a735caef94687d0d9c", + "type": "github" + }, + "original": { + "owner": "domenkozar", + "ref": "devenv-2.24", + "repo": "nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1733212471, + "narHash": "sha256-M1+uCoV5igihRfcUKrr1riygbe73/dzNnzPsmaLCmpo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "55d15ad12a74eb7d4646254e13638ad0c4128776", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1748740939, + "narHash": "sha256-rQaysilft1aVMwF14xIdGS3sj1yHlI6oKQNBRTF40cc=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "656a64127e9d791a334452c6b6606d17539476e2", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1749285348, + "narHash": "sha256-frdhQvPbmDYaScPFiCnfdh3B/Vh81Uuoo0w5TkWmmjU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3e3afe5174c561dee0df6f2c2b2236990146329f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1717432640, + "narHash": "sha256-+f9c4/ZX5MWDOuB1rKoWj+lBNm0z0rs4CK47HBLxy1o=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "88269ab3044128b7c2f4c7d68448b2fb50456870", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "release-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1746807397, + "narHash": "sha256-zU2z0jlkJGWLhdNr/8AJSxqK8XD0IlQgHp3VZcP56Aw=", + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "c5208b594838ea8e6cca5997fbf784b7cca1ca90", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1746807397, + "narHash": "sha256-zU2z0jlkJGWLhdNr/8AJSxqK8XD0IlQgHp3VZcP56Aw=", + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "c5208b594838ea8e6cca5997fbf784b7cca1ca90", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "flake-parts": "flake-parts_2", + "nixpkgs": "nixpkgs_4", + "nixpkgs-unstable": "nixpkgs-unstable", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..1cef0bb16 --- /dev/null +++ b/flake.nix @@ -0,0 +1,33 @@ +{ + # docs: https://devenv.sh/guides/using-with-flakes/#the-flakenix-file + + inputs = { + nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling"; # (i) https://devenv.sh/blog/2024/03/20/devenv-10-rewrite-in-rust/#testing-infrastructure + nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; + devenv.url = "github:cachix/devenv"; + flake-parts.url = "github:hercules-ci/flake-parts"; + systems.url = "github:nix-systems/default"; # (i) allows overriding systems easily, see https://github.com/nix-systems/nix-systems#consumer-usage + }; + + outputs = { self, nixpkgs, nixpkgs-unstable, devenv, systems, flake-parts, ... } @ inputs: ( + flake-parts.lib.mkFlake { inherit inputs; } { + systems = (import systems); + imports = [ + inputs.devenv.flakeModule + ]; + # perSystem docs: https://flake.parts/module-arguments.html#persystem-module-parameters + perSystem = { config, self', inputs', pkgs, system, ... }: { + + devenv.shells.default = { + imports = [ ./devenv.nix ]; + }; + + }; + } + ); + + nixConfig = { + extra-substituters = [ "https://devenv.cachix.org" ]; + extra-trusted-public-keys = [ "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=" ]; + }; +} diff --git a/src/api/web-dav.ts b/src/api/web-dav.ts index 6e445d419..7a0a54c3b 100644 --- a/src/api/web-dav.ts +++ b/src/api/web-dav.ts @@ -34,7 +34,7 @@ export async function judgeDirExist(context: WebDAVContext, dirPath: string): Pr const method = 'PROPFIND' headers.append('Accept', 'text/plain,application/xml') headers.append('Depth', '1') - const response = await fetch(url, { method, headers }) + const response = await fetch(url, { method, headers, credentials: 'omit' }) const status = response?.status if (status == 207) { return true @@ -62,7 +62,7 @@ export async function makeDirs(context: WebDAVContext, dirPath: string) { if (!exists) { const url = `${endpoint}/${currentPath}` const headers = authHeaders(auth) - const response = await fetch(url, { method: 'MKCOL', headers }) + const response = await fetch(url, { method: 'MKCOL', headers, credentials: 'omit' }) handleWriteResponse(response) } } @@ -72,7 +72,7 @@ export async function deleteDir(context: WebDAVContext, dirPath: string) { const { auth, endpoint } = context || {} const url = `${endpoint}/${dirPath}` const headers = authHeaders(auth) - const response = await fetchDelete(url, { headers }) + const response = await fetchDelete(url, { headers, credentials: 'omit' }) const status = response.status if (status === 403) { throw new Error("Unauthorized to delete directory") @@ -87,7 +87,7 @@ export async function writeFile(context: WebDAVContext, filePath: string, conten const headers = authHeaders(auth) headers.set("Content-Type", "application/octet-stream") const url = `${endpoint}/${filePath}` - const response = await fetch(url, { headers, method: 'put', body: content }) + const response = await fetch(url, { headers, method: 'put', body: content, credentials: 'omit' }) handleWriteResponse(response) } @@ -106,7 +106,7 @@ export async function readFile(context: WebDAVContext, filePath: string): Promis const headers = authHeaders(auth) const url = `${endpoint}/${filePath}` try { - const response = await fetchGet(url, { headers }) + const response = await fetchGet(url, { headers, credentials: 'omit' }) const status = response?.status if (status === 200) { return response.text()