Compare commits

...

23 Commits

Author SHA1 Message Date
diced 7bd477d7aa feat(v4.6.3): version 2026-06-25 20:05:04 -07:00
diced 26a16137b2 fix: build errors 2026-06-25 20:04:51 -07:00
diced d07c1fa99b feat: add copy links to multiple selections 2026-06-25 19:43:03 -07:00
Noah ae80d228b5 feat: extensionless file urls (#1109)
Co-authored-by: dicedtomato <git@diced.sh>
2026-06-25 10:41:01 -07:00
Noah b5c39bed47 fix: folders page loading with large file counts (#1085)
Co-authored-by: dicedtomato <git@diced.sh>
2026-06-24 22:07:07 -07:00
diced ca9bd41244 chore: update flake 2026-06-24 22:02:23 -07:00
diced 93f0210605 feat: add disk status and admin dashboard 2026-06-22 17:54:51 -07:00
diced 4329dc7cdf fix: cascade files & folders(#1106, #1042) 2026-06-22 15:42:43 -07:00
diced ae6a6536f9 fix: separate option to disable text view (#1099) 2026-06-22 15:42:43 -07:00
dicedtomato 0fc7e7a06f Merge commit from fork 2026-06-19 22:52:08 -07:00
zorex 18bc86c261 feat: add right-click context menu on file cards (#1105)
Co-authored-by: dicedtomato <git@diced.sh>
2026-06-14 13:16:13 -07:00
diced 2e210da549 fix: #1102 2026-06-14 13:10:56 -07:00
diced 3639ec0dc2 fix: #1104 2026-06-14 12:59:30 -07:00
diced 754c54542e feat(v4.6.2): version 2026-06-02 19:35:43 -07:00
dicedtomato 19b7e6f938 Merge commit from fork 2026-06-02 19:33:54 -07:00
dicedtomato cd22a8915e Merge commit from fork 2026-06-02 19:30:34 -07:00
zorex 97a75c0f84 feat: add user activity chart on home page (#1092)
Co-authored-by: dicedtomato <git@diced.sh>

also adds settings to hide the recents, activity graph, and file type table
2026-06-02 19:19:22 -07:00
diced d5e2bc3ec2 fix: build errors 2026-06-01 22:06:38 -07:00
diced 6f90339f17 fix: inconsistent border-radius 2026-06-01 21:41:54 -07:00
diced 833f8a30cc fix: optimize stats page 2026-06-01 18:46:18 -07:00
diced e6382b3881 fix: block thumbnails on files w/ passwords 2026-06-01 17:25:31 -07:00
diced e3789446c2 feat: reference folders by their name 2026-05-24 18:58:06 -07:00
diced 6c94abc73b feat: mimetype overhauls 2026-05-20 10:11:10 -07:00
95 changed files with 2022 additions and 1165 deletions
Generated
+65 -561
View File
@@ -19,69 +19,11 @@
]
},
"locked": {
"lastModified": 1767714506,
"narHash": "sha256-WaTs0t1CxhgxbIuvQ97OFhDTVUGd1HA+KzLZUZBhe0s=",
"lastModified": 1777487137,
"narHash": "sha256-TuvKVBX60mqyMT6OB5JqVEh1YIWtFMR/igLCaCdC9tw=",
"owner": "cachix",
"repo": "cachix",
"rev": "894c649f0daaa38bbcfb21de64be47dfa7cd0ec9",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "latest",
"repo": "cachix",
"type": "github"
}
},
"cachix_2": {
"inputs": {
"devenv": [
"devenv",
"crate2nix"
],
"flake-compat": [
"devenv",
"crate2nix"
],
"git-hooks": "git-hooks",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1767714506,
"narHash": "sha256-WaTs0t1CxhgxbIuvQ97OFhDTVUGd1HA+KzLZUZBhe0s=",
"owner": "cachix",
"repo": "cachix",
"rev": "894c649f0daaa38bbcfb21de64be47dfa7cd0ec9",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "latest",
"repo": "cachix",
"type": "github"
}
},
"cachix_3": {
"inputs": {
"devenv": [
"devenv",
"crate2nix",
"crate2nix_stable"
],
"flake-compat": [
"devenv",
"crate2nix",
"crate2nix_stable"
],
"git-hooks": "git-hooks_2",
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1767714506,
"narHash": "sha256-WaTs0t1CxhgxbIuvQ97OFhDTVUGd1HA+KzLZUZBhe0s=",
"owner": "cachix",
"repo": "cachix",
"rev": "894c649f0daaa38bbcfb21de64be47dfa7cd0ec9",
"rev": "a66a440c321d35f7193472c317f42a55ccd1cb93",
"type": "github"
},
"original": {
@@ -92,60 +34,19 @@
}
},
"crate2nix": {
"inputs": {
"cachix": "cachix_2",
"crate2nix_stable": "crate2nix_stable",
"devshell": "devshell_2",
"flake-compat": "flake-compat_2",
"flake-parts": "flake-parts_2",
"nix-test-runner": "nix-test-runner_2",
"nixpkgs": [
"devenv",
"nixpkgs"
],
"pre-commit-hooks": "pre-commit-hooks_2"
},
"flake": false,
"locked": {
"lastModified": 1773440526,
"narHash": "sha256-OcX1MYqUdoalY3/vU67PEx8m6RvqGxX0LwKonjzXn7I=",
"owner": "nix-community",
"lastModified": 1772186516,
"narHash": "sha256-8s28pzmQ6TOIUzznwFibtW1CMieMUl1rYJIxoQYor58=",
"owner": "rossng",
"repo": "crate2nix",
"rev": "e697d3049c909580128caa856ab8eb709556a97b",
"rev": "ba5dd398e31ee422fbe021767eb83b0650303a6e",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "crate2nix",
"type": "github"
}
},
"crate2nix_stable": {
"inputs": {
"cachix": "cachix_3",
"crate2nix_stable": [
"devenv",
"crate2nix",
"crate2nix_stable"
],
"devshell": "devshell",
"flake-compat": "flake-compat",
"flake-parts": "flake-parts",
"nix-test-runner": "nix-test-runner",
"nixpkgs": "nixpkgs_3",
"pre-commit-hooks": "pre-commit-hooks"
},
"locked": {
"lastModified": 1769627083,
"narHash": "sha256-SUuruvw1/moNzCZosHaa60QMTL+L9huWdsCBN6XZIic=",
"owner": "nix-community",
"repo": "crate2nix",
"rev": "7c33e664668faecf7655fa53861d7a80c9e464a2",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "0.15.0",
"owner": "rossng",
"repo": "crate2nix",
"rev": "ba5dd398e31ee422fbe021767eb83b0650303a6e",
"type": "github"
}
},
@@ -153,9 +54,10 @@
"inputs": {
"cachix": "cachix",
"crate2nix": "crate2nix",
"flake-compat": "flake-compat_3",
"flake-parts": "flake-parts_3",
"git-hooks": "git-hooks_3",
"flake-compat": "flake-compat",
"flake-parts": "flake-parts",
"ghostty": "ghostty",
"git-hooks": "git-hooks",
"nix": "nix",
"nixd": "nixd",
"nixpkgs": [
@@ -164,11 +66,11 @@
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1774134162,
"narHash": "sha256-pGjE0Agjnh8FmymDi3hiOy/pflcnbS8kpkfkL5/QKAc=",
"lastModified": 1782331842,
"narHash": "sha256-7CJ2EqNVPMq0ly39aaP6dGgdO627MqUtM/+Dm+QwNdU=",
"owner": "cachix",
"repo": "devenv",
"rev": "b24c9b58457396a9a6fe275b87555ba6e8f0a5fb",
"rev": "885e1c9d62cfa12232802de77b36aaded1ca609b",
"type": "github"
},
"original": {
@@ -189,80 +91,7 @@
"url": "file:///dev/null"
}
},
"devshell": {
"inputs": {
"nixpkgs": [
"devenv",
"crate2nix",
"crate2nix_stable",
"nixpkgs"
]
},
"locked": {
"lastModified": 1768818222,
"narHash": "sha256-460jc0+CZfyaO8+w8JNtlClB2n4ui1RbHfPTLkpwhU8=",
"owner": "numtide",
"repo": "devshell",
"rev": "255a2b1725a20d060f566e4755dbf571bbbb5f76",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"devshell_2": {
"inputs": {
"nixpkgs": [
"devenv",
"crate2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1768818222,
"narHash": "sha256-460jc0+CZfyaO8+w8JNtlClB2n4ui1RbHfPTLkpwhU8=",
"owner": "numtide",
"repo": "devshell",
"rev": "255a2b1725a20d060f566e4755dbf571bbbb5f76",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"flake-compat": {
"locked": {
"lastModified": 1733328505,
"narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=",
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
"revCount": 69,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.1.0/01948eb7-9cba-704f-bbf3-3fa956735b52/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"
}
},
"flake-compat_2": {
"locked": {
"lastModified": 1733328505,
"narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=",
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
"revCount": 69,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.1.0/01948eb7-9cba-704f-bbf3-3fa956735b52/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"
}
},
"flake-compat_3": {
"flake": false,
"locked": {
"lastModified": 1767039857,
@@ -282,17 +111,15 @@
"inputs": {
"nixpkgs-lib": [
"devenv",
"crate2nix",
"crate2nix_stable",
"nixpkgs"
]
},
"locked": {
"lastModified": 1768135262,
"narHash": "sha256-PVvu7OqHBGWN16zSi6tEmPwwHQ4rLPU9Plvs8/1TUBY=",
"lastModified": 1778716662,
"narHash": "sha256-m1Yf0wZ8j1OHjTc2UwHwyQRSnNeSgLJOd7q5Y45hzi4=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "80daad04eddbbf5a4d883996a73f3f542fa437ac",
"rev": "f7c1a2d347e4c52d5fb8d10cb4d94b5884e546fb",
"type": "github"
},
"original": {
@@ -302,58 +129,15 @@
}
},
"flake-parts_2": {
"inputs": {
"nixpkgs-lib": [
"devenv",
"crate2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1768135262,
"narHash": "sha256-PVvu7OqHBGWN16zSi6tEmPwwHQ4rLPU9Plvs8/1TUBY=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "80daad04eddbbf5a4d883996a73f3f542fa437ac",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-parts_3": {
"inputs": {
"nixpkgs-lib": [
"devenv",
"nixpkgs"
]
},
"locked": {
"lastModified": 1772408722,
"narHash": "sha256-rHuJtdcOjK7rAHpHphUb1iCvgkU3GpfvicLMwwnfMT0=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "f20dc5d9b8027381c474144ecabc9034d6a839a3",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-parts_4": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1772408722,
"narHash": "sha256-rHuJtdcOjK7rAHpHphUb1iCvgkU3GpfvicLMwwnfMT0=",
"lastModified": 1778716662,
"narHash": "sha256-m1Yf0wZ8j1OHjTc2UwHwyQRSnNeSgLJOd7q5Y45hzi4=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "f20dc5d9b8027381c474144ecabc9034d6a839a3",
"rev": "f7c1a2d347e4c52d5fb8d10cb4d94b5884e546fb",
"type": "github"
},
"original": {
@@ -362,86 +146,40 @@
"type": "github"
}
},
"ghostty": {
"flake": false,
"locked": {
"lastModified": 1779069789,
"narHash": "sha256-ojo+gso45/6CVSuqfSVnlWpQ4d0QeLgwok+v/g3yu0E=",
"owner": "ghostty-org",
"repo": "ghostty",
"rev": "4b7bf0b20e3baf9c1ba10c63f2ad1fd853faea8f",
"type": "github"
},
"original": {
"owner": "ghostty-org",
"repo": "ghostty",
"type": "github"
}
},
"git-hooks": {
"inputs": {
"flake-compat": [
"devenv",
"crate2nix",
"cachix",
"flake-compat"
],
"gitignore": "gitignore",
"nixpkgs": [
"devenv",
"crate2nix",
"cachix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1765404074,
"narHash": "sha256-+ZDU2d+vzWkEJiqprvV5PR26DVFN2vgddwG5SnPZcUM=",
"lastModified": 1778507602,
"narHash": "sha256-kTwur1wV+01SdqskVMSo6JMEpg71ps3HpbFY2GsflKs=",
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "2d6f58930fbcd82f6f9fd59fb6d13e37684ca529",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "git-hooks.nix",
"type": "github"
}
},
"git-hooks_2": {
"inputs": {
"flake-compat": [
"devenv",
"crate2nix",
"crate2nix_stable",
"cachix",
"flake-compat"
],
"gitignore": "gitignore_2",
"nixpkgs": [
"devenv",
"crate2nix",
"crate2nix_stable",
"cachix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1765404074,
"narHash": "sha256-+ZDU2d+vzWkEJiqprvV5PR26DVFN2vgddwG5SnPZcUM=",
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "2d6f58930fbcd82f6f9fd59fb6d13e37684ca529",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "git-hooks.nix",
"type": "github"
}
},
"git-hooks_3": {
"inputs": {
"flake-compat": [
"devenv",
"flake-compat"
],
"gitignore": "gitignore_5",
"nixpkgs": [
"devenv",
"nixpkgs"
]
},
"locked": {
"lastModified": 1772893680,
"narHash": "sha256-JDqZMgxUTCq85ObSaFw0HhE+lvdOre1lx9iI6vYyOEs=",
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "8baab586afc9c9b57645a734c820e4ac0a604af9",
"rev": "61ab0e80d9c7ab14c256b5b453d8b3fb0189ba0a",
"type": "github"
},
"original": {
@@ -451,102 +189,6 @@
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"devenv",
"crate2nix",
"cachix",
"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"
}
},
"gitignore_2": {
"inputs": {
"nixpkgs": [
"devenv",
"crate2nix",
"crate2nix_stable",
"cachix",
"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"
}
},
"gitignore_3": {
"inputs": {
"nixpkgs": [
"devenv",
"crate2nix",
"crate2nix_stable",
"pre-commit-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"
}
},
"gitignore_4": {
"inputs": {
"nixpkgs": [
"devenv",
"crate2nix",
"pre-commit-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"
}
},
"gitignore_5": {
"inputs": {
"nixpkgs": [
"devenv",
@@ -594,52 +236,20 @@
]
},
"locked": {
"lastModified": 1774103430,
"narHash": "sha256-MRNVInSmvhKIg3y0UdogQJXe+omvKijGszFtYpd5r9k=",
"lastModified": 1779748925,
"narHash": "sha256-meIhqGC04O5VXbKSFXSQoOKp+XCq5RMnwAk1Guo0VQo=",
"owner": "cachix",
"repo": "nix",
"rev": "e127c1c94cefe02d8ca4cca79ef66be4c527510e",
"rev": "0bc443c8ff235c3547d09327b48aaa2ab98b15f2",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "devenv-2.32",
"ref": "devenv-2.34",
"repo": "nix",
"type": "github"
}
},
"nix-test-runner": {
"flake": false,
"locked": {
"lastModified": 1588761593,
"narHash": "sha256-FKJykltAN/g3eIceJl4SfDnnyuH2jHImhMrXS2KvGIs=",
"owner": "stoeffel",
"repo": "nix-test-runner",
"rev": "c45d45b11ecef3eb9d834c3b6304c05c49b06ca2",
"type": "github"
},
"original": {
"owner": "stoeffel",
"repo": "nix-test-runner",
"type": "github"
}
},
"nix-test-runner_2": {
"flake": false,
"locked": {
"lastModified": 1588761593,
"narHash": "sha256-FKJykltAN/g3eIceJl4SfDnnyuH2jHImhMrXS2KvGIs=",
"owner": "stoeffel",
"repo": "nix-test-runner",
"rev": "c45d45b11ecef3eb9d834c3b6304c05c49b06ca2",
"type": "github"
},
"original": {
"owner": "stoeffel",
"repo": "nix-test-runner",
"type": "github"
}
},
"nixd": {
"inputs": {
"flake-parts": [
@@ -653,11 +263,11 @@
"treefmt-nix": "treefmt-nix"
},
"locked": {
"lastModified": 1773634079,
"narHash": "sha256-49qb4QNMv77VOeEux+sMd0uBhPvvHgVc0r938Bulvbo=",
"lastModified": 1778381404,
"narHash": "sha256-FqhdOTA8vyoIpkHhbs2cCT7h6EWM7nsLeOYJc1ifQLE=",
"owner": "nix-community",
"repo": "nixd",
"rev": "8ecf93d4d93745e05ea53534e8b94f5e9506e6bd",
"rev": "e3e45eb76663f522e196b7f0cf34cab201db7779",
"type": "github"
},
"original": {
@@ -667,69 +277,6 @@
}
},
"nixpkgs": {
"locked": {
"lastModified": 1765186076,
"narHash": "sha256-hM20uyap1a0M9d344I692r+ik4gTMyj60cQWO+hAYP8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "addf7cf5f383a3101ecfba091b98d0a1263dc9b8",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1772328832,
"narHash": "sha256-e+/T/pmEkLP6BHhYjx6GmwP5ivonQQn0bJdH9YrRB+Q=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "c185c7a5e5dd8f9add5b2f8ebeff00888b070742",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1765186076,
"narHash": "sha256-hM20uyap1a0M9d344I692r+ik4gTMyj60cQWO+hAYP8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "addf7cf5f383a3101ecfba091b98d0a1263dc9b8",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1769433173,
"narHash": "sha256-Gf1dFYgD344WZ3q0LPlRoWaNdNQq8kSBDLEWulRQSEs=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "13b0f9e6ac78abbbb736c635d87845c4f4bee51b",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_4": {
"locked": {
"lastModified": 1773964973,
"narHash": "sha256-NV/J+tTER0P5iJhUDL/8HO5MDjDceLQPRUYgdmy5wXw=",
@@ -745,61 +292,18 @@
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": [
"devenv",
"crate2nix",
"crate2nix_stable",
"flake-compat"
],
"gitignore": "gitignore_3",
"nixpkgs": [
"devenv",
"crate2nix",
"crate2nix_stable",
"nixpkgs"
]
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1769069492,
"narHash": "sha256-Efs3VUPelRduf3PpfPP2ovEB4CXT7vHf8W+xc49RL/U=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "a1ef738813b15cf8ec759bdff5761b027e3e1d23",
"lastModified": 1777168982,
"narHash": "sha256-GOkGPcboWE9BmGCRMLX3worL4EMnsnG8MyKmXNeYuhQ=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "f5901329dade4a6ea039af1433fb087bd9c1fe14",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"pre-commit-hooks_2": {
"inputs": {
"flake-compat": [
"devenv",
"crate2nix",
"flake-compat"
],
"gitignore": "gitignore_4",
"nixpkgs": [
"devenv",
"crate2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1769069492,
"narHash": "sha256-Efs3VUPelRduf3PpfPP2ovEB4CXT7vHf8W+xc49RL/U=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "a1ef738813b15cf8ec759bdff5761b027e3e1d23",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
@@ -807,8 +311,8 @@
"inputs": {
"devenv": "devenv",
"devenv-root": "devenv-root",
"flake-parts": "flake-parts_4",
"nixpkgs": "nixpkgs_4"
"flake-parts": "flake-parts_2",
"nixpkgs": "nixpkgs"
}
},
"rust-overlay": {
@@ -819,11 +323,11 @@
]
},
"locked": {
"lastModified": 1773630837,
"narHash": "sha256-zJhgAGnbVKeBMJOb9ctZm4BGS/Rnrz+5lfSXTVah4HQ=",
"lastModified": 1779074409,
"narHash": "sha256-6aXy8Ga41iLVM8ibddFU1O5+wYWcBGNEfZzZuL91eIc=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "f600ea449c7b5bb596fa1cf21c871cc5b9e31316",
"rev": "2a77b5b1dc952f214e8102acdef1622b68515560",
"type": "github"
},
"original": {
@@ -841,11 +345,11 @@
]
},
"locked": {
"lastModified": 1772660329,
"narHash": "sha256-IjU1FxYqm+VDe5qIOxoW+pISBlGvVApRjiw/Y/ttJzY=",
"lastModified": 1775636079,
"narHash": "sha256-pc20NRoMdiar8oPQceQT47UUZMBTiMdUuWrYu2obUP0=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "3710e0e1218041bbad640352a0440114b1e10428",
"rev": "790751ff7fd3801feeaf96d7dc416a8d581265ba",
"type": "github"
},
"original": {
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "zipline",
"private": true,
"license": "MIT",
"version": "4.6.1",
"version": "4.6.3",
"scripts": {
"build": "tsx scripts/build.ts",
"dev": "cross-env NODE_ENV=development DEBUG=zipline tsx --require ./src/dotenv.js --enable-source-maps ./src/server",
@@ -0,0 +1,5 @@
-- CreateIndex
CREATE INDEX "File_folderId_createdAt_idx" ON "public"."File"("folderId", "createdAt");
-- CreateIndex
CREATE INDEX "File_name_idx" ON "public"."File"("name");
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "public"."Zipline" ADD COLUMN "filesDisabledTypes" TEXT[] DEFAULT ARRAY[]::TEXT[],
ADD COLUMN "filesDisabledTypesDefault" TEXT;
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Zipline" ADD COLUMN "filesExtensionlessUrls" BOOLEAN NOT NULL DEFAULT false;
+6
View File
@@ -36,6 +36,8 @@ model Zipline {
filesRoute String @default("/u")
filesLength Int @default(6)
filesDefaultFormat String @default("random")
filesDisabledTypes String[] @default([])
filesDisabledTypesDefault String?
filesDisabledExtensions String[]
filesMaxFileSize String @default("100mb")
filesDefaultExpiration String?
@@ -47,6 +49,7 @@ model Zipline {
filesRandomWordsSeparator String @default("-")
filesDefaultCompressionFormat String? @default("jpg")
filesMaxFilesPerUpload Int @default(1000)
filesExtensionlessUrls Boolean @default(false)
urlsRoute String @default("/go")
urlsLength Int @default(6)
@@ -295,6 +298,9 @@ model File {
folderId String?
thumbnail Thumbnail?
@@index([name])
@@index([folderId, createdAt])
}
model Thumbnail {
@@ -0,0 +1,10 @@
import DashboardAdminHome from '@/components/pages/admin';
import { useTitle } from '@/lib/client/hooks/useTitle';
export function Component() {
useTitle('Administrator');
return <DashboardAdminHome />;
}
Component.displayName = 'Dashboard/Admin';
+1 -1
View File
@@ -47,7 +47,7 @@ export async function loader({ params, request }: { params: Params<string>; requ
function PublicFolderCard({ folder }: { folder: Partial<Folder> }) {
return (
<Link to={`/folder/${folder.id}`} style={{ textDecoration: 'none' }}>
<Card withBorder shadow='sm' radius='sm' style={{ cursor: 'pointer' }}>
<Card withBorder shadow='sm' style={{ cursor: 'pointer' }}>
<Card.Section withBorder inheritPadding py='xs'>
<Group gap='xs'>
<IconFolder size='1.2rem' />
+1
View File
@@ -77,6 +77,7 @@ export const router = createBrowserRouter([
if (!isAdministrator(user.role)) return redirect('/dashboard');
},
children: [
{ path: 'admin', lazy: () => import('./pages/dashboard/admin/index') },
{ path: 'admin/invites', lazy: () => import('./pages/dashboard/admin/invites') },
{ path: 'admin/settings/*', lazy: () => import('./pages/dashboard/admin/settings') },
{ path: 'admin/actions', lazy: () => import('./pages/dashboard/admin/actions') },
+15 -12
View File
@@ -10,7 +10,7 @@ import { isCode } from '@/lib/code';
import { config as zConfig } from '@/lib/config';
import type { Config } from '@/lib/config/validate';
import { prisma } from '@/lib/db';
import { File, fileSelect } from '@/lib/db/models/file';
import { findFileByName, File, fileSelect } from '@/lib/db/models/file';
import { User, userSelect } from '@/lib/db/models/user';
import { parseString } from '@/lib/parser';
import { parserMetrics } from '@/lib/parser/metrics';
@@ -24,17 +24,20 @@ import { createStaticHandler, createStaticRouter, StaticRouterProvider } from 'r
import { createRoutes } from './routes';
export const getFile = async (id: string) =>
prisma.file.findFirst({
where: { name: decodeURIComponent(id) },
select: {
...fileSelect,
password: true,
userId: true,
thumbnail: { select: { path: true } },
tags: { select: { id: true, name: true, color: true } },
Folder: { select: { id: true, public: true, name: true } },
},
});
findFileByName(id, (where, orderBy) =>
prisma.file.findFirst({
where,
...(orderBy && { orderBy }),
select: {
...fileSelect,
password: true,
userId: true,
thumbnail: { select: { path: true } },
tags: { select: { id: true, name: true, color: true } },
Folder: { select: { id: true, public: true, name: true } },
},
}),
);
export async function render(
{
+8
View File
@@ -5,3 +5,11 @@
font-weight: 700;
font-size: var(--mantine-font-size-xl);
}
.mantine-Table-th {
font-weight: 800;
}
.mantine-datatable {
border-radius: var(--mantine-radius-default);
}
+11 -5
View File
@@ -121,17 +121,23 @@ const navLinks: NavLinks[] = [
if: (user) => isAdministrator(user?.role),
active: (path: string) => path.startsWith('/dashboard/admin'),
links: [
{
label: 'Dashboard',
icon: <IconHome size='1rem' />,
active: (path: string) => path === '/dashboard/admin',
href: '/dashboard/admin',
},
{
label: 'Settings',
icon: <IconAdjustments size='1rem' />,
active: (path: string) => path.startsWith('/dashboard/admin/settings'),
if: (user) => user?.role === 'SUPERADMIN',
href: '/dashboard/admin/settings',
links: SETTINGS_EXTERNAL_LINKS.map(({ name, url, icon }) => ({
label: name,
icon,
active: (path: string) => path === url,
href: url,
links: SETTINGS_EXTERNAL_LINKS.map(({ label, href, icon: Icon }) => ({
label,
icon: <Icon size='1rem' />,
active: (path: string) => path === href,
href,
})),
},
{
+37
View File
@@ -0,0 +1,37 @@
import { ActionIcon, Anchor, Group, Paper, Stack, Text, Title } from '@mantine/core';
import { Link } from 'react-router-dom';
export function LinksList({
links,
}: {
links: {
label: string;
description: string;
href: string;
icon: any;
hidden?: boolean;
}[];
}) {
const visibleLinks = links.filter((link) => !link.hidden);
return (
<Stack gap='md'>
{visibleLinks.map(({ label, description, href, icon: Icon }) => (
<Anchor key={href} component={Link} to={href} style={{ textDecoration: 'none' }}>
<Paper withBorder p='sm'>
<Group gap='md'>
<ActionIcon variant='filled' radius='md' size='xl'>
<Icon size='1.75rem' />
</ActionIcon>
<div>
<Title order={4}>{label}</Title>
<Text c='dimmed'>{description}</Text>
</div>
</Group>
</Paper>
</Anchor>
))}
</Stack>
);
}
-1
View File
@@ -74,7 +74,6 @@ export default function ThemeProvider({
forceColorScheme={theme.colorScheme as unknown as any}
theme={createTheme({
...themeComponents(theme),
defaultRadius: 'md',
})}
>
{children}
+91 -87
View File
@@ -64,6 +64,96 @@ function VersionButton({ text, children, href }: { href: string; text: string; c
);
}
type VersionData = NonNullable<ReturnType<typeof useVersion>['version']>;
export function VersionInfo({ version }: { version: VersionData }) {
return (
<>
{version.isLatest && <Text>Running the latest version of Zipline.</Text>}
{version.isUpstream && (
<Text>
You are running an <b>unstable</b> version of Zipline. Upstream versions are not fully tested and
may contain bugs.
</Text>
)}
{!version.isLatest && !version.isUpstream && version.isRelease && (
<Text>
You are running an <b>outdated</b> version of Zipline. It is recommended to update to the{' '}
<Anchor href={version.latest.url}>latest version</Anchor>.
</Text>
)}
<Indicator processing position='middle-end' inline offset={-15} color='red' disabled={version.isLatest}>
<Title order={3} my='sm'>
Current Version
</Title>
</Indicator>
<DataDisplay
items={[
{
label: 'Version',
value: version.version.tag!,
href: `https://github.com/diced/zipline/releases/${version.version.tag}`,
},
{
label: 'Commit',
value: version.version.sha!.slice(0, 7)!,
href: `https://github.com/diced/zipline/commit/${version.version.sha}`,
},
{
label: 'Upstream?',
value: version.isUpstream ? 'Yes' : 'No',
color: version.isUpstream ? 'orange' : 'green',
},
]}
/>
{!version.isLatest && version.isUpstream && version.latest.commit && (
<>
<Title order={3} mt='sm'>
Latest Commit Available
</Title>
<Text c='dimmed' size='sm' mb='sm'>
This is only visible when running an upstream version.
</Text>
<DataDisplay
items={[
{
label: 'Commit',
value: version.latest.commit.sha!.slice(0, 7)!,
href: `https://github.com/diced/zipline/commit/${version.latest.commit.sha}`,
},
{
label: 'Available to update',
value: version.latest.commit.pull ? 'Yes' : 'No',
color: version.latest.commit.pull ? 'green' : 'red',
},
]}
/>
</>
)}
{!version.isLatest && version.isRelease && (
<>
<Title order={3} mt='sm'>
{version.latest.tag} is available
</Title>
<VersionButton text='Changelogs' href={version.latest.url}>
{version.latest.tag}
</VersionButton>
<VersionButton text='Update' href='https://zipline.diced.sh/docs/get-started/docker#updating'>
{version.latest.tag}
</VersionButton>
</>
)}
</>
);
}
export default function VersionBadge() {
const { version, isLoading } = useVersion();
const [opened, { open, close }] = useDisclosure(false);
@@ -74,93 +164,7 @@ export default function VersionBadge() {
return (
<>
<Modal title='Zipline Version' opened={opened} onClose={close} size='lg'>
{version.isLatest && <Text>Running the latest version of Zipline.</Text>}
{version.isUpstream && (
<Text>
You are running an <b>unstable</b> version of Zipline. Upstream versions are not fully tested and
may contain bugs.
</Text>
)}
{!version.isLatest && !version.isUpstream && version.isRelease && (
<Text>
You are running an <b>outdated</b> version of Zipline. It is recommended to update to the{' '}
<Anchor href={version.latest.url}>latest version</Anchor>.
</Text>
)}
<Indicator
processing
position='middle-end'
inline
offset={-15}
color='red'
disabled={version.isLatest}
>
<Title order={3} my='sm'>
Current Version
</Title>
</Indicator>
<DataDisplay
items={[
{
label: 'Version',
value: version.version.tag!,
href: `https://github.com/diced/zipline/releases/${version.version.tag}`,
},
{
label: 'Commit',
value: version.version.sha!.slice(0, 7)!,
href: `https://github.com/diced/zipline/commit/${version.version.sha}`,
},
{
label: 'Upstream?',
value: version.isUpstream ? 'Yes' : 'No',
color: version.isUpstream ? 'orange' : 'green',
},
]}
/>
{!version.isLatest && version.isUpstream && version.latest.commit && (
<>
<Title order={3} mt='sm'>
Latest Commit Available
</Title>
<Text c='dimmed' size='sm' mb='sm'>
This is only visible when running an upstream version.
</Text>
<DataDisplay
items={[
{
label: 'Commit',
value: version.latest.commit.sha!.slice(0, 7)!,
href: `https://github.com/diced/zipline/commit/${version.latest.commit.sha}`,
},
{
label: 'Available to update',
value: version.latest.commit.pull ? 'Yes' : 'No',
color: version.latest.commit.pull ? 'green' : 'red',
},
]}
/>
</>
)}
{!version.isLatest && version.isRelease && (
<>
<Title order={3} mt='sm'>
{version.latest.tag} is available
</Title>
<VersionButton text='Changelogs' href={version.latest.url}>
{version.latest.tag}
</VersionButton>
<VersionButton text='Update' href='https://zipline.diced.sh/docs/get-started/docker#updating'>
{version.latest.tag}
</VersionButton>
</>
)}
<VersionInfo version={version} />
</Modal>
<Tooltip label='Click to view more version information'>
+8 -9
View File
@@ -2,6 +2,7 @@ import type { File } from '@/lib/db/models/file';
import { Card } from '@mantine/core';
import { useState } from 'react';
import DashboardFileType from '../DashboardFileType';
import FileContextMenu from '../FileContextMenu';
import DashboardFileModal from './DashboardFileModal';
import styles from './index.module.css';
@@ -19,19 +20,17 @@ export default function DashboardFile({
}) {
const [open, setOpen] = useState(false);
const handleView = () => (onOpen ? onOpen(file.id) : setOpen(true));
return (
<>
{!onOpen && <DashboardFileModal open={open} setOpen={setOpen} file={file} reduce={reduce} user={id} />}
<Card
shadow='md'
radius='md'
p={0}
onClick={() => (onOpen ? onOpen(file.id) : setOpen(true))}
className={styles.file}
>
<DashboardFileType key={file.id} file={file} />
</Card>
<FileContextMenu file={file} reduce={reduce} user={id} onView={handleView}>
<Card shadow='md' radius='md' p={0} onClick={handleView} className={styles.file}>
<DashboardFileType key={file.id} file={file} />
</Card>
</FileContextMenu>
</>
);
}
+329
View File
@@ -0,0 +1,329 @@
import FolderComboboxOptions from '@/components/folders/FolderComboboxOptions';
import { useFolders } from '@/lib/client/hooks/useFolders';
import { useSettingsStore } from '@/lib/client/store/settings';
import type { File } from '@/lib/db/models/file';
import { buildFolderHierarchy } from '@/lib/folderHierarchy';
import { Box, Combobox, InputBase, Menu, ScrollArea, Text, useCombobox } from '@mantine/core';
import { useClipboard } from '@mantine/hooks';
import { modals } from '@mantine/modals';
import {
IconClipboardTypography,
IconCopy,
IconDownload,
IconExternalLink,
IconEye,
IconFolderMinus,
IconFolderSymlink,
IconPencil,
IconStar,
IconStarFilled,
IconTrashFilled,
} from '@tabler/icons-react';
import { useEffect, useMemo, useState } from 'react';
import {
addToFolder,
copyFile,
createFolderAndAdd,
deleteFile,
downloadFile,
favoriteFile,
removeFromFolder,
viewFile,
} from './actions';
import EditFileDetailsModal from './DashboardFile/EditFileDetailsModal';
const stop = (fn: () => void) => (event: React.MouseEvent) => {
event.stopPropagation();
fn();
};
function openCreateFolderModal(file: File) {
modals.openConfirmModal({
modalId: 'file-context-create-folder',
title: 'Create folder',
centered: true,
children: (
<InputBase
id='file-context-new-folder'
label='Folder name'
placeholder='My folder'
data-autofocus
onKeyDown={(event) => {
if (event.key !== 'Enter') return;
const name = event.currentTarget.value.trim();
if (!name) return;
createFolderAndAdd(file, name);
modals.closeAll();
}}
/>
),
labels: { confirm: 'Create', cancel: 'Cancel' },
onConfirm: () => {
const input = document.getElementById('file-context-new-folder') as HTMLInputElement | null;
const name = input?.value?.trim();
if (name) createFolderAndAdd(file, name);
},
});
}
export default function FileContextMenu({
file,
reduce,
user,
onView,
children,
}: {
file: File;
reduce?: boolean;
user?: string;
onView?: () => void;
children: React.ReactNode;
}) {
const [opened, setOpened] = useState(false);
const [position, setPosition] = useState({ x: 0, y: 0 });
const [editOpen, setEditOpen] = useState(false);
const clipboard = useClipboard();
const warnDeletion = useSettingsStore((state) => state.settings.warnDeletion);
const { data: folders } = useFolders(user);
const folderOptions = useMemo(() => {
if (!folders) return [];
return buildFolderHierarchy(folders);
}, [folders]);
const folderCombobox = useCombobox({
onDropdownClose: () => {
folderCombobox.resetSelectedOption();
setFolderSearch('');
},
});
const [folderSearch, setFolderSearch] = useState('');
useEffect(() => {
if (!opened) return;
const close = () => setOpened(false);
window.addEventListener('scroll', close, true);
window.addEventListener('resize', close);
return () => {
window.removeEventListener('scroll', close, true);
window.removeEventListener('resize', close);
};
}, [opened]);
const closeMenu = () => setOpened(false);
const run = (fn: () => void) => () => {
closeMenu();
fn();
};
const handleContextMenu = (event: React.MouseEvent) => {
event.preventDefault();
event.stopPropagation();
setPosition({ x: event.clientX, y: event.clientY });
setOpened(true);
};
const handleAddToFolder = async (value: string) => {
closeMenu();
folderCombobox.closeDropdown();
if (value === '$create') {
await createFolderAndAdd(file, folderSearch.trim());
} else {
await addToFolder(file, value);
}
setFolderSearch('');
};
const filteredFolders = folderOptions.filter((folder) =>
folder.path.toLowerCase().includes(folderSearch.toLowerCase().trim()),
);
return (
<>
<EditFileDetailsModal open={editOpen} onClose={() => setEditOpen(false)} file={file} />
<Box onContextMenu={handleContextMenu} style={{ display: 'contents' }}>
{children}
</Box>
<Menu
opened={opened}
onChange={setOpened}
withinPortal
shadow='md'
radius='md'
width={240}
position='bottom-start'
offset={4}
closeOnItemClick
>
<Menu.Target>
<Box
style={{
position: 'fixed',
left: position.x,
top: position.y,
width: 1,
height: 1,
padding: 0,
margin: 0,
pointerEvents: 'none',
}}
/>
</Menu.Target>
<Menu.Dropdown onClick={(event) => event.stopPropagation()}>
<Menu.Label>
<Text size='xs' fw={600} lineClamp={1}>
{file.name}
</Text>
<Text size='xs' c='dimmed' lineClamp={1}>
{file.type}
</Text>
</Menu.Label>
<Menu.Divider />
{onView && (
<Menu.Item leftSection={<IconEye size='1rem' />} onClick={stop(run(onView))}>
Open
</Menu.Item>
)}
<Menu.Item leftSection={<IconExternalLink size='1rem' />} onClick={stop(run(() => viewFile(file)))}>
Open in new tab
</Menu.Item>
<Menu.Divider />
<Menu.Item
leftSection={<IconCopy size='1rem' />}
onClick={stop(run(() => copyFile(file, clipboard)))}
>
Copy link
</Menu.Item>
<Menu.Item
leftSection={<IconClipboardTypography size='1rem' />}
onClick={stop(run(() => copyFile(file, clipboard, true)))}
>
Copy raw link
</Menu.Item>
<Menu.Item leftSection={<IconDownload size='1rem' />} onClick={stop(run(() => downloadFile(file)))}>
Download
</Menu.Item>
{!reduce && (
<>
<Menu.Divider />
<Menu.Item
leftSection={
file.favorite ? (
<IconStarFilled size='1rem' color='var(--mantine-color-yellow-5)' />
) : (
<IconStar size='1rem' />
)
}
onClick={stop(run(() => favoriteFile(file)))}
>
{file.favorite ? 'Unfavorite' : 'Favorite'}
</Menu.Item>
{file.folderId ? (
<Menu.Item
leftSection={<IconFolderMinus size='1rem' color='var(--mantine-color-red-5)' />}
onClick={stop(run(() => removeFromFolder(file)))}
>
Remove from folder
</Menu.Item>
) : (
<Menu.Sub openDelay={100} closeDelay={200}>
<Menu.Sub.Target>
<Menu.Sub.Item leftSection={<IconFolderSymlink size='1rem' />}>
Move to folder
</Menu.Sub.Item>
</Menu.Sub.Target>
<Menu.Sub.Dropdown>
<Box p='xs' w={220} onClick={(event) => event.stopPropagation()}>
<Combobox
store={folderCombobox}
onOptionSubmit={handleAddToFolder}
withinPortal={false}
>
<Combobox.Target>
<InputBase
size='xs'
placeholder='Search folders...'
value={folderSearch}
onChange={(event) => {
folderCombobox.openDropdown();
setFolderSearch(event.currentTarget.value);
}}
onClick={() => folderCombobox.openDropdown()}
onFocus={() => folderCombobox.openDropdown()}
rightSection={<Combobox.Chevron />}
rightSectionPointerEvents='none'
/>
</Combobox.Target>
<Combobox.Dropdown>
<ScrollArea.Autosize mah={200} type='scroll'>
<FolderComboboxOptions
folderOptions={filteredFolders}
searchValue={folderSearch}
additionalOptions={
!folders?.some((f) => f.name === folderSearch.trim()) &&
folderSearch.trim().length > 0 ? (
<Combobox.Option value='$create'>
+ Create &quot;{folderSearch.trim()}&quot;
</Combobox.Option>
) : null
}
/>
{!filteredFolders.length && !folderSearch.trim() && (
<Combobox.Empty px='xs' py='sm'>
<Text size='xs' c='dimmed'>
No folders yet
</Text>
</Combobox.Empty>
)}
</ScrollArea.Autosize>
</Combobox.Dropdown>
</Combobox>
<Menu.Item mt={4} onClick={stop(() => openCreateFolderModal(file))}>
+ Create new folder
</Menu.Item>
</Box>
</Menu.Sub.Dropdown>
</Menu.Sub>
)}
<Menu.Item
leftSection={<IconPencil size='1rem' />}
onClick={stop(run(() => setEditOpen(true)))}
>
Edit details
</Menu.Item>
<Menu.Divider />
<Menu.Item
color='red'
leftSection={<IconTrashFilled size='1rem' />}
onClick={stop(run(() => deleteFile(warnDeletion, file, () => {})))}
>
Delete
</Menu.Item>
</>
)}
</Menu.Dropdown>
</Menu>
</>
);
}
+1 -1
View File
@@ -33,7 +33,7 @@ export function copyFile(file: File, clipboard: ReturnType<typeof useClipboard>,
const url = raw
? getDomain(`/raw/${file.name}`)
: file.url
? getDomain(`${file.url}`)
? getDomain(file.url)
: getDomain(`/view/${file.name}`);
clipboard.copy(url);
+66
View File
@@ -0,0 +1,66 @@
import { useConfig } from '@/components/ConfigProvider';
import { LinksList } from '@/components/LinksList';
import useLogin from '@/lib/client/hooks/useLogin';
import { isAdministrator } from '@/lib/role';
import { SimpleGrid, Title } from '@mantine/core';
import { IconAdjustments, IconGraph, IconStopwatch, IconTags, IconUsersGroup } from '@tabler/icons-react';
import { Version } from './parts/Version';
import { Storage } from './parts/Storage';
export default function DashboardAdminHome() {
const { user } = useLogin();
const config = useConfig();
const adminLinks = [
{
label: 'Metrics',
description: 'Instance-wide usage graphs and statistics',
href: '/dashboard/metrics',
icon: IconGraph,
show:
config.features.metrics.enabled &&
(!config.features.metrics.adminOnly || isAdministrator(user?.role)),
},
{
label: 'Actions',
description: 'Maintenance tools and import/export',
href: '/dashboard/admin/actions',
icon: IconStopwatch,
show: true,
},
{
label: 'Users',
description: 'Manage users and quotas',
href: '/dashboard/admin/users',
icon: IconUsersGroup,
show: true,
},
{
label: 'Settings',
description: 'Server configuration',
href: '/dashboard/admin/settings',
icon: IconAdjustments,
show: user?.role === 'SUPERADMIN',
},
{
label: 'Invites',
description: 'Create and manage invite codes',
href: '/dashboard/admin/invites',
icon: IconTags,
show: config.invites.enabled,
},
];
return (
<>
<Title order={1}>Administrator</Title>
<SimpleGrid cols={{ base: 1, lg: 2 }} spacing='md' my='md'>
<Storage />
<Version />
</SimpleGrid>
<LinksList links={adminLinks} />
</>
);
}
@@ -0,0 +1,81 @@
import { Response } from '@/lib/api/response';
import { bytes } from '@/lib/bytes';
import { Button, Group, Paper, Progress, Skeleton, Stack, Text, Title, Tooltip } from '@mantine/core';
import { IconDatabase, IconRefresh } from '@tabler/icons-react';
import useSWR from 'swr';
export function Storage() {
const {
data: status,
isLoading,
error,
mutate,
} = useSWR<Response['/api/server/status']>('/api/server/status');
return (
<Paper withBorder p='md' radius='md'>
<Group justify='space-between' mb='sm'>
<Group gap='xs'>
<IconDatabase size='1.2rem' />
<Title order={3}>Storage</Title>
</Group>
<Tooltip label='Refresh storage stats'>
<Button variant='subtle' size='compact-sm' onClick={() => mutate()} loading={isLoading}>
<IconRefresh size='1rem' />
</Button>
</Tooltip>
</Group>
{isLoading ? (
<Stack gap='sm'>
<Skeleton height={18} animate />
<Skeleton height={28} animate />
<Skeleton height={12} animate />
</Stack>
) : error ? (
<Text size='sm' c='red'>
Failed to load storage
</Text>
) : status ? (
<Stack gap='sm'>
<Text size='sm' c='dimmed'>
{status.datasource === 's3' ? 'S3: ' : ''}
{status.storage.path}
</Text>
{status.storage.total != null ? (
<>
<Progress.Root size='xl'>
<Progress.Section
value={Math.min(100, (status.storage.used / status.storage.total) * 100)}
color={
status.storage.used / status.storage.total > 0.9
? 'red'
: status.storage.used / status.storage.total > 0.75
? 'orange'
: 'blue'
}
>
<Progress.Label>
{Math.round((status.storage.used / status.storage.total) * 100)}%
</Progress.Label>
</Progress.Section>
</Progress.Root>
<Text size='xs' c='dimmed' ta='right'>
{bytes(status.storage.used)} / {bytes(status.storage.total)}
</Text>
</>
) : (
<>
<Text size='xs' c='dimmed'>
{bytes(status.storage.used)} used
</Text>
</>
)}
</Stack>
) : null}
</Paper>
);
}
@@ -0,0 +1,31 @@
import { VersionInfo } from '@/components/VersionBadge';
import useVersion from '@/lib/client/hooks/useVersion';
import { Group, Paper, Skeleton, Stack, Text, Title } from '@mantine/core';
import { IconVersions } from '@tabler/icons-react';
export function Version() {
const { version, isLoading } = useVersion();
return (
<Paper withBorder p='md' radius='md'>
<Group gap='xs' mb='sm'>
<IconVersions size='1.2rem' />
<Title order={3}>Version</Title>
</Group>
{isLoading ? (
<Stack gap='sm'>
<Skeleton height={18} animate />
<Skeleton height={18} animate />
<Skeleton height={60} animate />
</Stack>
) : version ? (
<VersionInfo version={version} />
) : (
<Text size='xs' c='dimmed'>
Version information could not be loaded.
</Text>
)}
</Paper>
);
}
+120 -116
View File
@@ -3,6 +3,7 @@ import Stat from '@/components/Stat';
import type { Response } from '@/lib/api/response';
import { bytes } from '@/lib/bytes';
import useLogin from '@/lib/client/hooks/useLogin';
import { useSettingsStore } from '@/lib/client/store/settings';
import { isAdministrator } from '@/lib/role';
import { Button, Group, Paper, ScrollArea, SimpleGrid, Skeleton, Table, Text, Title } from '@mantine/core';
import {
@@ -17,11 +18,12 @@ import { lazy, Suspense } from 'react';
import { Link } from 'react-router-dom';
import useSWR from 'swr';
const DashboardFile = lazy(() => import('@/components/file/DashboardFile'));
const ActivityChart = lazy(() => import('./parts/ActivityChart'));
const Recents = lazy(() => import('./parts/Recents'));
export default function DashboardHome() {
const { user } = useLogin();
const { data: recent, isLoading: recentLoading } = useSWR<Response['/api/user/recent']>('/api/user/recent');
const { homeShowActivity, homeShowRecents, homeShowTypes } = useSettingsStore((state) => state.settings);
const { data: stats, isLoading: statsLoading } = useSWR<Response['/api/user/stats']>('/api/user/stats');
const config = useConfig();
@@ -38,6 +40,32 @@ export default function DashboardHome() {
</Text>
</Skeleton>
{homeShowRecents && (
<Suspense
fallback={
<Paper radius='md' withBorder p='md' mt='lg'>
<Skeleton height={24} width={180} mb='xs' animate />
<Skeleton height={260} mt='md' animate />
</Paper>
}
>
<Group mt='md' mb='xs' style={{ alignItems: 'center' }}>
<Title order={2}>Recent files</Title>
<Button
variant='outline'
size='compact-xs'
component={Link}
to='/dashboard/files'
leftSection={<IconFiles size='1rem' />}
>
View all files
</Button>
</Group>
<Recents />
</Suspense>
)}
{user?.quota && (user.quota.maxBytes || user.quota.maxFiles) ? (
<Text size='sm' c='dimmed'>
{user.quota.filesQuota === 'BY_BYTES' ? (
@@ -60,41 +88,9 @@ export default function DashboardHome() {
</Text>
) : null}
<Group mt='md' mb='xs' style={{ alignItems: 'center' }}>
<Title order={2}>Recent files</Title>
<Button
variant='outline'
size='compact-xs'
component={Link}
to='/dashboard/files'
leftSection={<IconFiles size='1rem' />}
>
View all files
</Button>
</Group>
{recentLoading ? (
<SimpleGrid cols={{ base: 1, md: 2, lg: 3 }} spacing={{ base: 'sm', md: 'md' }}>
{[...Array(3)].map((_, i) => (
<Skeleton key={i} height={350} animate />
))}
</SimpleGrid>
) : recent?.length !== 0 ? (
<SimpleGrid cols={{ base: 1, md: 2, lg: 3 }} spacing={{ base: 'sm', md: 'md' }}>
{recent!.map((file, i) => (
<Suspense fallback={<Skeleton height={350} animate />} key={i}>
<DashboardFile file={file} />
</Suspense>
))}
</SimpleGrid>
) : (
<Text size='sm' c='dimmed'>
You have no recent files. The last three files you uploaded will appear here.
</Text>
)}
<Group mt='md' style={{ alignItems: 'center' }}>
<Title order={2}>Stats</Title>
{(!config.features?.metrics?.adminOnly || isAdministrator(user?.role)) && (
<Button
variant='outline'
@@ -113,90 +109,98 @@ export default function DashboardHome() {
</Text>
{statsLoading ? (
<>
<SimpleGrid cols={{ base: 1, md: 2, lg: 4 }} spacing={{ base: 'sm', md: 'md' }}>
{[...Array(8)].map((_, i) => (
<Skeleton key={i} height={105} />
))}
</SimpleGrid>
<Title order={3} mt='lg' mb='xs'>
File types
</Title>
<Paper radius='sm' withBorder>
<ScrollArea.Autosize mah={400} type='auto'>
<Table highlightOnHover>
<Table.Thead>
<Table.Tr>
<Table.Th>File Type</Table.Th>
<Table.Th>Count</Table.Th>
</Table.Tr>
</Table.Thead>
<Table.Tbody>
{[...Array(5)].map((_, i) => (
<Table.Tr key={i}>
<Table.Td>
<Skeleton animate>
<Text>...</Text>
</Skeleton>
</Table.Td>
<Table.Td>
<Skeleton animate>
<Text>...</Text>
</Skeleton>
</Table.Td>
</Table.Tr>
))}
</Table.Tbody>
</Table>
</ScrollArea.Autosize>
</Paper>
</>
<SimpleGrid cols={{ base: 1, md: 2, lg: 4 }} spacing={{ base: 'sm', md: 'md' }}>
{[...Array(8)].map((_, i) => (
<Skeleton key={i} height={105} />
))}
</SimpleGrid>
) : (
<>
<SimpleGrid cols={{ base: 1, md: 2, lg: 4 }} spacing={{ base: 'sm', md: 'md' }}>
<Stat Icon={IconFiles} title='Files uploaded' value={stats!.filesUploaded} />
<Stat Icon={IconStarFilled} title='Favorite files' value={stats!.favoriteFiles} />
<Stat Icon={IconDeviceSdCard} title='Storage used' value={bytes(stats!.storageUsed)} />
<Stat Icon={IconDeviceSdCard} title='Average storage used' value={bytes(stats!.avgStorageUsed)} />
<Stat Icon={IconEyeFilled} title='File views' value={stats!.views} />
<Stat Icon={IconEyeFilled} title='Average file views' value={Math.round(stats!.avgViews)} />
<SimpleGrid cols={{ base: 1, md: 2, lg: 4 }} spacing={{ base: 'sm', md: 'md' }}>
<Stat Icon={IconFiles} title='Files uploaded' value={stats!.filesUploaded} />
<Stat Icon={IconStarFilled} title='Favorite files' value={stats!.favoriteFiles} />
<Stat Icon={IconDeviceSdCard} title='Storage used' value={bytes(stats!.storageUsed)} />
<Stat Icon={IconDeviceSdCard} title='Average storage used' value={bytes(stats!.avgStorageUsed)} />
<Stat Icon={IconEyeFilled} title='File views' value={stats!.views} />
<Stat Icon={IconEyeFilled} title='Average file views' value={Math.round(stats!.avgViews)} />
<Stat Icon={IconLink} title='Links created' value={stats!.urlsCreated} />
<Stat Icon={IconLink} title='Total link views' value={Math.round(stats!.urlViews)} />
</SimpleGrid>
<Stat Icon={IconLink} title='Links created' value={stats!.urlsCreated} />
<Stat Icon={IconLink} title='Total link views' value={Math.round(stats!.urlViews)} />
</SimpleGrid>
)}
{Object.keys(stats!.sortTypeCount).length !== 0 && (
<>
<Title order={3} mt='lg' mb='xs'>
File types
</Title>
<Paper radius='sm' withBorder>
<ScrollArea.Autosize mah={400} type='auto'>
<Table highlightOnHover>
<Table.Thead>
<Table.Tr>
<Table.Th>File Type</Table.Th>
<Table.Th>Count</Table.Th>
</Table.Tr>
</Table.Thead>
<Table.Tbody>
{Object.entries(stats!.sortTypeCount)
.sort(([, a], [, b]) => b - a)
.map(([type, count], i) => (
<Table.Tr key={i}>
<Table.Td>{type}</Table.Td>
<Table.Td>{count}</Table.Td>
</Table.Tr>
))}
</Table.Tbody>
</Table>
</ScrollArea.Autosize>
</Paper>
</>
)}
</>
{homeShowActivity && (
<Suspense
fallback={
<Paper radius='md' withBorder p='md' mt='lg'>
<Skeleton height={24} width={180} mb='xs' animate />
<Skeleton height={260} mt='md' animate />
</Paper>
}
>
<ActivityChart />
</Suspense>
)}
{statsLoading ? (
<Paper withBorder my='md'>
<ScrollArea.Autosize mah={400} type='auto'>
<Table highlightOnHover>
<Table.Thead>
<Table.Tr>
<Table.Th>File Type</Table.Th>
<Table.Th>Count</Table.Th>
</Table.Tr>
</Table.Thead>
<Table.Tbody>
{[...Array(5)].map((_, i) => (
<Table.Tr key={i}>
<Table.Td>
<Skeleton animate>
<Text>...</Text>
</Skeleton>
</Table.Td>
<Table.Td>
<Skeleton animate>
<Text>...</Text>
</Skeleton>
</Table.Td>
</Table.Tr>
))}
</Table.Tbody>
</Table>
</ScrollArea.Autosize>
</Paper>
) : (
Object.keys(stats!.sortTypeCount).length !== 0 &&
homeShowTypes && (
<>
<Title order={3} mt='lg' mb='xs'>
File types
</Title>
<Paper withBorder my='md'>
<ScrollArea.Autosize mah={400} type='auto'>
<Table highlightOnHover>
<Table.Thead>
<Table.Tr>
<Table.Th>File Type</Table.Th>
<Table.Th>Count</Table.Th>
</Table.Tr>
</Table.Thead>
<Table.Tbody>
{Object.entries(stats!.sortTypeCount)
.sort(([, a], [, b]) => b - a)
.map(([type, count], i) => (
<Table.Tr key={i}>
<Table.Td>{type}</Table.Td>
<Table.Td>{count}</Table.Td>
</Table.Tr>
))}
</Table.Tbody>
</Table>
</ScrollArea.Autosize>
</Paper>
</>
)
)}
</>
);
@@ -0,0 +1,204 @@
import type { Response } from '@/lib/api/response';
import { ChartTooltip, LineChart } from '@mantine/charts';
import { Box, Group, Paper, Select, Skeleton, Text, Title } from '@mantine/core';
import { IconChartAreaLine, IconLogin2, IconUpload } from '@tabler/icons-react';
import dayjs from 'dayjs';
import { useState } from 'react';
import useSWR from 'swr';
const CHART_HEIGHT = 260;
function parseChartDate(value: unknown): dayjs.Dayjs | null {
if (value == null || value === '') return null;
if (typeof value === 'number' && Number.isFinite(value)) {
const d = dayjs(value);
return d.isValid() ? d : null;
}
if (typeof value === 'string') {
const d = dayjs(value);
return d.isValid() ? d : null;
}
return null;
}
function formatDayLabel(value: unknown) {
const d = parseChartDate(value);
if (!d) return '';
const today = dayjs().startOf('day');
if (d.isSame(today, 'day')) return 'Today';
if (d.isSame(today.subtract(1, 'day'), 'day')) return 'Yesterday';
return d.format('MMM D');
}
export default function ActivityChart() {
const [days, setDays] = useState(14);
const { data, isLoading } = useSWR<Response['/api/user/activity']>('/api/user/activity?days=' + days);
if (isLoading) {
return (
<Paper radius='md' withBorder p='md' mt='lg'>
<Skeleton height={24} width={180} mb='xs' animate />
<Skeleton height={16} width={240} mb='lg' animate />
<Skeleton height={CHART_HEIGHT} animate />
</Paper>
);
}
if (!data?.series.length) return null;
const chartData = data.series
.map((point) => {
const d = dayjs(point.date);
if (!d.isValid()) return null;
return {
date: d.valueOf(),
uploads: point.uploads,
logins: point.logins,
};
})
.filter((point) => point !== null);
if (chartData.length === 0) return null;
const hasActivity = data.totals.uploads > 0 || data.totals.logins > 0;
return (
<Paper radius='md' withBorder p='md' mt='lg'>
<Group justify='space-between' align='flex-start' mb='lg' wrap='nowrap'>
<Box>
<Title order={3} fw={600}>
Activity
</Title>
<Group gap='xs' style={{ alignItems: 'center' }}>
<Text size='sm' c='dimmed' mt={4}>
Your uploads and logins over the last{' '}
</Text>
<Select
value={String(days)}
onChange={(v) => setDays(Number(v))}
data={[
{ value: '1', label: '1 day' },
{ value: '7', label: '7 days' },
{ value: '14', label: '14 days' },
{ value: '30', label: '30 days' },
]}
size='0.4rem'
variant='filled'
p={0}
m={0}
fw={500}
styles={{
input: {
color: 'var(--mantine-primary-color-filled)',
padding: 10,
width: '10em',
fontSize: '0.875rem',
},
section: {
margin: 0,
},
option: {
fontSize: '1rem',
},
wrapper: {
borderRadius: 1,
},
}}
comboboxProps={{
dropdownPadding: 0,
}}
/>
</Group>
</Box>
<Group gap='lg' visibleFrom='sm'>
<Group gap='xs'>
<IconUpload size='1rem' style={{ opacity: 0.85 }} color='var(--mantine-primary-color-filled)' />
<Box>
<Text size='xs' c='dimmed' lh={1.2}>
Uploads
</Text>
<Text size='sm' fw={600} lh={1.3}>
{data.totals.uploads}
</Text>
</Box>
</Group>
<Group gap='xs'>
<IconLogin2 size='1rem' style={{ opacity: 0.65 }} color='var(--mantine-color-gray-5)' />
<Box>
<Text size='xs' c='dimmed' lh={1.2}>
Logins
</Text>
<Text size='sm' fw={600} lh={1.3}>
{data.totals.logins}
</Text>
</Box>
</Group>
</Group>
</Group>
{!hasActivity ? (
<Paper withBorder h={CHART_HEIGHT} radius='md' p='md' ta='center'>
<Group align='center' justify='center' h='100%'>
<IconChartAreaLine size='1.75rem' style={{ opacity: 0.35 }} />
<Text size='sm' c='dimmed'>
No uploads or logins in this period yet
</Text>
</Group>
</Paper>
) : (
<LineChart
h={CHART_HEIGHT}
data={chartData}
dataKey='date'
curveType='natural'
connectNulls
withLegend={false}
withDots={false}
activeDotProps={{ r: 4, strokeWidth: 2 }}
gridAxis='none'
tickLine='none'
strokeWidth={2}
series={[
{
name: 'uploads',
label: 'Uploads',
color: 'var(--mantine-primary-color-filled)',
},
{
name: 'logins',
label: 'Logins',
color: 'gray.5',
},
]}
xAxisProps={{
tickMargin: 12,
minTickGap: 32,
tickFormatter: (v) => formatDayLabel(v),
}}
yAxisProps={{
width: 36,
tickMargin: 8,
}}
tooltipProps={{
content: ({ label, payload }) => (
<ChartTooltip
label={formatDayLabel(label) || '—'}
payload={payload}
series={[
{ name: 'uploads', label: 'Uploads', color: 'var(--mantine-primary-color-filled)' },
{ name: 'logins', label: 'Logins', color: 'gray.5' },
]}
/>
),
}}
/>
)}
</Paper>
);
}
@@ -0,0 +1,36 @@
import { Response } from '@/lib/api/response';
import { SimpleGrid, Skeleton, Text } from '@mantine/core';
import { lazy, Suspense } from 'react';
import useSWR from 'swr';
const DashboardFile = lazy(() => import('@/components/file/DashboardFile'));
export default function Recents() {
const { data, isLoading } = useSWR<Response['/api/user/recent']>('/api/user/recent');
if (isLoading)
return (
<SimpleGrid cols={{ base: 1, md: 2, lg: 3 }} spacing={{ base: 'sm', md: 'md' }}>
{[...Array(3)].map((_, i) => (
<Skeleton key={i} height={350} animate />
))}
</SimpleGrid>
);
if (data?.length)
return (
<SimpleGrid cols={{ base: 1, md: 2, lg: 3 }} spacing={{ base: 'sm', md: 'md' }}>
{data!.map((file, i) => (
<Suspense fallback={<Skeleton height={350} animate />} key={i}>
<DashboardFile file={file} />
</Suspense>
))}
</SimpleGrid>
);
return (
<Text size='sm' c='dimmed'>
You have no recent files. The last three files you uploaded will appear here.
</Text>
);
}
+23 -2
View File
@@ -1,10 +1,17 @@
import { mutateFiles } from '@/components/file/actions';
import { Response } from '@/lib/api/response';
import { File } from '@/lib/db/models/file';
import { getDomain } from '@/lib/client/webDomain';
import type { File } from '@/lib/db/models/file';
import { fetchApi } from '@/lib/fetchApi';
import { modals } from '@mantine/modals';
import { notifications } from '@mantine/notifications';
import { IconFilesOff, IconStarsFilled, IconStarsOff, IconTrashFilled } from '@tabler/icons-react';
import {
IconClipboardListFilled,
IconFilesOff,
IconStarsFilled,
IconStarsOff,
IconTrashFilled,
} from '@tabler/icons-react';
export async function bulkDelete(ids: string[], setSelectedFiles: (files: File[]) => void) {
modals.openConfirmModal({
@@ -130,3 +137,17 @@ export async function bulkFavorite(ids: string[], favorite: boolean) {
onCancel: modals.closeAll,
});
}
export async function bulkCopyLinks(urls: string[]) {
const links = urls.map((url) => getDomain(url)).join('\n');
await navigator.clipboard.writeText(links);
notifications.show({
title: 'Copied links to clipboard',
message: `Copied ${urls.length} link${urls.length === 1 ? '' : 's'} to clipboard`,
color: 'green',
icon: <IconClipboardListFilled size='1rem' />,
autoClose: true,
});
}
@@ -82,7 +82,7 @@ export default function CreateTagModal({ open, onClose }: { open: boolean; onClo
{...form.getInputProps('color')}
/>
<Button type='submit' variant='outline' radius='sm'>
<Button type='submit' variant='outline'>
Create tag
</Button>
</Stack>
@@ -99,7 +99,7 @@ export default function EditTagModal({
{...form.getInputProps('color')}
/>
<Button type='submit' variant='outline' radius='sm' disabled={!form.isDirty}>
<Button type='submit' variant='outline' disabled={!form.isDirty}>
Edit tag
</Button>
</Stack>
@@ -47,7 +47,7 @@ import useSWR from 'swr';
import { useShallow } from 'zustand/shallow';
import { DashboardFilesModals, DashboardFilesModalsUpdate } from '..';
import TableEditModal from '../TableEditModal';
import { bulkDelete, bulkFavorite } from '../bulk';
import { bulkCopyLinks, bulkDelete, bulkFavorite } from '../bulk';
import TagPill from '../tags/TagPill';
import { useApiPagination } from '../useApiPagination';
@@ -399,7 +399,8 @@ export default function FileTable({
<Collapse expanded={selectedFiles.length > 0}>
<Paper withBorder p='sm' my='sm'>
<Text size='sm' c='dimmed' mb='xs'>
Selections are saved across page changes
Selections are saved across page changes. Currently selected <b>{selectedFiles.length}</b> file
{selectedFiles.length > 1 ? 's' : ''}.
</Text>
<Group>
@@ -415,7 +416,7 @@ export default function FileTable({
)
}
>
Delete {selectedFiles.length} file{selectedFiles.length > 1 ? 's' : ''}
Delete files
</Button>
<Button
@@ -429,8 +430,15 @@ export default function FileTable({
)
}
>
{unfavoriteAll ? 'Unfavorite' : 'Favorite'} {selectedFiles.length} file
{selectedFiles.length > 1 ? 's' : ''}
{unfavoriteAll ? 'Unfavorite' : 'Favorite'} files
</Button>
<Button
variant='outline'
leftSection={<IconCopy size='1rem' />}
onClick={() => bulkCopyLinks(selectedFiles.map((x) => x.url!))}
>
Copy file links
</Button>
{!id && (
@@ -508,7 +516,6 @@ export default function FileTable({
{/*@ts-ignore*/}
<DataTable
mt='xs'
borderRadius='sm'
withTableBorder
minHeight={200}
records={data?.page ?? []}
+1 -1
View File
@@ -48,7 +48,7 @@ export default function FolderCard({
<MoveFolderModal folder={folder} opened={moveOpen} onClose={() => setMoveOpen(false)} />
<DeleteFolderModal opened={deleteOpen} folder={folder} onClose={() => setDeleteOpen(false)} />
<Card withBorder shadow='sm' radius='sm' style={{ cursor: onNavigate ? 'pointer' : 'default' }}>
<Card withBorder shadow='sm' style={{ cursor: onNavigate ? 'pointer' : 'default' }}>
<Card.Section withBorder inheritPadding py='xs' onClick={() => onNavigate?.(folder.id)}>
<Group justify='space-between'>
<Group gap='xs'>
+2 -2
View File
@@ -55,7 +55,7 @@ export default function DashboardFolders() {
data: currentFolder,
error: currentFolderError,
isLoading,
} = useSWR<Folder>(currentFolderId ? `/api/user/folders/${currentFolderId}` : null);
} = useSWR<Folder>(currentFolderId ? `/api/user/folders/${currentFolderId}?noincl=true` : null);
const form = useForm({
initialValues: {
@@ -158,7 +158,7 @@ export default function DashboardFolders() {
{...form.getInputProps('isPublic', { type: 'checkbox' })}
/>
<Button type='submit' variant='outline' radius='sm' leftSection={<IconFolderPlus size='1rem' />}>
<Button type='submit' variant='outline' leftSection={<IconFolderPlus size='1rem' />}>
Create
</Button>
</Stack>
@@ -3,6 +3,7 @@ import { Response } from '@/lib/api/response';
import { Folder } from '@/lib/db/models/folder';
import { fetchApi } from '@/lib/fetchApi';
import { buildFolderHierarchy } from '@/lib/folderHierarchy';
import { openWarningModal } from '@/lib/client/warningModal';
import { useFolders } from '@/lib/client/hooks/useFolders';
import { Button, Combobox, InputBase, Modal, Radio, Stack, Text, useCombobox } from '@mantine/core';
import { notifications } from '@mantine/notifications';
@@ -10,7 +11,7 @@ import { IconTrashFilled } from '@tabler/icons-react';
import { useMemo, useState } from 'react';
import { mutateFolder } from '../actions';
type ChildrenAction = 'root' | 'folder' | 'cascade';
type ChildrenAction = 'root' | 'folder' | 'cascade' | 'cascade-files';
export default function DeleteFolderModal({
folder,
@@ -47,29 +48,9 @@ export default function DeleteFolderModal({
return selected?.path || '';
};
const handleDelete = async () => {
const performDelete = async (body: any) => {
setLoading(true);
const body: any = {
delete: 'folder',
};
if (hasContent) {
body.childrenAction = childrenAction;
if (childrenAction === 'folder') {
if (!targetFolderId) {
notifications.show({
title: 'No folder selected',
message: 'Please select a folder to move contents to',
color: 'red',
});
setLoading(false);
return;
}
body.targetFolderId = targetFolderId;
}
}
const { error } = await fetchApi<Response['/api/user/folders/[id]']>(
`/api/user/folders/${folder.id}`,
'DELETE',
@@ -95,6 +76,46 @@ export default function DeleteFolderModal({
}
};
const handleDelete = async () => {
const body: any = {
delete: 'folder',
};
if (hasContent) {
body.childrenAction = childrenAction;
if (childrenAction === 'folder') {
if (!targetFolderId) {
notifications.show({
title: 'No folder selected',
message: 'Please select a folder to move contents to',
color: 'red',
});
return;
}
body.targetFolderId = targetFolderId;
}
}
if (hasContent && (childrenAction === 'cascade' || childrenAction === 'cascade-files')) {
openWarningModal({
confirmLabel: `Delete '${folder.name}' and ${childrenAction === 'cascade-files' ? 'all subfolders and files' : 'all subfolders'}?`,
message: (
<Stack gap='sm'>
<Text c='red' fw={500}>
{childrenAction === 'cascade-files'
? 'All subfolders and every file within them will be permanently deleted from storage. This action cannot be undone.'
: 'All subfolders will be permanently deleted (files will be moved to the root). This action cannot be undone.'}
</Text>
</Stack>
),
onConfirm: () => performDelete(body),
});
return;
}
await performDelete(body);
};
return (
<Modal centered opened={opened} onClose={onClose} title={`Delete "${folder.name}"?`}>
<Stack gap='sm'>
@@ -118,7 +139,15 @@ export default function DeleteFolderModal({
value='cascade'
label={
<Text size='sm' c='red'>
Delete everything (cascade delete)
Delete subfolders (files moved to root)
</Text>
}
/>
<Radio
value='cascade-files'
label={
<Text size='sm' c='red'>
Delete subfolders and their files (cascade delete)
</Text>
}
/>
@@ -171,8 +200,15 @@ export default function DeleteFolderModal({
{childrenAction === 'cascade' && (
<Text size='sm' c='red' fw={500}>
Warning: This will permanently delete all contents within this folder (subfolders will be
deleted, and files will be unlinked from their folders).
Warning: This will permanently delete all subfolders within this folder. Files will be
unlinked from their folders and moved to the root.
</Text>
)}
{childrenAction === 'cascade-files' && (
<Text size='sm' c='red' fw={500}>
Warning: This will permanently delete all subfolders within this folder, along with every file
contained in them. The files will be removed from storage and cannot be recovered.
</Text>
)}
</>
@@ -12,7 +12,7 @@ export default function FolderGridView({
currentFolderId: string | null;
onNavigate: (folderId: string | null) => void;
}) {
const queryParam = currentFolderId ? `?parentId=${currentFolderId}` : '?root=true';
const queryParam = currentFolderId ? `?parentId=${currentFolderId}&noincl=true` : '?root=true&noincl=true';
const { data: folders, isLoading } = useSWR<Extract<Response['/api/user/folders'], Folder[]>>(
`/api/user/folders${queryParam}`,
);
@@ -119,7 +119,7 @@ export default function FolderTableView({
}) {
const clipboard = useClipboard();
const queryParam = currentFolderId ? `?parentId=${currentFolderId}` : '?root=true';
const queryParam = currentFolderId ? `?parentId=${currentFolderId}&noincl=true` : '?root=true&noincl=true';
const { data, isLoading } = useSWR<Extract<Response['/api/user/folders'], Folder[]>>(
`/api/user/folders${queryParam}`,
);
@@ -168,7 +168,6 @@ export default function FolderTableView({
<Box my='sm'>
<DataTable
borderRadius='sm'
withTableBorder
minHeight={200}
records={sorted ?? []}
+1 -1
View File
@@ -19,7 +19,7 @@ export default function InviteCard({
return (
<>
<Card withBorder shadow='sm' radius='sm'>
<Card withBorder shadow='sm'>
<Card.Section withBorder inheritPadding py='xs'>
<Group justify='space-between'>
<Anchor href={`/invite/${invite.code}`} target='_blank' fw={400}>
+1 -7
View File
@@ -96,13 +96,7 @@ export default function DashboardInvites() {
{...form.getInputProps('maxUses')}
/>
<Button
type='submit'
variant='outline'
fullWidth
radius='sm'
leftSection={<IconPlus size='1rem' />}
>
<Button type='submit' variant='outline' fullWidth leftSection={<IconPlus size='1rem' />}>
Create
</Button>
</Stack>
@@ -49,7 +49,6 @@ export default function InviteTableView() {
<Box my='sm'>
<DataTable
borderRadius='sm'
withTableBorder
minHeight={200}
records={sorted ?? []}
+4 -1
View File
@@ -1,4 +1,5 @@
import { Modal, Center, PinInput, Text, Group, Button } from '@mantine/core';
import { useMediaQuery } from '@mantine/hooks';
import { IconX, IconShieldQuestion } from '@tabler/icons-react';
export default function TotpModal({
@@ -12,6 +13,8 @@ export default function TotpModal({
onVerify: () => void;
onCancel: () => void;
}) {
const mobile = useMediaQuery('(max-width: 600px)');
return (
<Modal onClose={onCancel} title='Enter code' opened={state.open} withCloseButton={false}>
<form onSubmit={onVerify}>
@@ -23,7 +26,7 @@ export default function TotpModal({
onChange={onPinChange}
error={!!state.error}
disabled={state.disabled}
size='xl'
size={mobile ? 'md' : 'xl'}
autoFocus
/>
</Center>
+7 -7
View File
@@ -3,11 +3,11 @@ import { DatePicker } from '@mantine/dates';
import { IconCalendarSearch, IconCalendarTime } from '@tabler/icons-react';
import dayjs from 'dayjs';
import { lazy, useState } from 'react';
import FilesUrlsCountGraph from './parts/FilesUrlsCountGraph';
import { StatsCardsSkeleton } from './parts/StatsCards';
import { StatsTablesSkeleton } from './parts/StatsTables';
import { useApiStats } from './useStats';
const FilesUrlsCountGraph = lazy(() => import('./parts/FilesUrlsCountGraph'));
const StorageGraph = lazy(() => import('./parts/StorageGraph'));
const ViewsGraph = lazy(() => import('./parts/ViewsGraph'));
const StatsCards = lazy(() => import('./parts/StatsCards'));
@@ -133,16 +133,16 @@ export default function DashboardMetrics() {
<StatsCardsSkeleton />
<StatsTablesSkeleton />
</div>
) : data?.length ? (
) : data?.points.length ? (
<div>
<StatsCards data={data} />
<StatsTables data={data} />
<StatsCards points={data.points} />
<StatsTables latest={data.latest} />
<SimpleGrid mt='md' cols={{ base: 1, md: 2 }}>
<FilesUrlsCountGraph metrics={data} />
<ViewsGraph metrics={data} />
<FilesUrlsCountGraph points={data.points} />
<ViewsGraph points={data.points} />
</SimpleGrid>
<div>
<StorageGraph metrics={data} />
<StorageGraph points={data.points} />
</div>
</div>
) : (
@@ -1,23 +1,28 @@
import { Metric } from '@/lib/db/models/metric';
import { MetricsPoint } from '@/lib/metrics';
import { ChartTooltip, LineChart } from '@mantine/charts';
import { Paper, Title } from '@mantine/core';
import { useMemo } from 'react';
import { defaultChartProps } from '../statsHelpers';
export default function FilesUrlsCountGraph({ metrics }: { metrics: Metric[] }) {
const sortedMetrics = metrics.sort(
(a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime(),
export default function FilesUrlsCountGraph({ points }: { points: MetricsPoint[] }) {
const data = useMemo(
() =>
points
.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime())
.map((point) => ({
date: new Date(point.createdAt).getTime(),
files: point.files,
urls: point.urls,
})),
[points],
);
return (
<Paper radius='sm' withBorder p='sm'>
<Paper radius='md' withBorder p='sm'>
<Title order={3}>Count</Title>
<LineChart
data={sortedMetrics.map((metric) => ({
date: new Date(metric.createdAt).getTime(),
files: metric.data.files,
urls: metric.data.urls,
}))}
data={data}
series={[
{
name: 'files',
@@ -1,5 +1,5 @@
import { bytes } from '@/lib/bytes';
import { Metric } from '@/lib/db/models/metric';
import { MetricsPoint } from '@/lib/metrics';
import { Group, Paper, rgba, SimpleGrid, Skeleton, Text } from '@mantine/core';
import {
IconArrowDown,
@@ -21,8 +21,8 @@ function StatCard({
Icon,
}: {
title: string;
first: number;
last: number;
first: number | bigint;
last: number | bigint;
Icon: TablerIcon;
formatter?: (value: number) => string;
}) {
@@ -35,9 +35,9 @@ function StatCard({
}[color];
return (
<Paper radius='sm' withBorder p='sm'>
<Paper radius='md' withBorder p='sm'>
<Group justify='space-between'>
<Text size='xl' fw='bolder'>
<Text size='xl' fw={900}>
{title}
</Text>
@@ -45,8 +45,8 @@ function StatCard({
</Group>
<Group justify='flex-start' gap='xs'>
<Text size='xl' fw='bolder'>
{formatter ? formatter(first) : first}
<Text size='lg' fw={600}>
{formatter ? formatter(Number(first)) : first}
</Text>
<Paper
@@ -54,7 +54,6 @@ function StatCard({
py={2}
pl={5}
pr={8}
radius='sm'
display='flex'
bg={rgba(`var(--mantine-color-${color}-6)`, 0.25)}
>
@@ -87,14 +86,11 @@ export function StatsCardsSkeleton() {
);
}
export default function StatsCards({ data }: { data: Metric[] }) {
if (!data.length) return null;
const sortedMetrics = data.sort(
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
);
export default function StatsCards({ points }: { points: MetricsPoint[] }) {
if (!points.length) return null;
const recent = sortedMetrics[0];
const last = sortedMetrics[sortedMetrics.length - 1];
const recent = points[0];
const last = points[points.length - 1];
return (
<SimpleGrid
@@ -105,28 +101,18 @@ export default function StatsCards({ data }: { data: Metric[] }) {
}}
mb='sm'
>
<StatCard title='Files' first={recent.data.files} last={last.data.files} Icon={IconFiles} />
<StatCard title='URLs' first={recent.data.urls} last={last.data.urls} Icon={IconLink} />
<StatCard title='Files' first={recent.files} last={last.files} Icon={IconFiles} />
<StatCard title='URLs' first={recent.urls} last={last.urls} Icon={IconLink} />
<StatCard
title='Storage Used'
first={recent.data.storage}
last={last.data.storage}
first={recent.storage}
last={last.storage}
formatter={bytes}
Icon={IconDatabase}
/>
<StatCard title='Users' first={recent.data.users} last={last.data.users} Icon={IconUsers} />
<StatCard
title='File Views'
first={recent.data.fileViews}
last={last.data.fileViews}
Icon={IconEyeFilled}
/>
<StatCard
title='URL Views'
first={recent.data.urlViews}
last={last.data.urlViews}
Icon={IconEyeFilled}
/>
<StatCard title='Users' first={recent.users} last={last.users} Icon={IconUsers} />
<StatCard title='File Views' first={recent.fileViews} last={last.fileViews} Icon={IconEyeFilled} />
<StatCard title='URL Views' first={recent.urlViews} last={last.urlViews} Icon={IconEyeFilled} />
</SimpleGrid>
);
}
@@ -17,7 +17,7 @@ export function StatsTablesSkeleton() {
return (
<>
<SimpleGrid cols={{ base: 1, md: 2 }}>
<Paper radius='sm' withBorder>
<Paper radius='md' withBorder>
<ScrollArea.Autosize mah={500} type='auto'>
<Table highlightOnHover stickyHeader>
<Table.Thead>
@@ -42,7 +42,7 @@ export function StatsTablesSkeleton() {
</ScrollArea.Autosize>
</Paper>
<Paper radius='sm' withBorder mah={500}>
<Paper withBorder mah={500} radius='md'>
<ScrollArea.Autosize mah={500} type='auto'>
<Table highlightOnHover stickyHeader>
<Table.Thead>
@@ -65,7 +65,7 @@ export function StatsTablesSkeleton() {
</ScrollArea.Autosize>
</Paper>
<Paper radius='sm' withBorder>
<Paper withBorder radius='md'>
<ScrollArea.Autosize mah={500} type='auto'>
<Table highlightOnHover stickyHeader>
<Table.Thead>
@@ -86,7 +86,7 @@ export function StatsTablesSkeleton() {
</ScrollArea.Autosize>
</Paper>
<Paper radius='sm' withBorder p='sm'>
<Paper withBorder p='sm'>
<Skeleton height={500} />
</Paper>
</SimpleGrid>
@@ -94,18 +94,18 @@ export function StatsTablesSkeleton() {
);
}
export default function StatsTables({ data }: { data: Metric[] }) {
if (!data.length) return null;
export default function StatsTables({ latest }: { latest: Metric | null }) {
if (!latest) return null;
const recent = data[0]; // it is sorted by desc so 0 is the first one.
const recent = latest;
if (recent.data.filesUsers.length === 0 || recent.data.urlsUsers.length === 0) return null;
return (
<>
<SimpleGrid cols={{ base: 1, md: 2 }}>
<Paper radius='sm' withBorder>
<ScrollArea.Autosize mah={500} type='auto'>
<Paper radius='md' withBorder>
<ScrollArea.Autosize mah={500} type='auto' bdrs='md'>
<Table highlightOnHover stickyHeader>
<Table.Thead>
<Table.Tr>
@@ -131,8 +131,8 @@ export default function StatsTables({ data }: { data: Metric[] }) {
</ScrollArea.Autosize>
</Paper>
<Paper radius='sm' withBorder mah={500}>
<ScrollArea.Autosize mah={500} type='auto'>
<Paper radius='md' withBorder mah={500}>
<ScrollArea.Autosize mah={500} type='auto' bdrs='md'>
<Table highlightOnHover stickyHeader>
<Table.Thead>
<Table.Tr>
@@ -156,8 +156,8 @@ export default function StatsTables({ data }: { data: Metric[] }) {
</ScrollArea.Autosize>
</Paper>
<Paper radius='sm' withBorder>
<ScrollArea.Autosize mah={500} type='auto'>
<Paper radius='md' withBorder>
<ScrollArea.Autosize mah={500} type='auto' bdrs='md'>
<Table highlightOnHover stickyHeader>
<Table.Thead>
<Table.Tr>
@@ -179,7 +179,7 @@ export default function StatsTables({ data }: { data: Metric[] }) {
</ScrollArea.Autosize>
</Paper>
<Paper radius='sm' withBorder p='sm'>
<Paper radius='md' withBorder p='sm'>
<TypesPieChart metric={recent} />
</Paper>
</SimpleGrid>
@@ -1,25 +1,30 @@
import { bytes } from '@/lib/bytes';
import { Metric } from '@/lib/db/models/metric';
import { LineChart, ChartTooltip } from '@mantine/charts';
import { MetricsPoint } from '@/lib/metrics';
import { ChartTooltip, LineChart } from '@mantine/charts';
import { Paper, Title } from '@mantine/core';
import { useMemo } from 'react';
import { defaultChartProps } from '../statsHelpers';
export default function StorageGraph({ metrics }: { metrics: Metric[] }) {
const sortedMetrics = metrics.sort(
(a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime(),
export default function StorageGraph({ points }: { points: MetricsPoint[] }) {
const data = useMemo(
() =>
points
.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime())
.map((point) => ({
date: new Date(point.createdAt).getTime(),
storage: point.storage,
})),
[points],
);
return (
<Paper radius='sm' withBorder p='sm' mt='md'>
<Paper radius='md' withBorder p='sm' mt='md'>
<Title order={3} mb='sm'>
Storage Used
</Title>
<LineChart
data={sortedMetrics.map((metric) => ({
date: new Date(metric.createdAt).getTime(),
storage: metric.data.storage,
}))}
data={data}
series={[
{
name: 'storage',
@@ -1,22 +1,27 @@
import { Metric } from '@/lib/db/models/metric';
import { MetricsPoint } from '@/lib/metrics';
import { ChartTooltip, LineChart } from '@mantine/charts';
import { Paper, Title } from '@mantine/core';
import { useMemo } from 'react';
import { defaultChartProps } from '../statsHelpers';
export default function ViewsGraph({ metrics }: { metrics: Metric[] }) {
const sortedMetrics = metrics.sort(
(a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime(),
export default function ViewsGraph({ points }: { points: MetricsPoint[] }) {
const data = useMemo(
() =>
points
.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime())
.map((point) => ({
date: new Date(point.createdAt).getTime(),
files: point.fileViews,
urls: point.urlViews,
})),
[points],
);
return (
<Paper radius='sm' withBorder p='sm'>
<Paper radius='md' withBorder p='sm'>
<Title order={3}>Views</Title>
<LineChart
data={sortedMetrics.map((metric) => ({
date: new Date(metric.createdAt).getTime(),
files: metric.data.fileViews,
urls: metric.data.urlViews,
}))}
data={data}
series={[
{
name: 'files',
+4 -1
View File
@@ -13,7 +13,10 @@ export const defaultChartProps: Partial<LineChartProps> & { dataKey: string } =
dataKey: 'date',
};
export function percentChange(a: number, b: number): [string, string] {
export function percentChange(a: number | bigint, b: number | bigint): [string, string] {
if (typeof a === 'bigint') a = Number(a);
if (typeof b === 'bigint') b = Number(b);
const change = Math.round(((b - a) / a) * 100);
const color = change > 0 ? 'green' : change < 0 ? 'red' : 'gray';
+6 -1
View File
@@ -1,4 +1,5 @@
import { Group, Paper, Stack, Text, Title } from '@mantine/core';
import { useUserStore } from '@/lib/client/store/user';
import ClearTempButton from './actions/ClearTempButton';
import ClearZerosButton from './actions/ClearZerosButton';
import GenThumbsButton from './actions/GenThumbsButton';
@@ -10,6 +11,7 @@ const ACTIONS = [
name: 'Import/Export Data',
desc: 'Allows you to import or export server data and configurations.',
Component: ImportExport,
superAdminOnly: true,
},
{
name: 'Clear Temporary Files',
@@ -34,6 +36,9 @@ const ACTIONS = [
];
export default function DashboardServerActions() {
const user = useUserStore((state) => state.user);
const actions = ACTIONS.filter((action) => !action.superAdminOnly || user?.role === 'SUPERADMIN');
return (
<>
<Group gap='sm'>
@@ -43,7 +48,7 @@ export default function DashboardServerActions() {
Useful tools and scripts for server management.
</Text>
<Stack gap='xs' my='sm'>
{ACTIONS.map(({ name, desc, Component }) => (
{actions.map(({ name, desc, Component }) => (
<Paper withBorder p='sm' key={name}>
<Group gap='md'>
<Component />
+8 -30
View File
@@ -1,3 +1,4 @@
import { LinksList } from '@/components/LinksList';
import { Response } from '@/lib/api/response';
import { useTitle } from '@/lib/client/hooks/useTitle';
import {
@@ -9,8 +10,6 @@ import {
Collapse,
Group,
LoadingOverlay,
Paper,
Stack,
Text,
Title,
} from '@mantine/core';
@@ -176,9 +175,10 @@ const SETTINGS_COMPONENTS = {
export const SETTINGS_EXTERNAL_LINKS = Object.values(SETTINGS_COMPONENTS)
.filter((setting) => setting.component !== null)
.map((setting) => ({
name: setting.name,
url: `/dashboard/admin/settings/${setting.key}`,
icon: setting.Icon ? <setting.Icon size='1rem' /> : <IconAdjustmentsHorizontalFilled size='1rem' />,
label: setting.name,
description: setting.desc,
href: `/dashboard/admin/settings/${setting.key}`,
icon: setting.Icon ? setting.Icon : IconAdjustmentsHorizontalFilled,
}));
const SETTINGS_PART_KEYS = Object.keys(SETTINGS_COMPONENTS)
@@ -332,31 +332,9 @@ export default function DashboardServerSettings() {
</Suspense>
</Box>
) : (
<Stack mt='md' gap='md'>
{Object.entries(SETTINGS_COMPONENTS)
.filter(([key]) => key !== 'settings')
.map(([k, { key, Icon, name, desc }]) => (
<Anchor
key={k}
component={Link}
to={`/dashboard/admin/settings/${key}`}
style={{ textDecoration: 'none' }}
>
<Paper withBorder p='sm'>
<Group gap='md'>
<ActionIcon variant='filled' radius='md' size='xl'>
{Icon ? <Icon size='1.75rem' /> : <IconAdjustmentsHorizontalFilled size='1.75rem' />}
</ActionIcon>
<div>
<Title order={4}>{name}</Title>
<Text c='dimmed'>{desc}</Text>
</div>
</Group>
</Paper>
</Anchor>
))}
</Stack>
<Box my='sm'>
<LinksList links={SETTINGS_EXTERNAL_LINKS} />
</Box>
)}
</>
);
@@ -3,7 +3,7 @@ import { Button, LoadingOverlay, NumberInput, Select, Stack, Switch, TextInput }
import { useForm } from '@mantine/form';
import { IconDeviceFloppy } from '@tabler/icons-react';
import { useNavigate } from 'react-router-dom';
import { settingsOnSubmit } from '../settingsOnSubmit';
import { checkCommaArray, settingsOnSubmit } from '../settingsOnSubmit';
import useServerSettings from '../useServerSettings';
export default function Files() {
@@ -25,6 +25,8 @@ function Form({ data, isLoading }: { data: Response['/api/server/settings']; isL
filesRoute: data.settings.filesRoute,
filesLength: data.settings.filesLength,
filesDefaultFormat: data.settings.filesDefaultFormat,
filesDisabledTypes: data.settings.filesDisabledTypes.join(', '),
filesDisabledTypesDefault: data.settings.filesDisabledTypesDefault,
filesDisabledExtensions: data.settings.filesDisabledExtensions.join(', '),
filesMaxFileSize: data.settings.filesMaxFileSize,
filesDefaultExpiration: data.settings.filesDefaultExpiration,
@@ -36,6 +38,7 @@ function Form({ data, isLoading }: { data: Response['/api/server/settings']; isL
filesRandomWordsSeparator: data.settings.filesRandomWordsSeparator,
filesDefaultCompressionFormat: data.settings.filesDefaultCompressionFormat,
filesMaxFilesPerUpload: data.settings.filesMaxFilesPerUpload,
filesExtensionlessUrls: data.settings.filesExtensionlessUrls,
},
enhanceGetInputProps: (payload) => ({
disabled: data.tampered.includes(payload.field) || false,
@@ -55,25 +58,17 @@ function Form({ data, isLoading }: { data: Response['/api/server/settings']; isL
values.filesMaxExpiration = values.filesMaxExpiration.trim();
}
if (!values.filesDisabledExtensions) {
// @ts-ignore
values.filesDisabledExtensions = [];
} else if (
values.filesDisabledExtensions &&
typeof values.filesDisabledExtensions === 'string' &&
values.filesDisabledExtensions.trim() === ''
) {
// @ts-ignore
values.filesDisabledExtensions = [];
if (values.filesDisabledTypesDefault?.trim() === '' || !values.filesDisabledTypesDefault) {
values.filesDisabledTypesDefault = null;
} else {
if (!Array.isArray(values.filesDisabledExtensions))
// @ts-ignore
values.filesDisabledExtensions = values.filesDisabledExtensions
.split(',')
.map((ext) => ext.trim())
.filter((ext) => ext !== '');
values.filesDisabledTypesDefault = values.filesDisabledTypesDefault.trim();
}
// @ts-ignore
values.filesDisabledExtensions = checkCommaArray(values.filesDisabledExtensions);
// @ts-ignore
values.filesDisabledTypes = checkCommaArray(values.filesDisabledTypes);
return settingsOnSubmit(navigate, form)(values);
};
@@ -86,12 +81,32 @@ function Form({ data, isLoading }: { data: Response['/api/server/settings']; isL
{...form.getInputProps('filesAssumeMimetypes', { type: 'checkbox' })}
/>
<TextInput
label='Disabled Types'
description='Mimetypes to disable, separated by commas. It is recommended to have the Assume Mimetypes setting enabled if you are disabling mimetypes, as this will also block files with the corresponding extensions.'
placeholder='text/html, application/javascript'
{...form.getInputProps('filesDisabledTypes')}
/>
<TextInput
label='Default MIME for Disabled Types'
description='The default MIME type to use for disabled types. Leave blank to completely block disabled types.'
placeholder='application/octet-stream'
{...form.getInputProps('filesDisabledTypesDefault')}
/>
<Switch
label='Remove GPS Metadata'
description='Remove GPS metadata from files.'
{...form.getInputProps('filesRemoveGpsMetadata', { type: 'checkbox' })}
/>
<Switch
label='Extensionless URLs'
description='Allow file links without the extension (e.g. /u/uuid instead of /u/uuid.png). Upload responses still include the extension.'
{...form.getInputProps('filesExtensionlessUrls', { type: 'checkbox' })}
/>
<TextInput
label='Route'
description='The route to use for file uploads. Requires a server restart.'
@@ -6,6 +6,22 @@ import { IconDeviceFloppy } from '@tabler/icons-react';
import { useForm } from '@mantine/form';
import { NavigateFunction } from 'react-router-dom';
export function checkCommaArray(value: unknown): string[] {
if (!value) return [];
if (value && typeof value === 'string' && value.trim() === '') return [];
if (!Array.isArray(value) && typeof value === 'string')
return value
.split(',')
.map((x) => x.trim())
.filter((x) => x !== '');
if (Array.isArray(value)) return value.map((x) => String(x).trim()).filter((x) => x !== '');
return [];
}
export function settingsOnSubmit(navigate: NavigateFunction, form: ReturnType<typeof useForm<any>>) {
return async (values: unknown) => {
const { data, error } = await fetchApi<Response['/api/server/settings']>(
@@ -63,6 +63,26 @@ export default function SettingsDashboard() {
checked={settings.fileNavButtons}
onChange={(event) => update('fileNavButtons', event.currentTarget.checked)}
/>
<Switch
label='Show recents'
description='Show recent uploads and logins on the home page.'
checked={settings.homeShowRecents}
onChange={(event) => update('homeShowRecents', event.currentTarget.checked)}
/>
<Switch
label='Show activity'
description='Show your recent activity as a graph on the home page.'
checked={settings.homeShowActivity}
onChange={(event) => update('homeShowActivity', event.currentTarget.checked)}
/>
<Switch
label='Show file types'
description='Show the file types table on the home page.'
checked={settings.homeShowTypes}
onChange={(event) => update('homeShowTypes', event.currentTarget.checked)}
/>
</Stack>
<Select
@@ -58,6 +58,7 @@ function Form({ user, setUser }: { user: User; setUser: (u: User) => void }) {
const form = useForm({
initialValues: {
enabled: user.view.enabled || false,
disableTextFiles: user.view.disableTextFiles || false,
content: user.view.content || '',
embed: user.view.embed || false,
embedMediaOnly: user.view.embedMediaOnly || false,
@@ -73,8 +74,9 @@ function Form({ user, setUser }: { user: User; setUser: (u: User) => void }) {
});
const onSubmit = async (values: typeof form.values) => {
const valuesTrimmed = {
const view = {
enabled: values.enabled,
disableTextFiles: values.disableTextFiles,
embed: values.embed,
embedMediaOnly: values.embed ? false : values.embedMediaOnly,
content: values.content.trim() || null,
@@ -89,7 +91,7 @@ function Form({ user, setUser }: { user: User; setUser: (u: User) => void }) {
};
const { data, error } = await fetchApi<Response['/api/user']>('/api/user', 'PATCH', {
view: valuesTrimmed,
view,
});
if (!data && error) {
@@ -124,6 +126,12 @@ function Form({ user, setUser }: { user: User; setUser: (u: User) => void }) {
<Stack gap='sm' mt='xs'>
<form onSubmit={form.onSubmit(onSubmit)}>
<SimpleGrid cols={{ base: 1, md: 2 }} spacing='sm' mb='xs'>
<Switch
label='Disable text files'
description='Disable viewing text files through view-routes. This has no effect on other file types and will work even if view-routes are disabled.'
{...form.getInputProps('disableTextFiles', { type: 'checkbox' })}
/>
<Switch
label='Enable View Routes'
description='Enable viewing files through customizable view-routes'
+2 -2
View File
@@ -208,7 +208,7 @@ export default function UploadFile({ title, folder }: { title?: string; folder?:
</Collapse>
<Collapse expanded={progress.speed > 0 && progress.remaining > 0}>
<Paper withBorder p='xs' radius='sm'>
<Paper withBorder p='xs'>
<Text ta='center' size='sm'>
{bytes(progress.speed)}/s, {humanizeDuration(progress.remaining)} remaining
</Text>
@@ -216,7 +216,7 @@ export default function UploadFile({ title, folder }: { title?: string; folder?:
</Collapse>
<Collapse expanded={progress.percent === 100}>
<Paper withBorder p='xs' radius='sm'>
<Paper withBorder p='xs'>
<Text ta='center' size='sm' c='yellow' fw={500}>
Finalizing upload(s)...
</Text>
+1 -1
View File
@@ -24,7 +24,7 @@ export default function UserCard({
return (
<>
<Card withBorder shadow='sm' radius='sm'>
<Card withBorder shadow='sm'>
<Card.Section withBorder inheritPadding py='xs'>
<Group justify='space-between'>
{url.enabled ? (
+1 -1
View File
@@ -198,7 +198,7 @@ export default function DashboardURLs() {
{...form.getInputProps('password')}
/>
<Button type='submit' variant='outline' radius='sm' leftSection={<IconLink size='1rem' />}>
<Button type='submit' variant='outline' leftSection={<IconLink size='1rem' />}>
Create
</Button>
</Stack>
@@ -155,7 +155,6 @@ export default function UrlTableView() {
<Box my='sm'>
<DataTable
borderRadius='sm'
withTableBorder
minHeight={200}
records={sorted ?? []}
+3 -9
View File
@@ -1,7 +1,7 @@
import { Response } from '@/lib/api/response';
import { readToDataURL } from '@/lib/base64';
import { bytes } from '@/lib/bytes';
import { User } from '@/lib/db/models/user';
import { LimitedUser } from '@/lib/db/models/user';
import { fetchApi } from '@/lib/fetchApi';
import { canInteract } from '@/lib/role';
import { useUserStore } from '@/lib/client/store/user';
@@ -31,7 +31,7 @@ export default function EditUserModal({
opened,
onClose,
}: {
user?: User | null;
user?: LimitedUser | null;
opened: boolean;
onClose: () => void;
}) {
@@ -268,13 +268,7 @@ export default function EditUserModal({
/>
<Divider />
<Button
type='submit'
variant='outline'
color='blue'
radius='sm'
leftSection={<IconUserEdit size='1rem' />}
>
<Button type='submit' variant='outline' color='blue' leftSection={<IconUserEdit size='1rem' />}>
Update user
</Button>
</Stack>
+3 -3
View File
@@ -1,4 +1,4 @@
import { User } from '@/lib/db/models/user';
import { LimitedUser } from '@/lib/db/models/user';
import { ActionIcon, Avatar, Card, Group, Menu, Stack, Text } from '@mantine/core';
import { useUserStore } from '@/lib/client/store/user';
import { IconDots, IconFiles, IconTrashFilled, IconUserEdit } from '@tabler/icons-react';
@@ -9,7 +9,7 @@ import RelativeDate from '@/components/RelativeDate';
import { canInteract, isAdministrator, roleName } from '@/lib/role';
import { Link } from 'react-router-dom';
export default function UserCard({ user }: { user: User }) {
export default function UserCard({ user }: { user: LimitedUser }) {
const currentUser = useUserStore((state) => state.user);
const [opened, setOpen] = useState(false);
@@ -18,7 +18,7 @@ export default function UserCard({ user }: { user: User }) {
<>
<EditUserModal user={user} opened={opened} onClose={() => setOpen(false)} />
<Card withBorder shadow='sm' radius='sm'>
<Card withBorder shadow='sm'>
<Card.Section withBorder inheritPadding py='xs'>
<Group justify='space-between'>
<Group>
+3 -3
View File
@@ -1,12 +1,12 @@
import { Response } from '@/lib/api/response';
import { User } from '@/lib/db/models/user';
import { LimitedUser } from '@/lib/db/models/user';
import { fetchApi } from '@/lib/fetchApi';
import { modals } from '@mantine/modals';
import { notifications } from '@mantine/notifications';
import { IconUserCancel, IconUserMinus } from '@tabler/icons-react';
import { mutate } from 'swr';
export async function deleteUser(user: User) {
export async function deleteUser(user: LimitedUser) {
modals.openConfirmModal({
centered: true,
title: `Delete ${user.username}?`,
@@ -33,7 +33,7 @@ export async function deleteUser(user: User) {
});
}
async function handleDeleteUser(user: User, deleteFiles: boolean = false) {
async function handleDeleteUser(user: LimitedUser, deleteFiles: boolean = false) {
const { data, error } = await fetchApi<Response['/api/users/[id]']>(`/api/users/${user.id}`, 'DELETE', {
delete: deleteFiles,
});
+3 -4
View File
@@ -1,7 +1,6 @@
import GridTableSwitcher from '@/components/GridTableSwitcher';
import { Response } from '@/lib/api/response';
import { readToDataURL } from '@/lib/base64';
import { User } from '@/lib/db/models/user';
import { LimitedUser } from '@/lib/db/models/user';
import { fetchApi } from '@/lib/fetchApi';
import { canInteract } from '@/lib/role';
import { useUserStore } from '@/lib/client/store/user';
@@ -68,7 +67,7 @@ export default function DashboardUsers() {
}
}
const { data, error } = await fetchApi<Extract<Response['/api/users'], User>>('/api/users', 'POST', {
const { data, error } = await fetchApi<LimitedUser>('/api/users', 'POST', {
username: values.username,
password: values.password,
role: values.role ?? 'USER',
@@ -144,7 +143,7 @@ export default function DashboardUsers() {
{...form.getInputProps('role')}
/>
<Button type='submit' variant='outline' radius='sm' leftSection={<IconUserPlus size='1rem' />}>
<Button type='submit' variant='outline' leftSection={<IconUserPlus size='1rem' />}>
Create
</Button>
</Stack>
@@ -1,13 +1,11 @@
import { Response } from '@/lib/api/response';
import { User } from '@/lib/db/models/user';
import { LimitedUser } from '@/lib/db/models/user';
import { Center, Group, Paper, SimpleGrid, Skeleton, Stack, Text, Title } from '@mantine/core';
import { IconFilesOff } from '@tabler/icons-react';
import useSWR from 'swr';
import UserCard from '../UserCard';
export default function UserGridView() {
const { data: users, isLoading } =
useSWR<Extract<Response['/api/users'], User[]>>('/api/users?noincl=true');
const { data: users, isLoading } = useSWR<LimitedUser[]>('/api/users?noincl=true');
return (
<>
@@ -1,7 +1,6 @@
import RelativeDate from '@/components/RelativeDate';
import { Response } from '@/lib/api/response';
import { useUserStore } from '@/lib/client/store/user';
import { User } from '@/lib/db/models/user';
import { LimitedUser } from '@/lib/db/models/user';
import { canInteract, roleName } from '@/lib/role';
import { ActionIcon, Avatar, Box, Group, Tooltip } from '@mantine/core';
import { IconEdit, IconFiles, IconTrashFilled } from '@tabler/icons-react';
@@ -15,20 +14,20 @@ import EditUserModal from '../EditUserModal';
export default function UserTableView() {
const currentUser = useUserStore((state) => state.user);
const { data, isLoading } = useSWR<Extract<Response['/api/users'], User[]>>('/api/users?noincl=true');
const { data, isLoading } = useSWR<LimitedUser[]>('/api/users?noincl=true');
const [selectedUser, setSelectedUser] = useState<User | null>(null);
const [selectedUser, setSelectedUser] = useState<LimitedUser | null>(null);
const [sortStatus, setSortStatus] = useState<DataTableSortStatus>({
columnAccessor: 'createdAt',
direction: 'desc',
});
const sorted = useMemo<User[]>(() => {
const sorted = useMemo<LimitedUser[]>(() => {
if (!data) return [];
const { columnAccessor, direction } = sortStatus;
const key = columnAccessor as keyof User;
const key = columnAccessor as keyof LimitedUser;
return [...data].sort((a, b) => {
const av = a[key]!;
@@ -45,7 +44,6 @@ export default function UserTableView() {
<Box my='sm'>
<DataTable
borderRadius='sm'
withTableBorder
minHeight={200}
records={sorted ?? []}
+2
View File
@@ -63,6 +63,7 @@ export const API_ERRORS = {
1062: 'No files in multipart/form-data request',
1063: 'Already linked to this OAuth provider',
1064: 'Invalid OAuth state parameter',
1065: 'Invalid MIME type',
// 2xxx, session errors
2000: 'Invalid login session',
@@ -91,6 +92,7 @@ export const API_ERRORS = {
3016: 'OAuth registration is disabled',
3017: 'OAuth login is not allowed for this account',
3018: 'Invalid access token provided.',
3019: 'You cannot modify this user',
// 4xxx, not founds
4000: 'File not found',
+4
View File
@@ -14,6 +14,7 @@ import { ApiServerImportV3 } from '@/server/routes/api/server/import/v3';
import { ApiServerImportV4 } from '@/server/routes/api/server/import/v4';
import { ApiServerPublicResponse } from '@/server/routes/api/server/public';
import { ApiServerRequerySizeResponse } from '@/server/routes/api/server/requery_size';
import { ApiServerStatusResponse } from '@/server/routes/api/server/status';
import { ApiServerSettingsResponse, ApiServerSettingsWebResponse } from '@/server/routes/api/server/settings';
import { ApiServerThemesResponse } from '@/server/routes/api/server/themes';
import { ApiServerThumbnailsResponse } from '@/server/routes/api/server/thumbnails';
@@ -34,6 +35,7 @@ import { ApiUserMfaPasskeyResponse } from '@/server/routes/api/user/mfa/passkey'
import { ApiUserMfaTotpResponse } from '@/server/routes/api/user/mfa/totp';
import { ApiUserRecentResponse } from '@/server/routes/api/user/recent';
import { ApiUserSessionsResponse } from '@/server/routes/api/user/sessions';
import { ApiUserActivityResponse } from '@/server/routes/api/user/activity';
import { ApiUserStatsResponse } from '@/server/routes/api/user/stats';
import { ApiUserTagsResponse } from '@/server/routes/api/user/tags';
import { ApiUserTagsIdResponse } from '@/server/routes/api/user/tags/[id]';
@@ -70,6 +72,7 @@ export type Response = {
'/api/user/sessions': ApiUserSessionsResponse;
'/api/user': ApiUserResponse;
'/api/user/stats': ApiUserStatsResponse;
'/api/user/activity': ApiUserActivityResponse;
'/api/user/recent': ApiUserRecentResponse;
'/api/user/token': ApiUserTokenResponse;
'/api/user/export': ApiUserExportResponse;
@@ -78,6 +81,7 @@ export type Response = {
'/api/server/clear_temp': ApiServerClearTempResponse;
'/api/server/clear_zeros': ApiServerClearZerosResponse;
'/api/server/requery_size': ApiServerRequerySizeResponse;
'/api/server/status': ApiServerStatusResponse;
'/api/server/settings': ApiServerSettingsResponse;
'/api/server/settings/web': ApiServerSettingsWebResponse;
'/api/server/public': ApiServerPublicResponse;
+1 -1
View File
@@ -19,5 +19,5 @@ export default function useVersion() {
revalidateOnReconnect: false,
});
return { version: data?.data, isLoading };
return { version: data?.data, details: data?.details, cached: data?.cached, isLoading };
}
+6
View File
@@ -12,6 +12,9 @@ export type SettingsStore = {
themeDark: string;
themeLight: string;
domain: '' | string;
homeShowRecents: boolean;
homeShowActivity: boolean;
homeShowTypes: boolean;
};
update: <K extends keyof SettingsStore['settings']>(key: K, value: SettingsStore['settings'][K]) => void;
@@ -27,6 +30,9 @@ const defaultSettings: SettingsStore['settings'] = {
themeDark: 'builtin:dark_blue',
themeLight: 'builtin:light_blue',
domain: '',
homeShowRecents: true,
homeShowActivity: true,
homeShowTypes: true,
};
export const useSettingsStore = create<SettingsStore>()(
+1 -1
View File
@@ -20,7 +20,7 @@ export function openWarningModal(options: WarningModalOptions) {
onCancel: () => modals.closeAll(),
onConfirm: options.onConfirm,
zIndex: 10320948239487,
size: 'auto',
size: 'md',
});
}
+3
View File
@@ -22,6 +22,8 @@ export const DATABASE_TO_PROP = {
filesRoute: 'files.route',
filesLength: 'files.length',
filesDefaultFormat: 'files.defaultFormat',
filesDisabledTypes: 'files.disabledTypes',
filesDisabledTypesDefault: 'files.disabledTypesDefault',
filesDisabledExtensions: 'files.disabledExtensions',
filesMaxFileSize: 'files.maxFileSize',
filesDefaultExpiration: 'files.defaultExpiration',
@@ -33,6 +35,7 @@ export const DATABASE_TO_PROP = {
filesRandomWordsSeparator: 'files.randomWordsSeparator',
filesDefaultCompressionFormat: 'files.defaultCompressionFormat',
filesMaxFilesPerUpload: 'files.maxFilesPerUpload',
filesExtensionlessUrls: 'files.extensionlessUrls',
urlsRoute: 'urls.route',
urlsLength: 'urls.length',
+3
View File
@@ -56,6 +56,8 @@ export const ENVS = [
env('files.route', 'FILES_ROUTE', 'string', true),
env('files.length', 'FILES_LENGTH', 'number', true),
env('files.defaultFormat', 'FILES_DEFAULT_FORMAT', 'string', true),
env('files.disabledTypes', 'FILES_DISABLED_TYPES', 'string[]', true),
env('files.disabledTypesDefault', 'FILES_DISABLED_TYPES_DEFAULT', 'string', true),
env('files.disabledExtensions', 'FILES_DISABLED_EXTENSIONS', 'string[]', true),
env('files.maxFileSize', 'FILES_MAX_FILE_SIZE', 'string', true),
env('files.defaultExpiration', 'FILES_DEFAULT_EXPIRATION', 'string', true),
@@ -66,6 +68,7 @@ export const ENVS = [
env('files.randomWordsSeparator', 'FILES_RANDOM_WORDS_SEPARATOR', 'string', true),
env('files.defaultCompressionFormat', 'FILES_DEFAULT_COMPRESSION_FORMAT', 'string', true),
env('files.maxFilesPerUpload', 'FILES_MAX_FILES_PER_UPLOAD', 'number', true),
env('files.extensionlessUrls', 'FILES_EXTENSIONLESS_URLS', 'boolean', true),
env('urls.route', 'URLS_ROUTE', 'string', true),
env('urls.length', 'URLS_LENGTH', 'number', true),
+3 -1
View File
@@ -49,6 +49,7 @@ export const rawConfig: any = {
randomWordsSeparator: undefined,
defaultCompressionFormat: undefined,
maxFilesPerUpload: undefined,
extensionlessUrls: undefined,
},
urls: {
route: undefined,
@@ -169,10 +170,11 @@ export async function read() {
}
global.__tamperedConfig__.push(col);
logger.info('overriding database value from env', { col, value: val });
}
}
logger.debug('overridden db settings from env vars', { overridden: global.__tamperedConfig__ });
const raw = structuredClone(rawConfig);
for (const [key, value] of Object.entries(database)) {
+2
View File
@@ -1,4 +1,5 @@
import enabled from '../oauth/enabled';
import { version } from '../../../package.json';
import { Config } from './validate';
export type SafeConfig = Omit<
@@ -21,6 +22,7 @@ export function safeConfig(config: Config): SafeConfig {
bypassLocalLogin: oauth.bypassLocalLogin,
loginOnly: oauth.loginOnly,
};
(rest as SafeConfig).version = version;
return rest as SafeConfig;
}
+5
View File
@@ -18,6 +18,8 @@ declare global {
}
}
export const MIME_REGEX = /^[a-zA-Z0-9!#$&^_\-\+.]+\/[a-zA-Z0-9!#$&^_\-\+.]+$/gi;
export const MAX_SAFE_TIMEOUT_MS = 2147483647;
export function validateInterval(value: string): boolean {
@@ -131,6 +133,8 @@ export const schema = z.object({
route: z.string().startsWith('/').min(1).trim().toLowerCase().default('/u'),
length: z.number().default(6),
defaultFormat: z.enum(['random', 'date', 'uuid', 'name', 'gfycat', 'random-words']).default('random'),
disabledTypes: z.array(z.string().regex(MIME_REGEX, 'Invalid MIME type format')).default([]),
disabledTypesDefault: z.string().nullable().default(null),
disabledExtensions: z.array(z.string()).default([]),
maxFileSize: z.string().default('100mb'),
defaultExpiration: z.string().nullable().default(null),
@@ -145,6 +149,7 @@ export const schema = z.object({
.default('jpg')
.refine((v) => checkOutput(v), 'System does not support outputting this image format.'),
maxFilesPerUpload: z.number().max(2147483647).min(1).default(1000),
extensionlessUrls: z.boolean().default(false),
}),
urls: z.object({
route: z.string().startsWith('/').min(1).trim().toLowerCase().default('/go'),
+14 -1
View File
@@ -14,6 +14,10 @@ async function existsAndCanRW(path: string): Promise<boolean> {
}
}
function isCrossDeviceMove(error: unknown): boolean {
return typeof error === 'object' && error !== null && 'code' in error && error.code === 'EXDEV';
}
export class LocalDatasource extends Datasource {
name = 'local';
logger = log('datasource').c('local');
@@ -44,7 +48,7 @@ export class LocalDatasource extends Datasource {
const path = this.resolvePath(file);
if (!path) throw new Error('Invalid path provided');
// handles if given a path to a file, it will just move it instead of doing unecessary writes
// handles path-based writes without duplicating bytes when the source can be consumed
if (typeof data === 'string' && data.startsWith('/')) {
const exists = await existsAndCanRW(data);
if (!exists)
@@ -52,6 +56,15 @@ export class LocalDatasource extends Datasource {
"Something went very wrong! the temporary directory wasn't readable or the file doesn't exist.",
);
if (!noDelete) {
try {
await rename(data, path);
return;
} catch (e) {
if (!isCrossDeviceMove(e)) throw e;
}
}
await copyFile(data, path);
if (!noDelete) await rm(data);
+21 -12
View File
@@ -7,6 +7,7 @@ import {
GetObjectCommand,
HeadObjectCommand,
ListObjectsCommand,
ListObjectsV2Command,
PutObjectCommand,
S3Client,
UploadPartCopyCommand,
@@ -256,23 +257,31 @@ export class S3Datasource extends Datasource {
}
public async totalSize(): Promise<number> {
const command = new ListObjectsCommand({
Bucket: this.options.bucket,
Prefix: this.options.subdirectory ?? undefined,
Delimiter: this.options.subdirectory ? undefined : '/',
});
let total = 0;
let continuationToken: string | undefined;
try {
const res = await this.client.send(command);
do {
const res = await this.client.send(
new ListObjectsV2Command({
Bucket: this.options.bucket,
Prefix: this.options.subdirectory ?? undefined,
ContinuationToken: continuationToken,
}),
);
if (!isOk(res.$metadata.httpStatusCode || 0)) {
this.logger.error('there was an error while listing objects');
this.logger.error('error metadata', res.$metadata as Record<string, unknown>);
if (!isOk(res.$metadata.httpStatusCode || 0)) {
this.logger.error('there was an error while listing objects');
this.logger.error('error metadata', res.$metadata as Record<string, unknown>);
return 0;
}
return 0;
}
return res.Contents?.reduce((acc, obj) => acc + Number(obj.Size), 0) ?? 0;
total += res.Contents?.reduce((acc, obj) => acc + Number(obj.Size ?? 0), 0) ?? 0;
continuationToken = res.IsTruncated ? res.NextContinuationToken : undefined;
} while (continuationToken);
return total;
} catch (e) {
this.logger.error('there was an error while listing objects');
this.logger.error('error metadata', e as Record<string, unknown>);
+16
View File
@@ -1,5 +1,7 @@
import { config } from '@/lib/config';
import { sanitizeFilename } from '@/lib/fs';
import { formatRootUrl } from '@/lib/url';
import type { Prisma } from '@/prisma/client';
import { z } from 'zod';
import { tagSchema, tagSelectNoFiles } from './tag';
@@ -27,6 +29,20 @@ export const fileSelect = {
},
};
export async function findFileByName<TResult>(
id: string,
query: (
where: Prisma.FileWhereInput,
orderBy?: Prisma.FileOrderByWithRelationInput,
) => Promise<TResult | null>,
) {
const name = sanitizeFilename(id);
if (!name) return null;
const file = await query({ name });
if (file || !config.files.extensionlessUrls || name.includes('.')) return file;
return query({ name: { startsWith: `${name}.` } }, { createdAt: 'desc' });
}
export function cleanFile(file: File) {
file.password = !!file.password;
+15 -6
View File
@@ -38,30 +38,39 @@ export async function buildPublicParentChain(parentId: string | null): Promise<F
};
}
export function cleanFolder<T extends Partial<Folder>>(folder: T, stringifyDates = false): T {
type CleanableFolder = {
createdAt?: string | Date;
updatedAt?: string | Date;
files?: unknown;
children?: unknown;
parent?: unknown;
[key: string]: unknown;
};
export function cleanFolder<T extends CleanableFolder>(folder: T, stringifyDates = false): T {
if (folder.files && Array.isArray(folder.files)) cleanFiles(folder.files as any, stringifyDates);
if (stringifyDates) {
if (folder.createdAt && folder.createdAt instanceof Date)
folder.createdAt = folder.createdAt.toISOString();
(folder as CleanableFolder).createdAt = folder.createdAt.toISOString();
if (folder.updatedAt && folder.updatedAt instanceof Date)
folder.updatedAt = folder.updatedAt.toISOString();
(folder as CleanableFolder).updatedAt = folder.updatedAt.toISOString();
}
if (folder.children && Array.isArray(folder.children)) {
for (const child of folder.children) {
cleanFolder(child, stringifyDates);
if (child && typeof child === 'object') cleanFolder(child as CleanableFolder, stringifyDates);
}
}
if (folder.parent && typeof folder.parent === 'object') {
cleanFolder(folder.parent, stringifyDates);
cleanFolder(folder.parent as CleanableFolder, stringifyDates);
}
return folder;
}
export function cleanFolders<T extends Partial<Folder>>(folders: T[], stringifyDates = false): T[] {
export function cleanFolders<T extends CleanableFolder>(folders: T[], stringifyDates = false): T[] {
for (let i = 0; i !== folders.length; ++i) {
cleanFolder(folders[i], stringifyDates);
}
+22
View File
@@ -14,9 +14,20 @@ export const userSelect = {
sessions: true,
};
export const limitedUserSelect = {
id: true,
username: true,
createdAt: true,
updatedAt: true,
role: true,
view: true,
quota: true,
};
export const userViewSchema = z
.object({
enabled: z.boolean().nullish(),
disableTextFiles: z.boolean().nullish(),
align: z.enum(['left', 'center', 'right']).nullish(),
showMimetype: z.boolean().nullish(),
showTags: z.boolean().nullish(),
@@ -106,3 +117,14 @@ export const userSchema = z.object({
});
export type User = z.infer<typeof userSchema>;
export const limitedUserSchema = userSchema.omit({
oauthProviders: true,
totpSecret: true,
passkeys: true,
sessions: true,
password: true,
token: true,
});
export type LimitedUser = z.infer<typeof limitedUserSchema>;
+41
View File
@@ -0,0 +1,41 @@
import { statfs } from 'fs/promises';
import { config } from './config';
import { datasource } from './datasource';
import z from 'zod';
export const diskStatusSchema = z.object({
used: z.number(),
total: z.number().nullable(),
available: z.number().nullable(),
path: z.string(),
});
export type DiskStatus = z.infer<typeof diskStatusSchema>;
async function localDiskStatus() {
const path = config.datasource.local!.directory;
const stats = await statfs(path);
const total = stats.blocks * stats.bsize;
const available = stats.bavail * stats.bsize;
const used = total - stats.bfree * stats.bsize;
return { used, total, available, path };
}
async function s3DiskStatus() {
const s3 = config.datasource.s3!;
const totalSize = await datasource.totalSize();
const path = `${s3.bucket}${s3.subdirectory ? `/${s3.subdirectory.replace(/\/$/, '')}` : ''}`;
return {
used: totalSize,
total: null,
available: null,
path,
};
}
export async function diskStatus() {
return config.datasource.type === 'local' ? localDiskStatus() : s3DiskStatus();
}
+72
View File
@@ -0,0 +1,72 @@
import z from 'zod';
import { prisma } from './db';
import { Metric } from './db/models/metric';
export const metricsPointSchema = z.object({
id: z.string(),
createdAt: z.date(),
users: z.number(),
files: z.number(),
fileViews: z.number(),
urls: z.number(),
urlViews: z.number(),
storage: z.bigint(),
});
export type MetricsPoint = z.infer<typeof metricsPointSchema>;
export function getMetricsPoints(from?: Date, to?: Date): Promise<MetricsPoint[]> {
if (from && to) {
return prisma.$queryRaw<MetricsPoint[]>`
SELECT
id,
"createdAt",
(data->>'users')::int AS users,
(data->>'files')::int AS files,
(data->>'fileViews')::int AS "fileViews",
(data->>'urls')::int AS urls,
(data->>'urlViews')::int AS "urlViews",
(data->>'storage')::bigint AS storage
FROM "Metric"
WHERE "createdAt" >= ${from} AND "createdAt" <= ${to}
ORDER BY "createdAt" DESC
`;
}
return prisma.$queryRaw<MetricsPoint[]>`
SELECT
id,
"createdAt",
(data->>'users')::int AS users,
(data->>'files')::int AS files,
(data->>'fileViews')::int AS "fileViews",
(data->>'urls')::int AS urls,
(data->>'urlViews')::int AS "urlViews",
(data->>'storage')::bigint AS storage
FROM "Metric"
ORDER BY "createdAt" DESC
`;
}
export function getLatestMetricsPoint(from?: Date, to?: Date): Promise<Metric | null> {
return prisma.metric.findFirst({
where: from && to ? { createdAt: { gte: from, lte: to } } : undefined,
orderBy: { createdAt: 'desc' },
});
}
export function downsample(points: MetricsPoint[], max: number = 500): MetricsPoint[] {
if (points.length <= max) return points;
const indices = new Set<number>();
indices.add(0);
indices.add(points.length - 1);
const middle = max - 2;
const step = (points.length - 1) / (middle + 1);
for (let i = 1; i <= middle; i++) {
indices.add(Math.round(i * step));
}
return [...indices].sort((a, b) => a - b).map((i) => points[i]!);
}
+6
View File
@@ -11,6 +11,12 @@ export function canInteract(current?: Role, target?: Role) {
);
}
export function interactableRoles(current?: Role): Role[] {
if (current === 'SUPERADMIN') return ['USER', 'ADMIN'];
if (current === 'ADMIN') return ['USER'];
return [];
}
export function roleName(role?: Role) {
switch (role) {
case 'USER':
+1
View File
@@ -47,6 +47,7 @@ export function themeComponents(theme: ZiplineTheme): MantineThemeOverride {
return {
...rest,
variantColorResolver: variantColorResolver,
defaultRadius: 'md',
components: {
...components,
AppShell: AppShell.extend({
+2
View File
@@ -70,6 +70,8 @@ export default typedPlugin(
preHandler: [userMiddleware, administratorMiddleware],
},
async (req, res) => {
if (req.user.role !== 'SUPERADMIN') throw new ApiError(3015);
if (req.query.counts) {
const counts = await getCounts();
+5 -3
View File
@@ -20,7 +20,7 @@ export default typedPlugin(
PATH,
{
schema: {
description: 'Fetch a folder by ID. Behavior varies based on public and allowUploads flags.',
description: 'Fetch a folder by ID/name. Behavior varies based on public and allowUploads flags.',
params: z.object({
id: z.string(),
}),
@@ -45,8 +45,10 @@ export default typedPlugin(
async (req, res) => {
const { id } = req.params;
const folder = await prisma.folder.findUnique({
where: { id },
const folder = await prisma.folder.findFirst({
where: {
OR: [{ id }, { name: id }],
},
include: {
children: {
where: { public: true },
@@ -4,7 +4,7 @@ import { checkOutput, COMPRESS_TYPES } from '@/lib/compress';
import { reloadSettings } from '@/lib/config';
import type { readDatabaseSettings } from '@/lib/config/read/db';
import { safeConfig } from '@/lib/config/safe';
import { MAX_SAFE_TIMEOUT_MS } from '@/lib/config/validate';
import { MAX_SAFE_TIMEOUT_MS, MIME_REGEX } from '@/lib/config/validate';
import { prisma } from '@/lib/db';
import { log } from '@/lib/logger';
import { secondlyRatelimit } from '@/lib/ratelimits';
@@ -181,6 +181,8 @@ export default typedPlugin(
'Provided route is reserved',
),
filesLength: z.number().min(1).max(64),
filesDisabledTypes: z.array(z.string().regex(MIME_REGEX, 'Invalid MIME type')),
filesDisabledTypesDefault: z.string().regex(MIME_REGEX, 'Invalid MIME type').nullable(),
filesDefaultFormat: z.enum(['random', 'date', 'uuid', 'name', 'gfycat']),
filesDisabledExtensions: z
.union([
@@ -191,7 +193,6 @@ export default typedPlugin(
typeof value === 'string' ? value.split(',').map((ext) => ext.trim()) : value,
),
filesMaxFileSize: zBytes,
filesDefaultExpiration: zMs.nullable(),
filesMaxExpiration: zMs.nullable(),
filesAssumeMimetypes: z.boolean(),
@@ -203,6 +204,7 @@ export default typedPlugin(
.enum(COMPRESS_TYPES)
.refine((v) => checkOutput(v), 'System does not support outputting this image format.'),
filesMaxFilesPerUpload: z.number().min(1).max(2147483647),
filesExtensionlessUrls: z.boolean(),
urlsRoute: z
.string()
+41
View File
@@ -0,0 +1,41 @@
import { config } from '@/lib/config';
import { diskStatus, diskStatusSchema } from '@/lib/disk';
import { administratorMiddleware } from '@/server/middleware/administrator';
import { userMiddleware } from '@/server/middleware/user';
import typedPlugin from '@/server/typedPlugin';
import z from 'zod';
export const apiServerStatusResponseSchema = z.object({
datasource: z.enum(['local', 's3']).describe('Configured datasource type for this Zipline instance.'),
storage: diskStatusSchema,
});
export type ApiServerStatusResponse = z.infer<typeof apiServerStatusResponseSchema>;
export const PATH = '/api/server/status';
export default typedPlugin(
async (server) => {
server.get(
PATH,
{
schema: {
description: 'Get disk status for the configured datasource',
response: {
200: apiServerStatusResponseSchema,
},
tags: ['auth', 'admin'],
},
preHandler: [userMiddleware, administratorMiddleware],
},
async (_, res) => {
const status = await diskStatus();
return res.send({
datasource: config.datasource.type,
storage: status,
});
},
);
},
{ name: PATH },
);
+21 -25
View File
@@ -1,16 +1,22 @@
import { ApiError } from '@/lib/api/errors';
import { config } from '@/lib/config';
import { prisma } from '@/lib/db';
import { Metric, metricSchema } from '@/lib/db/models/metric';
import { metricSchema } from '@/lib/db/models/metric';
import { downsample, getLatestMetricsPoint, getMetricsPoints, metricsPointSchema } from '@/lib/metrics';
import { isAdministrator } from '@/lib/role';
import { zQsBoolean } from '@/lib/validation';
import { userMiddleware } from '@/server/middleware/user';
import typedPlugin from '@/server/typedPlugin';
import z from 'zod';
export type ApiStatsResponse = Metric[];
export const apiStatsResponseSchema = z.object({
latest: metricSchema.nullable(),
points: z.array(metricsPointSchema),
});
export type ApiStatsResponse = z.infer<typeof apiStatsResponseSchema>;
export const PATH = '/api/stats';
export default typedPlugin(
async (server) => {
server.get(
@@ -39,7 +45,7 @@ export default typedPlugin(
all: zQsBoolean.default(false),
}),
response: {
200: z.array(metricSchema),
200: apiStatsResponseSchema,
},
tags: ['auth'],
},
@@ -60,30 +66,20 @@ export default typedPlugin(
if (fromDate > new Date()) throw new ApiError(1059);
}
const stats = await prisma.metric.findMany({
where: {
...(!all && {
createdAt: {
gte: fromDate,
lte: toDate,
},
}),
},
orderBy: {
createdAt: 'desc',
},
});
const [latest, points] = await Promise.all([
getLatestMetricsPoint(!all ? fromDate : undefined, !all ? toDate : undefined),
all ? getMetricsPoints() : getMetricsPoints(fromDate, toDate),
]);
if (!config.features.metrics.showUserSpecific) {
for (let i = 0; i !== stats.length; ++i) {
const stat = stats[i].data;
stat.filesUsers = [];
stat.urlsUsers = [];
}
if (latest && !config.features.metrics.showUserSpecific) {
latest.data.filesUsers = [];
latest.data.urlsUsers = [];
}
return res.send(stats);
return res.send({
latest,
points: downsample(points),
});
},
);
},
+8 -1
View File
@@ -155,7 +155,8 @@ export default typedPlugin(
const { fileName } = nameResult;
// determine mimetype
const { mimetype, assumed } = await getMimetype(file.mimetype, extension);
const { assumed, ...mimeRes } = await getMimetype(file.mimetype, extension);
let mimetype = mimeRes.mimetype;
if (config.files.assumeMimetypes) {
response.assumedMimetypes![i] = assumed;
@@ -170,6 +171,12 @@ export default typedPlugin(
}
}
if (config.files.disabledTypes.includes(mimetype.trim().toLowerCase())) {
console.log(mimetype, config.files.disabledTypesDefault);
if (config.files.disabledTypesDefault) mimetype = config.files.disabledTypesDefault;
else throw new ApiError(1065, `file[${i}]: File type ${mimetype} is not allowed`);
}
// compress the image if requested
let compressed;
if (mimetype.startsWith('image/') && options.imageCompression) {
+126
View File
@@ -0,0 +1,126 @@
import { prisma } from '@/lib/db';
import { userMiddleware } from '@/server/middleware/user';
import typedPlugin from '@/server/typedPlugin';
import dayjs from 'dayjs';
import z from 'zod';
export type ApiUserActivityDay = {
date: string;
uploads: number;
logins: number;
};
export type ApiUserActivityResponse = {
days: number;
series: ApiUserActivityDay[];
totals: {
uploads: number;
logins: number;
};
};
export const PATH = '/api/user/activity';
const MAX_DAYS = 90;
const DEFAULT_DAYS = 14;
export default typedPlugin(
async (server) => {
server.get(
PATH,
{
schema: {
description: 'Daily upload and login counts for the authenticated user over a recent window.',
querystring: z.object({
days: z.coerce.number().int().min(1).max(MAX_DAYS).default(DEFAULT_DAYS),
}),
response: {
200: z.object({
days: z.number(),
series: z.array(
z.object({
date: z.string(),
uploads: z.number(),
logins: z.number(),
}),
),
totals: z.object({
uploads: z.number(),
logins: z.number(),
}),
}),
},
tags: ['auth'],
},
preHandler: [userMiddleware],
},
async (req, res) => {
const days = req.query.days;
const start = dayjs()
.subtract(days - 1, 'day')
.startOf('day')
.toDate();
const [files, sessions] = await Promise.all([
prisma.file.findMany({
where: {
userId: req.user.id,
createdAt: { gte: start },
},
select: { createdAt: true },
}),
prisma.userSession.findMany({
where: {
userId: req.user.id,
createdAt: { gte: start },
},
select: { createdAt: true },
}),
]);
const uploadsByDay = new Map<string, number>();
const loginsByDay = new Map<string, number>();
for (const file of files) {
const key = dayjs(file.createdAt).format('YYYY-MM-DD');
uploadsByDay.set(key, (uploadsByDay.get(key) ?? 0) + 1);
}
for (const session of sessions) {
const key = dayjs(session.createdAt).format('YYYY-MM-DD');
loginsByDay.set(key, (loginsByDay.get(key) ?? 0) + 1);
}
const series: ApiUserActivityDay[] = [];
let totalUploads = 0;
let totalLogins = 0;
for (let i = days - 1; i >= 0; i--) {
const day = dayjs().subtract(i, 'day').startOf('day');
const key = day.format('YYYY-MM-DD');
const uploads = uploadsByDay.get(key) ?? 0;
const logins = loginsByDay.get(key) ?? 0;
totalUploads += uploads;
totalLogins += logins;
series.push({
date: day.toISOString(),
uploads,
logins,
});
}
return res.send({
days,
series,
totals: {
uploads: totalUploads,
logins: totalLogins,
},
});
},
);
},
{ name: PATH },
);
@@ -1,11 +1,12 @@
import { ApiError } from '@/lib/api/errors';
import { datasource } from '@/lib/datasource';
import { prisma } from '@/lib/db';
import { fileSelect } from '@/lib/db/models/file';
import { buildParentChain, Folder, cleanFolder, folderSchema } from '@/lib/db/models/folder';
import { User } from '@/lib/db/models/user';
import { log } from '@/lib/logger';
import { canInteract } from '@/lib/role';
import { zStringTrimmed } from '@/lib/validation';
import { zQsBoolean, zStringTrimmed } from '@/lib/validation';
import { userMiddleware } from '@/server/middleware/user';
import typedPlugin from '@/server/typedPlugin';
import { FastifyRequest } from 'fastify';
@@ -29,6 +30,11 @@ const paramsSchema = z.object({
id: z.string(),
});
const folderMutationInclude = {
_count: { select: { children: true, files: true } },
parent: { select: { id: true, name: true, parentId: true } },
} as const;
const folderExistsAndEditable = async (req: FastifyRequest) => {
const { id } = req.params as z.infer<typeof paramsSchema>;
@@ -52,8 +58,12 @@ export default typedPlugin(
PATH,
{
schema: {
description: 'Fetch a specific folder by ID, including files, children, and its parent chain.',
description:
'Fetch a specific folder by ID, optionally including files, children, and its parent chain.',
params: paramsSchema,
querystring: z.object({
noincl: zQsBoolean.optional(),
}),
response: {
200: folderSchema.partial(),
},
@@ -63,18 +73,21 @@ export default typedPlugin(
},
async (req, res) => {
const { id } = req.params;
const { noincl } = req.query;
const folder = await prisma.folder.findUnique({
where: {
id,
},
include: {
files: {
select: {
...fileSelect,
password: true,
...(!noincl && {
files: {
select: {
...fileSelect,
password: true,
},
},
},
}),
User: true,
children: {
orderBy: { createdAt: 'desc' },
@@ -98,7 +111,7 @@ export default typedPlugin(
(folder as any).parent = await buildParentChain(folder.parentId);
}
return res.send(cleanFolder(folder));
return res.send(cleanFolder(folder as unknown as Partial<Folder>));
},
);
@@ -149,15 +162,7 @@ export default typedPlugin(
data: {
files: { connect: { id } },
},
include: {
files: {
select: {
...fileSelect,
password: true,
},
},
User: true,
},
include: folderMutationInclude,
});
logger.info('file added to folder', { folder: folderId, file: id });
@@ -227,20 +232,7 @@ export default typedPlugin(
...(allowUploads !== undefined && { allowUploads }),
...(parentId !== undefined && { parentId }),
},
include: {
files: {
select: {
...fileSelect,
password: true,
},
},
_count: {
select: { children: true, files: true },
},
parent: {
select: { id: true, name: true, parentId: true },
},
},
include: folderMutationInclude,
});
logger.info('folder updated', {
@@ -267,7 +259,7 @@ export default typedPlugin(
delete: z.enum(['file', 'folder']),
id: zStringTrimmed.optional(),
childrenAction: z.enum(['root', 'folder', 'cascade']).optional(),
childrenAction: z.enum(['root', 'folder', 'cascade', 'cascade-files']).optional(),
targetFolderId: z.string().optional(),
}),
params: paramsSchema,
@@ -299,6 +291,8 @@ export default typedPlugin(
}
try {
const toDeleteFiles: string[] = [];
const result = await prisma.$transaction(async (tx) => {
if (!childrenAction) {
return { success: true };
@@ -320,7 +314,9 @@ export default typedPlugin(
});
return { success: true };
} else if (childrenAction === 'cascade') {
} else if (childrenAction === 'cascade' || childrenAction === 'cascade-files') {
const deleteFiles = childrenAction === 'cascade-files';
const deleteRecursive = async (id: string) => {
const children = await tx.folder.findMany({
where: { parentId: id },
@@ -329,6 +325,16 @@ export default typedPlugin(
for (const child of children) {
await deleteRecursive(child.id);
}
if (deleteFiles) {
const files = await tx.file.findMany({
where: { folderId: id },
select: { name: true },
});
toDeleteFiles.push(...files.map((f) => f.name));
await tx.file.deleteMany({ where: { folderId: id } });
}
await tx.folder.delete({ where: { id } });
};
@@ -341,7 +347,11 @@ export default typedPlugin(
if (!result?.success) throw new ApiError(1019);
if (result?.isCascade) {
logger.info('folder cascade deleted', { folder: folderId });
for (const name of toDeleteFiles) {
await datasource.delete(name);
}
logger.info('folder cascade deleted', { folder: folderId, files: toDeleteFiles.length });
return res.send({ success: true });
} else {
await prisma.folder.delete({ where: { id: folderId } });
@@ -379,14 +389,7 @@ export default typedPlugin(
data: {
files: { disconnect: { id } },
},
include: {
files: {
select: {
...fileSelect,
password: true,
},
},
},
include: folderMutationInclude,
});
logger.info('file removed from folder', { folder: nFolder.id, file: id });
+9 -9
View File
@@ -37,24 +37,23 @@ export default typedPlugin(
preHandler: [userMiddleware],
},
async (req, res) => {
const { noincl, user, parentId, root } = req.query;
const { noincl, user: userId, parentId, root } = req.query;
if (user) {
const user = await prisma.user.findUnique({
if (userId) {
const targetUser = await prisma.user.findUnique({
where: {
id: req.user.id,
id: userId,
},
});
if (!user) throw new ApiError(4009);
if (req.user.id !== user.id) {
if (!canInteract(req.user.role, user.role)) throw new ApiError(4009);
}
if (!targetUser) throw new ApiError(4009);
if (req.user.id !== targetUser.id && !canInteract(req.user.role, targetUser.role))
throw new ApiError(4009);
}
const folders = await prisma.folder.findMany({
where: {
userId: user || req.user.id,
userId: userId || req.user.id,
...(root && { parentId: null }),
...(parentId && { parentId }),
},
@@ -133,6 +132,7 @@ export default typedPlugin(
id: {
in: files,
},
userId: req.user.id,
},
select: {
id: true,
+4
View File
@@ -58,6 +58,7 @@ export default typedPlugin(
embedColor: z.string().nullish(),
embedSiteName: z.string().nullish(),
enabled: z.boolean().optional(),
disableTextFiles: z.boolean().optional(),
align: z.enum(['left', 'center', 'right']).optional(),
showMimetype: z.boolean().optional(),
showTags: z.boolean().optional(),
@@ -100,6 +101,9 @@ export default typedPlugin(
view: {
...req.user.view,
...(req.body.view.enabled !== undefined && { enabled: req.body.view.enabled || false }),
...(req.body.view.disableTextFiles !== undefined && {
disableTextFiles: req.body.view.disableTextFiles || false,
}),
...(req.body.view.content !== undefined && { content: req.body.view.content || null }),
...(req.body.view.embed !== undefined && { embed: req.body.view.embed || false }),
...(req.body.view.embedMediaOnly !== undefined && {
+19 -17
View File
@@ -3,7 +3,7 @@ import { bytes } from '@/lib/bytes';
import { hashPassword } from '@/lib/crypto';
import { datasource } from '@/lib/datasource';
import { prisma } from '@/lib/db';
import { User, userSchema, userSelect } from '@/lib/db/models/user';
import { LimitedUser, limitedUserSchema, limitedUserSelect } from '@/lib/db/models/user';
import { log } from '@/lib/logger';
import { canInteract } from '@/lib/role';
import { zStringTrimmed } from '@/lib/validation';
@@ -13,7 +13,7 @@ import { userMiddleware } from '@/server/middleware/user';
import typedPlugin from '@/server/typedPlugin';
import { z } from 'zod';
export type ApiUsersIdResponse = User;
export type ApiUsersIdResponse = LimitedUser;
const logger = log('api').c('users').c('[id]');
@@ -31,7 +31,7 @@ export default typedPlugin(
description: 'Fetch a specific user by ID, including their profile and role (admin only).',
params: paramsSchema,
response: {
200: userSchema,
200: limitedUserSchema,
},
tags: ['auth', 'admin'],
},
@@ -42,10 +42,11 @@ export default typedPlugin(
where: {
id: req.params.id,
},
select: userSelect,
select: limitedUserSelect,
});
if (!user) throw new ApiError(4009);
if (!canInteract(req.user.role, user.role)) throw new ApiError(4009);
return res.send(user);
},
@@ -73,7 +74,7 @@ export default typedPlugin(
.optional(),
}),
response: {
200: userSchema,
200: limitedUserSchema,
},
tags: ['auth', 'admin'],
},
@@ -84,9 +85,13 @@ export default typedPlugin(
where: {
id: req.params.id,
},
select: userSelect,
select: {
id: true,
role: true,
},
});
if (!user) throw new ApiError(4009);
if (!canInteract(req.user.role, user.role)) throw new ApiError(3019);
const { username, password, avatar, role, quota } = req.body;
if (role && !canInteract(req.user.role, role)) throw new ApiError(3007);
@@ -149,11 +154,7 @@ export default typedPlugin(
},
}),
},
select: {
...userSelect,
totpSecret: false,
passkeys: false,
},
select: limitedUserSelect,
});
logger.info(`${req.user.username} updated another user`, {
@@ -176,7 +177,7 @@ export default typedPlugin(
delete: z.boolean().optional(),
}),
response: {
200: userSchema,
200: limitedUserSchema,
},
tags: ['auth', 'admin'],
},
@@ -187,7 +188,11 @@ export default typedPlugin(
where: {
id: req.params.id,
},
select: userSelect,
select: {
id: true,
role: true,
username: true,
},
});
if (!user) throw new ApiError(4009);
@@ -242,10 +247,7 @@ export default typedPlugin(
where: {
id: user.id,
},
select: {
...userSelect,
totpSecret: false,
},
select: limitedUserSelect,
});
logger.info(`${req.user.username} deleted another user`, {
+10 -11
View File
@@ -2,10 +2,10 @@ import { ApiError } from '@/lib/api/errors';
import { config } from '@/lib/config';
import { createToken, hashPassword } from '@/lib/crypto';
import { prisma } from '@/lib/db';
import { User, userSchema, userSelect } from '@/lib/db/models/user';
import { LimitedUser, limitedUserSchema, limitedUserSelect } from '@/lib/db/models/user';
import { log } from '@/lib/logger';
import { secondlyRatelimit } from '@/lib/ratelimits';
import { canInteract } from '@/lib/role';
import { canInteract, interactableRoles } from '@/lib/role';
import { zQsBoolean, zStringTrimmed } from '@/lib/validation';
import { Role } from '@/prisma/client';
import { administratorMiddleware } from '@/server/middleware/administrator';
@@ -14,7 +14,7 @@ import typedPlugin from '@/server/typedPlugin';
import { readFile } from 'fs/promises';
import { z } from 'zod';
export type ApiUsersResponse = User[] | User;
export type ApiUsersResponse = LimitedUser[] | LimitedUser;
const logger = log('api').c('users');
@@ -33,19 +33,22 @@ export default typedPlugin(
'List users in the instance, optionally excluding the current admin from the results (admin only).',
querystring: querySchema,
response: {
200: z.array(userSchema),
200: z.array(limitedUserSchema),
},
tags: ['auth', 'admin'],
},
preHandler: [userMiddleware, administratorMiddleware],
},
async (req, res) => {
const roles = interactableRoles(req.user.role);
const users = await prisma.user.findMany({
select: {
...userSelect,
...limitedUserSelect,
avatar: true,
},
where: {
role: { in: roles },
...(req.query.noincl && { id: { not: req.user.id } }),
},
});
@@ -67,7 +70,7 @@ export default typedPlugin(
role: z.enum(Role).default('USER').optional(),
}),
response: {
200: userSchema,
200: limitedUserSchema,
},
tags: ['auth', 'admin'],
},
@@ -106,11 +109,7 @@ export default typedPlugin(
avatar: avatar64 ?? null,
token: createToken(),
},
select: {
...userSelect,
totpSecret: false,
passkeys: false,
},
select: limitedUserSelect,
});
logger.info(`${req.user.username} created a new user`, {
+3 -2
View File
@@ -1,6 +1,7 @@
import { ApiError } from '@/lib/api/errors';
import { config } from '@/lib/config';
import { log } from '@/lib/logger';
import { isAdministrator } from '@/lib/role';
import { getVersion } from '@/lib/version';
import { userMiddleware } from '@/server/middleware/user';
import typedPlugin from '@/server/typedPlugin';
@@ -64,8 +65,8 @@ export default typedPlugin(
},
preHandler: [userMiddleware],
},
async (_, res) => {
if (!config.features.versionChecking) throw new ApiError(9002);
async (req, res) => {
if (!config.features.versionChecking && !isAdministrator(req.user.role)) throw new ApiError(9002);
const details = getVersion();
+28 -11
View File
@@ -1,3 +1,4 @@
import { findFileByName } from '@/lib/db/models/file';
import { prisma } from '@/lib/db';
import { FastifyReply, FastifyRequest } from 'fastify';
import { rawFileHandler } from './raw/[id]';
@@ -16,19 +17,35 @@ export async function filesRoute(
res: FastifyReply,
) {
const { id } = req.params;
const file = await prisma.file.findFirst({
where: {
name: decodeURIComponent(id),
},
include: {
User: true,
},
});
const file = await findFileByName(id, (where, orderBy) =>
prisma.file.findFirst({
where,
...(orderBy && { orderBy }),
select: {
name: true,
type: true,
password: true,
User: {
select: {
view: true,
},
},
},
}),
);
if (!file) return res.callNotFound();
if (file.User?.view.enabled) return res.redirect(`/view/${encodeURIComponent(file.name)}`);
if (file.type.startsWith('text/')) return res.redirect(`/view/${encodeURIComponent(file.name)}`);
if (file.password) return res.redirect(`/view/${encodeURIComponent(file.name)}`);
const viewUrl = `/view/${encodeURIComponent(file.name)}`;
if (file.password) return res.redirect(viewUrl);
if (file.type.startsWith('text/')) {
if (file.User?.view?.disableTextFiles) return rawFileHandler(req, res);
return res.redirect(viewUrl);
}
if (file.User?.view?.enabled) return res.redirect(viewUrl);
return rawFileHandler(req, res);
}
+12 -6
View File
@@ -3,7 +3,9 @@ import { ApiError } from '@/lib/api/errors';
import { parseRange } from '@/lib/api/range';
import { config } from '@/lib/config';
import { datasource } from '@/lib/datasource';
import { findFileByName } from '@/lib/db/models/file';
import { prisma } from '@/lib/db';
import { sanitizeFilename } from '@/lib/fs';
import { log } from '@/lib/logger';
import { guess } from '@/lib/mimes';
import { TimedCache } from '@/lib/timedCache';
@@ -34,10 +36,16 @@ export const rawFileHandler = async (
const { id } = req.params;
const { token, download } = req.query;
const idSanitized = sanitizeFilename(id);
if (!idSanitized) return res.callNotFound();
if (id.startsWith('.thumbnail')) {
const thumbnail = await prisma.thumbnail.findFirst({
where: {
path: id,
path: idSanitized,
file: {
password: null,
},
},
});
@@ -58,11 +66,9 @@ export const rawFileHandler = async (
.send(buf);
}
const file = await prisma.file.findFirst({
where: {
name: decodeURIComponent(id),
},
});
const file = await findFileByName(idSanitized, (where, orderBy) =>
prisma.file.findFirst({ where, ...(orderBy && { orderBy }) }),
);
if (!file) return res.callNotFound();
if (file?.deletesAt && file.deletesAt <= new Date()) {
+2
View File
@@ -19,6 +19,8 @@ export async function unixSocketPath() {
logger.warn('removed existing unix socket before listen', { path });
return path;
} catch (error) {
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return path;
logger.warn('error while checking for existing unix socket', { path, error });
process.exit(1);
}