mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 16:16:55 +00:00
Compare commits
25 Commits
182ec18a2b
...
v0.7.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3906ec4371 | ||
|
|
5d130204a6 | ||
|
|
4997b1f38c | ||
|
|
1d3704bfad | ||
|
|
ae1d34fc6b | ||
|
|
f10a0a2da3 | ||
|
|
0eb1d29259 | ||
|
|
cf0f8fe0b9 | ||
|
|
30c56e0926 | ||
|
|
83d595636b | ||
|
|
008c8ad6ba | ||
|
|
5729af380d | ||
|
|
c0e71993e9 | ||
|
|
280d46b48d | ||
|
|
d1f9018213 | ||
|
|
2e3cd4f8a2 | ||
|
|
d98be331ad | ||
|
|
841c57e8fc | ||
|
|
90ac5ba4c3 | ||
|
|
dfffa004ac | ||
|
|
0cd55a413d | ||
|
|
361d966a59 | ||
|
|
aef43b8bfa | ||
|
|
7f128cccf6 | ||
|
|
a198e5f6dc |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "arkvault",
|
||||
"private": true,
|
||||
"version": "0.6.0",
|
||||
"version": "0.7.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
@@ -17,11 +17,12 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^2.0.0",
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@iconify-json/material-symbols": "^1.2.50",
|
||||
"@sveltejs/adapter-node": "^5.4.0",
|
||||
"@sveltejs/kit": "^2.49.2",
|
||||
"@sveltejs/vite-plugin-svelte": "^6.2.1",
|
||||
"@tanstack/svelte-virtual": "^3.13.13",
|
||||
"@tanstack/svelte-virtual": "^3.13.16",
|
||||
"@trpc/client": "^11.8.1",
|
||||
"@types/file-saver": "^2.0.7",
|
||||
"@types/ms": "^0.7.34",
|
||||
@@ -49,7 +50,7 @@
|
||||
"svelte-check": "^4.3.5",
|
||||
"tailwindcss": "^3.4.19",
|
||||
"typescript": "^5.9.3",
|
||||
"typescript-eslint": "^8.50.1",
|
||||
"typescript-eslint": "^8.51.0",
|
||||
"unplugin-icons": "^22.5.0",
|
||||
"vite": "^7.3.0"
|
||||
},
|
||||
@@ -63,7 +64,7 @@
|
||||
"pg": "^8.16.3",
|
||||
"superjson": "^2.2.6",
|
||||
"uuid": "^13.0.0",
|
||||
"zod": "^4.2.1"
|
||||
"zod": "^4.3.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^22.0.0",
|
||||
|
||||
201
pnpm-lock.yaml
generated
201
pnpm-lock.yaml
generated
@@ -36,12 +36,15 @@ importers:
|
||||
specifier: ^13.0.0
|
||||
version: 13.0.0
|
||||
zod:
|
||||
specifier: ^4.2.1
|
||||
version: 4.2.1
|
||||
specifier: ^4.3.5
|
||||
version: 4.3.5
|
||||
devDependencies:
|
||||
'@eslint/compat':
|
||||
specifier: ^2.0.0
|
||||
version: 2.0.0(eslint@9.39.2(jiti@1.21.7))
|
||||
'@eslint/js':
|
||||
specifier: ^9.39.2
|
||||
version: 9.39.2
|
||||
'@iconify-json/material-symbols':
|
||||
specifier: ^1.2.50
|
||||
version: 1.2.50
|
||||
@@ -55,8 +58,8 @@ importers:
|
||||
specifier: ^6.2.1
|
||||
version: 6.2.1(svelte@5.46.1)(vite@7.3.0(@types/node@25.0.3)(jiti@1.21.7)(yaml@2.8.0))
|
||||
'@tanstack/svelte-virtual':
|
||||
specifier: ^3.13.13
|
||||
version: 3.13.13(svelte@5.46.1)
|
||||
specifier: ^3.13.16
|
||||
version: 3.13.16(svelte@5.46.1)
|
||||
'@trpc/client':
|
||||
specifier: ^11.8.1
|
||||
version: 11.8.1(@trpc/server@11.8.1(typescript@5.9.3))(typescript@5.9.3)
|
||||
@@ -139,8 +142,8 @@ importers:
|
||||
specifier: ^5.9.3
|
||||
version: 5.9.3
|
||||
typescript-eslint:
|
||||
specifier: ^8.50.1
|
||||
version: 8.50.1(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
specifier: ^8.51.0
|
||||
version: 8.51.0(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
unplugin-icons:
|
||||
specifier: ^22.5.0
|
||||
version: 22.5.0(svelte@5.46.1)
|
||||
@@ -316,8 +319,8 @@ packages:
|
||||
cpu: [x64]
|
||||
os: [win32]
|
||||
|
||||
'@eslint-community/eslint-utils@4.9.0':
|
||||
resolution: {integrity: sha512-ayVFHdtZ+hsq1t2Dy24wCmGXGe4q9Gu3smhLYALJrr473ZH27MsnSL+LKUlimp4BWJqMDMLmPpx/Q9R3OAlL4g==}
|
||||
'@eslint-community/eslint-utils@4.9.1':
|
||||
resolution: {integrity: sha512-phrYmNiYppR7znFEdqgfWHXR6NCkZEK7hwWDHZUjit/2/U0r6XvkDl0SYnoM51Hq7FhCGdLDT6zxCCOY1hexsQ==}
|
||||
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
|
||||
peerDependencies:
|
||||
eslint: ^6.0.0 || ^7.0.0 || >=8.0.0
|
||||
@@ -617,13 +620,13 @@ packages:
|
||||
svelte: ^5.0.0
|
||||
vite: ^6.3.0 || ^7.0.0
|
||||
|
||||
'@tanstack/svelte-virtual@3.13.13':
|
||||
resolution: {integrity: sha512-VDOvbRw3R+XBQdFodEJ4E7AOmEyo3Bmr4zL4DLVnJ0fxICdbvY5F5t8zSwJ4f7lqjckXi0yKFzY8WBtjaNbsGQ==}
|
||||
'@tanstack/svelte-virtual@3.13.16':
|
||||
resolution: {integrity: sha512-LRDPRzAPTIiDjiCA9lhNlFnZRLj/XsNhzNRsT5JEA8hzcBmZw8avdYYVjydPAy0ObFJgG1zBAm9Dtvwqju36sg==}
|
||||
peerDependencies:
|
||||
svelte: ^3.48.0 || ^4.0.0 || ^5.0.0
|
||||
|
||||
'@tanstack/virtual-core@3.13.13':
|
||||
resolution: {integrity: sha512-uQFoSdKKf5S8k51W5t7b2qpfkyIbdHMzAn+AMQvHPxKUPeo1SsGaA4JRISQT87jm28b7z8OEqPcg1IOZagQHcA==}
|
||||
'@tanstack/virtual-core@3.13.16':
|
||||
resolution: {integrity: sha512-njazUC8mDkrxWmyZmn/3eXrDcP8Msb3chSr4q6a65RmwdSbMlMCdnOphv6/8mLO7O3Fuza5s4M4DclmvAO5w0w==}
|
||||
|
||||
'@trpc/client@11.8.1':
|
||||
resolution: {integrity: sha512-L/SJFGanr9xGABmuDoeXR4xAdHJmsXsiF9OuH+apecJ+8sUITzVT1EPeqp0ebqA6lBhEl5pPfg3rngVhi/h60Q==}
|
||||
@@ -663,63 +666,63 @@ packages:
|
||||
'@types/resolve@1.20.2':
|
||||
resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==}
|
||||
|
||||
'@typescript-eslint/eslint-plugin@8.50.1':
|
||||
resolution: {integrity: sha512-PKhLGDq3JAg0Jk/aK890knnqduuI/Qj+udH7wCf0217IGi4gt+acgCyPVe79qoT+qKUvHMDQkwJeKW9fwl8Cyw==}
|
||||
'@typescript-eslint/eslint-plugin@8.51.0':
|
||||
resolution: {integrity: sha512-XtssGWJvypyM2ytBnSnKtHYOGT+4ZwTnBVl36TA4nRO2f4PRNGz5/1OszHzcZCvcBMh+qb7I06uoCmLTRdR9og==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
peerDependencies:
|
||||
'@typescript-eslint/parser': ^8.50.1
|
||||
'@typescript-eslint/parser': ^8.51.0
|
||||
eslint: ^8.57.0 || ^9.0.0
|
||||
typescript: '>=4.8.4 <6.0.0'
|
||||
|
||||
'@typescript-eslint/parser@8.50.1':
|
||||
resolution: {integrity: sha512-hM5faZwg7aVNa819m/5r7D0h0c9yC4DUlWAOvHAtISdFTc8xB86VmX5Xqabrama3wIPJ/q9RbGS1worb6JfnMg==}
|
||||
'@typescript-eslint/parser@8.51.0':
|
||||
resolution: {integrity: sha512-3xP4XzzDNQOIqBMWogftkwxhg5oMKApqY0BAflmLZiFYHqyhSOxv/cd/zPQLTcCXr4AkaKb25joocY0BD1WC6A==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
peerDependencies:
|
||||
eslint: ^8.57.0 || ^9.0.0
|
||||
typescript: '>=4.8.4 <6.0.0'
|
||||
|
||||
'@typescript-eslint/project-service@8.50.1':
|
||||
resolution: {integrity: sha512-E1ur1MCVf+YiP89+o4Les/oBAVzmSbeRB0MQLfSlYtbWU17HPxZ6Bhs5iYmKZRALvEuBoXIZMOIRRc/P++Ortg==}
|
||||
'@typescript-eslint/project-service@8.51.0':
|
||||
resolution: {integrity: sha512-Luv/GafO07Z7HpiI7qeEW5NW8HUtZI/fo/kE0YbtQEFpJRUuR0ajcWfCE5bnMvL7QQFrmT/odMe8QZww8X2nfQ==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
peerDependencies:
|
||||
typescript: '>=4.8.4 <6.0.0'
|
||||
|
||||
'@typescript-eslint/scope-manager@8.50.1':
|
||||
resolution: {integrity: sha512-mfRx06Myt3T4vuoHaKi8ZWNTPdzKPNBhiblze5N50//TSHOAQQevl/aolqA/BcqqbJ88GUnLqjjcBc8EWdBcVw==}
|
||||
'@typescript-eslint/scope-manager@8.51.0':
|
||||
resolution: {integrity: sha512-JhhJDVwsSx4hiOEQPeajGhCWgBMBwVkxC/Pet53EpBVs7zHHtayKefw1jtPaNRXpI9RA2uocdmpdfE7T+NrizA==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
|
||||
'@typescript-eslint/tsconfig-utils@8.50.1':
|
||||
resolution: {integrity: sha512-ooHmotT/lCWLXi55G4mvaUF60aJa012QzvLK0Y+Mp4WdSt17QhMhWOaBWeGTFVkb2gDgBe19Cxy1elPXylslDw==}
|
||||
'@typescript-eslint/tsconfig-utils@8.51.0':
|
||||
resolution: {integrity: sha512-Qi5bSy/vuHeWyir2C8u/uqGMIlIDu8fuiYWv48ZGlZ/k+PRPHtaAu7erpc7p5bzw2WNNSniuxoMSO4Ar6V9OXw==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
peerDependencies:
|
||||
typescript: '>=4.8.4 <6.0.0'
|
||||
|
||||
'@typescript-eslint/type-utils@8.50.1':
|
||||
resolution: {integrity: sha512-7J3bf022QZE42tYMO6SL+6lTPKFk/WphhRPe9Tw/el+cEwzLz1Jjz2PX3GtGQVxooLDKeMVmMt7fWpYRdG5Etg==}
|
||||
'@typescript-eslint/type-utils@8.51.0':
|
||||
resolution: {integrity: sha512-0XVtYzxnobc9K0VU7wRWg1yiUrw4oQzexCG2V2IDxxCxhqBMSMbjB+6o91A+Uc0GWtgjCa3Y8bi7hwI0Tu4n5Q==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
peerDependencies:
|
||||
eslint: ^8.57.0 || ^9.0.0
|
||||
typescript: '>=4.8.4 <6.0.0'
|
||||
|
||||
'@typescript-eslint/types@8.50.1':
|
||||
resolution: {integrity: sha512-v5lFIS2feTkNyMhd7AucE/9j/4V9v5iIbpVRncjk/K0sQ6Sb+Np9fgYS/63n6nwqahHQvbmujeBL7mp07Q9mlA==}
|
||||
'@typescript-eslint/types@8.51.0':
|
||||
resolution: {integrity: sha512-TizAvWYFM6sSscmEakjY3sPqGwxZRSywSsPEiuZF6d5GmGD9Gvlsv0f6N8FvAAA0CD06l3rIcWNbsN1e5F/9Ag==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
|
||||
'@typescript-eslint/typescript-estree@8.50.1':
|
||||
resolution: {integrity: sha512-woHPdW+0gj53aM+cxchymJCrh0cyS7BTIdcDxWUNsclr9VDkOSbqC13juHzxOmQ22dDkMZEpZB+3X1WpUvzgVQ==}
|
||||
'@typescript-eslint/typescript-estree@8.51.0':
|
||||
resolution: {integrity: sha512-1qNjGqFRmlq0VW5iVlcyHBbCjPB7y6SxpBkrbhNWMy/65ZoncXCEPJxkRZL8McrseNH6lFhaxCIaX+vBuFnRng==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
peerDependencies:
|
||||
typescript: '>=4.8.4 <6.0.0'
|
||||
|
||||
'@typescript-eslint/utils@8.50.1':
|
||||
resolution: {integrity: sha512-lCLp8H1T9T7gPbEuJSnHwnSuO9mDf8mfK/Nion5mZmiEaQD9sWf9W4dfeFqRyqRjF06/kBuTmAqcs9sewM2NbQ==}
|
||||
'@typescript-eslint/utils@8.51.0':
|
||||
resolution: {integrity: sha512-11rZYxSe0zabiKaCP2QAwRf/dnmgFgvTmeDTtZvUvXG3UuAdg/GU02NExmmIXzz3vLGgMdtrIosI84jITQOxUA==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
peerDependencies:
|
||||
eslint: ^8.57.0 || ^9.0.0
|
||||
typescript: '>=4.8.4 <6.0.0'
|
||||
|
||||
'@typescript-eslint/visitor-keys@8.50.1':
|
||||
resolution: {integrity: sha512-IrDKrw7pCRUR94zeuCSUWQ+w8JEf5ZX5jl/e6AHGSLi1/zIr0lgutfn/7JpfCey+urpgQEdrZVYzCaVVKiTwhQ==}
|
||||
'@typescript-eslint/visitor-keys@8.51.0':
|
||||
resolution: {integrity: sha512-mM/JRQOzhVN1ykejrvwnBRV3+7yTKK8tVANVN3o1O0t0v7o+jqdVu9crPy5Y9dov15TJk/FTIgoUGHrTOVL3Zg==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
|
||||
'@xmldom/xmldom@0.9.8':
|
||||
@@ -827,8 +830,8 @@ packages:
|
||||
resolution: {integrity: sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA==}
|
||||
engines: {node: '>= 6'}
|
||||
|
||||
caniuse-lite@1.0.30001761:
|
||||
resolution: {integrity: sha512-JF9ptu1vP2coz98+5051jZ4PwQgd2ni8A+gYSN7EA7dPKIMf0pDlSUxhdmVOaV3/fYK5uWBkgSXJaRLr4+3A6g==}
|
||||
caniuse-lite@1.0.30001762:
|
||||
resolution: {integrity: sha512-PxZwGNvH7Ak8WX5iXzoK1KPZttBXNPuaOvI2ZYU7NrlM+d9Ov+TUvlLOBNGzVXAntMSMMlJPd+jY6ovrVjSmUw==}
|
||||
|
||||
chalk@4.1.2:
|
||||
resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==}
|
||||
@@ -1039,8 +1042,8 @@ packages:
|
||||
resolution: {integrity: sha512-j6PAQ2uUr79PZhBjP5C5fhl8e39FmRnOjsD5lGnWrFU8i2G776tBK7+nP8KuQUTTyAZUwfQqXAgrVH5MbH9CYQ==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
|
||||
esquery@1.6.0:
|
||||
resolution: {integrity: sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg==}
|
||||
esquery@1.7.0:
|
||||
resolution: {integrity: sha512-Ap6G0WQwcU/LHsvLwON1fAQX9Zp0A2Y6Y/cJBl9r/JbW90Zyg4/zbG6zzKa2OTALELarYHmKu0GhpM5EO+7T0g==}
|
||||
engines: {node: '>=0.10'}
|
||||
|
||||
esrap@2.2.1:
|
||||
@@ -1854,8 +1857,8 @@ packages:
|
||||
resolution: {integrity: sha512-sf4i37nQ2LBx4m3wB74y+ubopq6W/dIzXg0FDGjsYnZHVa1Da8FH853wlL2gtUhg+xJXjfk3kUZS3BRoQeoQBQ==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
ts-api-utils@2.1.0:
|
||||
resolution: {integrity: sha512-CUgTZL1irw8u29bzrOD/nH85jqyc74D6SshFgujOIA7osm2Rz7dYH77agkx7H4FBNxDq7Cjf+IjaX/8zwFW+ZQ==}
|
||||
ts-api-utils@2.4.0:
|
||||
resolution: {integrity: sha512-3TaVTaAv2gTiMB35i3FiGJaRfwb3Pyn/j3m/bfAvGe8FB7CF6u+LMYqYlDh7reQf7UNvoTvdfAqHGmPGOSsPmA==}
|
||||
engines: {node: '>=18.12'}
|
||||
peerDependencies:
|
||||
typescript: '>=4.8.4'
|
||||
@@ -1877,8 +1880,8 @@ packages:
|
||||
resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==}
|
||||
engines: {node: '>= 0.8.0'}
|
||||
|
||||
typescript-eslint@8.50.1:
|
||||
resolution: {integrity: sha512-ytTHO+SoYSbhAH9CrYnMhiLx8To6PSSvqnvXyPUgPETCvB6eBKmTI9w6XMPS3HsBRGkwTVBX+urA8dYQx6bHfQ==}
|
||||
typescript-eslint@8.51.0:
|
||||
resolution: {integrity: sha512-jh8ZuM5oEh2PSdyQG9YAEM1TCGuWenLSuSUhf/irbVUNW9O5FhbFVONviN2TgMTBnUmyHv7E56rYnfLZK6TkiA==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
peerDependencies:
|
||||
eslint: ^8.57.0 || ^9.0.0
|
||||
@@ -2022,8 +2025,8 @@ packages:
|
||||
zimmerframe@1.1.4:
|
||||
resolution: {integrity: sha512-B58NGBEoc8Y9MWWCQGl/gq9xBCe4IiKM0a2x7GZdQKOW5Exr8S1W24J6OgM1njK8xCRGvAJIL/MxXHf6SkmQKQ==}
|
||||
|
||||
zod@4.2.1:
|
||||
resolution: {integrity: sha512-0wZ1IRqGGhMP76gLqz8EyfBXKk0J2qo2+H3fi4mcUP/KtTocoX08nmIAHl1Z2kJIZbZee8KOpBCSNPRgauucjw==}
|
||||
zod@4.3.5:
|
||||
resolution: {integrity: sha512-k7Nwx6vuWx1IJ9Bjuf4Zt1PEllcwe7cls3VNzm4CQ1/hgtFUK2bRNG3rvnpPUhFjmqJKAKtjV576KnUkHocg/g==}
|
||||
|
||||
snapshots:
|
||||
|
||||
@@ -2114,7 +2117,7 @@ snapshots:
|
||||
'@esbuild/win32-x64@0.27.2':
|
||||
optional: true
|
||||
|
||||
'@eslint-community/eslint-utils@4.9.0(eslint@9.39.2(jiti@1.21.7))':
|
||||
'@eslint-community/eslint-utils@4.9.1(eslint@9.39.2(jiti@1.21.7))':
|
||||
dependencies:
|
||||
eslint: 9.39.2(jiti@1.21.7)
|
||||
eslint-visitor-keys: 3.4.3
|
||||
@@ -2386,12 +2389,12 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@tanstack/svelte-virtual@3.13.13(svelte@5.46.1)':
|
||||
'@tanstack/svelte-virtual@3.13.16(svelte@5.46.1)':
|
||||
dependencies:
|
||||
'@tanstack/virtual-core': 3.13.13
|
||||
'@tanstack/virtual-core': 3.13.16
|
||||
svelte: 5.46.1
|
||||
|
||||
'@tanstack/virtual-core@3.13.13': {}
|
||||
'@tanstack/virtual-core@3.13.16': {}
|
||||
|
||||
'@trpc/client@11.8.1(@trpc/server@11.8.1(typescript@5.9.3))(typescript@5.9.3)':
|
||||
dependencies:
|
||||
@@ -2428,95 +2431,95 @@ snapshots:
|
||||
|
||||
'@types/resolve@1.20.2': {}
|
||||
|
||||
'@typescript-eslint/eslint-plugin@8.50.1(@typescript-eslint/parser@8.50.1(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3))(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)':
|
||||
'@typescript-eslint/eslint-plugin@8.51.0(@typescript-eslint/parser@8.51.0(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3))(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)':
|
||||
dependencies:
|
||||
'@eslint-community/regexpp': 4.12.2
|
||||
'@typescript-eslint/parser': 8.50.1(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
'@typescript-eslint/scope-manager': 8.50.1
|
||||
'@typescript-eslint/type-utils': 8.50.1(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
'@typescript-eslint/utils': 8.50.1(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
'@typescript-eslint/visitor-keys': 8.50.1
|
||||
'@typescript-eslint/parser': 8.51.0(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
'@typescript-eslint/scope-manager': 8.51.0
|
||||
'@typescript-eslint/type-utils': 8.51.0(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
'@typescript-eslint/utils': 8.51.0(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
'@typescript-eslint/visitor-keys': 8.51.0
|
||||
eslint: 9.39.2(jiti@1.21.7)
|
||||
ignore: 7.0.5
|
||||
natural-compare: 1.4.0
|
||||
ts-api-utils: 2.1.0(typescript@5.9.3)
|
||||
ts-api-utils: 2.4.0(typescript@5.9.3)
|
||||
typescript: 5.9.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@typescript-eslint/parser@8.50.1(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)':
|
||||
'@typescript-eslint/parser@8.51.0(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)':
|
||||
dependencies:
|
||||
'@typescript-eslint/scope-manager': 8.50.1
|
||||
'@typescript-eslint/types': 8.50.1
|
||||
'@typescript-eslint/typescript-estree': 8.50.1(typescript@5.9.3)
|
||||
'@typescript-eslint/visitor-keys': 8.50.1
|
||||
'@typescript-eslint/scope-manager': 8.51.0
|
||||
'@typescript-eslint/types': 8.51.0
|
||||
'@typescript-eslint/typescript-estree': 8.51.0(typescript@5.9.3)
|
||||
'@typescript-eslint/visitor-keys': 8.51.0
|
||||
debug: 4.4.3
|
||||
eslint: 9.39.2(jiti@1.21.7)
|
||||
typescript: 5.9.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@typescript-eslint/project-service@8.50.1(typescript@5.9.3)':
|
||||
'@typescript-eslint/project-service@8.51.0(typescript@5.9.3)':
|
||||
dependencies:
|
||||
'@typescript-eslint/tsconfig-utils': 8.50.1(typescript@5.9.3)
|
||||
'@typescript-eslint/types': 8.50.1
|
||||
'@typescript-eslint/tsconfig-utils': 8.51.0(typescript@5.9.3)
|
||||
'@typescript-eslint/types': 8.51.0
|
||||
debug: 4.4.3
|
||||
typescript: 5.9.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@typescript-eslint/scope-manager@8.50.1':
|
||||
'@typescript-eslint/scope-manager@8.51.0':
|
||||
dependencies:
|
||||
'@typescript-eslint/types': 8.50.1
|
||||
'@typescript-eslint/visitor-keys': 8.50.1
|
||||
'@typescript-eslint/types': 8.51.0
|
||||
'@typescript-eslint/visitor-keys': 8.51.0
|
||||
|
||||
'@typescript-eslint/tsconfig-utils@8.50.1(typescript@5.9.3)':
|
||||
'@typescript-eslint/tsconfig-utils@8.51.0(typescript@5.9.3)':
|
||||
dependencies:
|
||||
typescript: 5.9.3
|
||||
|
||||
'@typescript-eslint/type-utils@8.50.1(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)':
|
||||
'@typescript-eslint/type-utils@8.51.0(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)':
|
||||
dependencies:
|
||||
'@typescript-eslint/types': 8.50.1
|
||||
'@typescript-eslint/typescript-estree': 8.50.1(typescript@5.9.3)
|
||||
'@typescript-eslint/utils': 8.50.1(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
'@typescript-eslint/types': 8.51.0
|
||||
'@typescript-eslint/typescript-estree': 8.51.0(typescript@5.9.3)
|
||||
'@typescript-eslint/utils': 8.51.0(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
debug: 4.4.3
|
||||
eslint: 9.39.2(jiti@1.21.7)
|
||||
ts-api-utils: 2.1.0(typescript@5.9.3)
|
||||
ts-api-utils: 2.4.0(typescript@5.9.3)
|
||||
typescript: 5.9.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@typescript-eslint/types@8.50.1': {}
|
||||
'@typescript-eslint/types@8.51.0': {}
|
||||
|
||||
'@typescript-eslint/typescript-estree@8.50.1(typescript@5.9.3)':
|
||||
'@typescript-eslint/typescript-estree@8.51.0(typescript@5.9.3)':
|
||||
dependencies:
|
||||
'@typescript-eslint/project-service': 8.50.1(typescript@5.9.3)
|
||||
'@typescript-eslint/tsconfig-utils': 8.50.1(typescript@5.9.3)
|
||||
'@typescript-eslint/types': 8.50.1
|
||||
'@typescript-eslint/visitor-keys': 8.50.1
|
||||
'@typescript-eslint/project-service': 8.51.0(typescript@5.9.3)
|
||||
'@typescript-eslint/tsconfig-utils': 8.51.0(typescript@5.9.3)
|
||||
'@typescript-eslint/types': 8.51.0
|
||||
'@typescript-eslint/visitor-keys': 8.51.0
|
||||
debug: 4.4.3
|
||||
minimatch: 9.0.5
|
||||
semver: 7.7.3
|
||||
tinyglobby: 0.2.15
|
||||
ts-api-utils: 2.1.0(typescript@5.9.3)
|
||||
ts-api-utils: 2.4.0(typescript@5.9.3)
|
||||
typescript: 5.9.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@typescript-eslint/utils@8.50.1(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)':
|
||||
'@typescript-eslint/utils@8.51.0(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)':
|
||||
dependencies:
|
||||
'@eslint-community/eslint-utils': 4.9.0(eslint@9.39.2(jiti@1.21.7))
|
||||
'@typescript-eslint/scope-manager': 8.50.1
|
||||
'@typescript-eslint/types': 8.50.1
|
||||
'@typescript-eslint/typescript-estree': 8.50.1(typescript@5.9.3)
|
||||
'@eslint-community/eslint-utils': 4.9.1(eslint@9.39.2(jiti@1.21.7))
|
||||
'@typescript-eslint/scope-manager': 8.51.0
|
||||
'@typescript-eslint/types': 8.51.0
|
||||
'@typescript-eslint/typescript-estree': 8.51.0(typescript@5.9.3)
|
||||
eslint: 9.39.2(jiti@1.21.7)
|
||||
typescript: 5.9.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@typescript-eslint/visitor-keys@8.50.1':
|
||||
'@typescript-eslint/visitor-keys@8.51.0':
|
||||
dependencies:
|
||||
'@typescript-eslint/types': 8.50.1
|
||||
'@typescript-eslint/types': 8.51.0
|
||||
eslint-visitor-keys: 4.2.1
|
||||
|
||||
'@xmldom/xmldom@0.9.8':
|
||||
@@ -2564,7 +2567,7 @@ snapshots:
|
||||
autoprefixer@10.4.23(postcss@8.5.6):
|
||||
dependencies:
|
||||
browserslist: 4.28.1
|
||||
caniuse-lite: 1.0.30001761
|
||||
caniuse-lite: 1.0.30001762
|
||||
fraction.js: 5.3.4
|
||||
picocolors: 1.1.1
|
||||
postcss: 8.5.6
|
||||
@@ -2602,7 +2605,7 @@ snapshots:
|
||||
browserslist@4.28.1:
|
||||
dependencies:
|
||||
baseline-browser-mapping: 2.9.11
|
||||
caniuse-lite: 1.0.30001761
|
||||
caniuse-lite: 1.0.30001762
|
||||
electron-to-chromium: 1.5.267
|
||||
node-releases: 2.0.27
|
||||
update-browserslist-db: 1.2.3(browserslist@4.28.1)
|
||||
@@ -2631,7 +2634,7 @@ snapshots:
|
||||
|
||||
camelcase-css@2.0.1: {}
|
||||
|
||||
caniuse-lite@1.0.30001761: {}
|
||||
caniuse-lite@1.0.30001762: {}
|
||||
|
||||
chalk@4.1.2:
|
||||
dependencies:
|
||||
@@ -2795,7 +2798,7 @@ snapshots:
|
||||
|
||||
eslint-plugin-svelte@3.13.1(eslint@9.39.2(jiti@1.21.7))(svelte@5.46.1):
|
||||
dependencies:
|
||||
'@eslint-community/eslint-utils': 4.9.0(eslint@9.39.2(jiti@1.21.7))
|
||||
'@eslint-community/eslint-utils': 4.9.1(eslint@9.39.2(jiti@1.21.7))
|
||||
'@jridgewell/sourcemap-codec': 1.5.5
|
||||
eslint: 9.39.2(jiti@1.21.7)
|
||||
esutils: 2.0.3
|
||||
@@ -2828,7 +2831,7 @@ snapshots:
|
||||
|
||||
eslint@9.39.2(jiti@1.21.7):
|
||||
dependencies:
|
||||
'@eslint-community/eslint-utils': 4.9.0(eslint@9.39.2(jiti@1.21.7))
|
||||
'@eslint-community/eslint-utils': 4.9.1(eslint@9.39.2(jiti@1.21.7))
|
||||
'@eslint-community/regexpp': 4.12.2
|
||||
'@eslint/config-array': 0.21.1
|
||||
'@eslint/config-helpers': 0.4.2
|
||||
@@ -2848,7 +2851,7 @@ snapshots:
|
||||
eslint-scope: 8.4.0
|
||||
eslint-visitor-keys: 4.2.1
|
||||
espree: 10.4.0
|
||||
esquery: 1.6.0
|
||||
esquery: 1.7.0
|
||||
esutils: 2.0.3
|
||||
fast-deep-equal: 3.1.3
|
||||
file-entry-cache: 8.0.0
|
||||
@@ -2875,7 +2878,7 @@ snapshots:
|
||||
acorn-jsx: 5.3.2(acorn@8.15.0)
|
||||
eslint-visitor-keys: 4.2.1
|
||||
|
||||
esquery@1.6.0:
|
||||
esquery@1.7.0:
|
||||
dependencies:
|
||||
estraverse: 5.3.0
|
||||
|
||||
@@ -3601,7 +3604,7 @@ snapshots:
|
||||
|
||||
totalist@3.0.1: {}
|
||||
|
||||
ts-api-utils@2.1.0(typescript@5.9.3):
|
||||
ts-api-utils@2.4.0(typescript@5.9.3):
|
||||
dependencies:
|
||||
typescript: 5.9.3
|
||||
|
||||
@@ -3615,12 +3618,12 @@ snapshots:
|
||||
dependencies:
|
||||
prelude-ls: 1.2.1
|
||||
|
||||
typescript-eslint@8.50.1(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3):
|
||||
typescript-eslint@8.51.0(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3):
|
||||
dependencies:
|
||||
'@typescript-eslint/eslint-plugin': 8.50.1(@typescript-eslint/parser@8.50.1(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3))(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
'@typescript-eslint/parser': 8.50.1(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
'@typescript-eslint/typescript-estree': 8.50.1(typescript@5.9.3)
|
||||
'@typescript-eslint/utils': 8.50.1(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
'@typescript-eslint/eslint-plugin': 8.51.0(@typescript-eslint/parser@8.51.0(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3))(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
'@typescript-eslint/parser': 8.51.0(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
'@typescript-eslint/typescript-estree': 8.51.0(typescript@5.9.3)
|
||||
'@typescript-eslint/utils': 8.51.0(eslint@9.39.2(jiti@1.21.7))(typescript@5.9.3)
|
||||
eslint: 9.39.2(jiti@1.21.7)
|
||||
typescript: 5.9.3
|
||||
transitivePeerDependencies:
|
||||
@@ -3704,4 +3707,4 @@ snapshots:
|
||||
|
||||
zimmerframe@1.1.4: {}
|
||||
|
||||
zod@4.2.1: {}
|
||||
zod@4.3.5: {}
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
count: number;
|
||||
item: Snippet<[index: number]>;
|
||||
itemHeight: (index: number) => number;
|
||||
itemGap?: number;
|
||||
placeholder?: Snippet;
|
||||
}
|
||||
|
||||
let { class: className, count, item, itemHeight, placeholder }: Props = $props();
|
||||
let { class: className, count, item, itemHeight, itemGap, placeholder }: Props = $props();
|
||||
|
||||
let element: HTMLElement | undefined = $state();
|
||||
let scrollMargin = $state(0);
|
||||
@@ -20,6 +21,7 @@
|
||||
createWindowVirtualizer({
|
||||
count,
|
||||
estimateSize: itemHeight,
|
||||
gap: itemGap,
|
||||
scrollMargin,
|
||||
}),
|
||||
);
|
||||
@@ -32,7 +34,7 @@
|
||||
if (!element) return;
|
||||
|
||||
const observer = new ResizeObserver(() => {
|
||||
scrollMargin = element!.getBoundingClientRect().top + window.scrollY;
|
||||
scrollMargin = Math.round(element!.getBoundingClientRect().top + window.scrollY);
|
||||
});
|
||||
observer.observe(element.parentElement!);
|
||||
return () => observer.disconnect();
|
||||
@@ -52,7 +54,7 @@
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{#if placeholder && $virtualizer.getVirtualItems().length === 0}
|
||||
{#if placeholder && count === 0}
|
||||
{@render placeholder()}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { browser } from "$app/environment";
|
||||
import { getFileThumbnail } from "$lib/modules/file";
|
||||
import type { SummarizedFileInfo } from "$lib/modules/filesystem";
|
||||
import { requestFileThumbnailDownload } from "$lib/services/file";
|
||||
|
||||
interface Props {
|
||||
info: SummarizedFileInfo;
|
||||
@@ -10,25 +9,16 @@
|
||||
|
||||
let { info, onclick }: Props = $props();
|
||||
|
||||
let showThumbnail = $derived(
|
||||
browser && (info.contentType.startsWith("image/") || info.contentType.startsWith("video/")),
|
||||
);
|
||||
let thumbnailPromise = $derived(
|
||||
showThumbnail ? requestFileThumbnailDownload(info.id, info.dataKey?.key) : null,
|
||||
);
|
||||
let thumbnail = $derived(getFileThumbnail(info));
|
||||
</script>
|
||||
|
||||
<button
|
||||
onclick={onclick && (() => setTimeout(() => onclick(info), 100))}
|
||||
class="aspect-square overflow-hidden rounded transition active:scale-95 active:brightness-90"
|
||||
>
|
||||
{#await thumbnailPromise}
|
||||
<div class="h-full w-full bg-gray-100"></div>
|
||||
{:then thumbnail}
|
||||
{#if thumbnail}
|
||||
<img src={thumbnail} alt={info.name} class="h-full w-full object-cover" />
|
||||
{#if $thumbnail}
|
||||
<img src={$thumbnail} alt={info.name} class="h-full w-full object-cover" />
|
||||
{:else}
|
||||
<div class="h-full w-full bg-gray-100"></div>
|
||||
{/if}
|
||||
{/await}
|
||||
</button>
|
||||
|
||||
44
src/lib/components/molecules/Categories.svelte
Normal file
44
src/lib/components/molecules/Categories.svelte
Normal file
@@ -0,0 +1,44 @@
|
||||
<script module lang="ts">
|
||||
import type { DataKey } from "$lib/modules/filesystem";
|
||||
|
||||
export interface SelectedCategory {
|
||||
id: number;
|
||||
dataKey?: DataKey;
|
||||
name: string;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type { Component } from "svelte";
|
||||
import type { SvelteHTMLElements } from "svelte/elements";
|
||||
import { ActionEntryButton } from "$lib/components/atoms";
|
||||
import { CategoryLabel } from "$lib/components/molecules";
|
||||
import type { SubCategoryInfo } from "$lib/modules/filesystem";
|
||||
import { sortEntries } from "$lib/utils";
|
||||
|
||||
interface Props {
|
||||
categories: SubCategoryInfo[];
|
||||
categoryMenuIcon?: Component<SvelteHTMLElements["svg"]>;
|
||||
onCategoryClick: (category: SelectedCategory) => void;
|
||||
onCategoryMenuClick?: (category: SelectedCategory) => void;
|
||||
}
|
||||
|
||||
let { categories, categoryMenuIcon, onCategoryClick, onCategoryMenuClick }: Props = $props();
|
||||
|
||||
let categoriesWithName = $derived(sortEntries([...categories]));
|
||||
</script>
|
||||
|
||||
{#if categoriesWithName.length > 0}
|
||||
<div class="space-y-1">
|
||||
{#each categoriesWithName as category (category.id)}
|
||||
<ActionEntryButton
|
||||
class="h-12"
|
||||
onclick={() => onCategoryClick(category)}
|
||||
actionButtonIcon={categoryMenuIcon}
|
||||
onActionButtonClick={() => onCategoryMenuClick?.(category)}
|
||||
>
|
||||
<CategoryLabel name={category.name} />
|
||||
</ActionEntryButton>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -1,33 +0,0 @@
|
||||
<script lang="ts">
|
||||
import type { Component } from "svelte";
|
||||
import type { SvelteHTMLElements } from "svelte/elements";
|
||||
import type { SubCategoryInfo } from "$lib/modules/filesystem";
|
||||
import { SortBy, sortEntries } from "$lib/utils";
|
||||
import Category from "./Category.svelte";
|
||||
import type { SelectedCategory } from "./service";
|
||||
|
||||
interface Props {
|
||||
categories: SubCategoryInfo[];
|
||||
categoryMenuIcon?: Component<SvelteHTMLElements["svg"]>;
|
||||
onCategoryClick: (category: SelectedCategory) => void;
|
||||
onCategoryMenuClick?: (category: SelectedCategory) => void;
|
||||
sortBy?: SortBy;
|
||||
}
|
||||
|
||||
let { categories, categoryMenuIcon, onCategoryClick, onCategoryMenuClick }: Props = $props();
|
||||
|
||||
let categoriesWithName = $derived(sortEntries(structuredClone($state.snapshot(categories))));
|
||||
</script>
|
||||
|
||||
{#if categoriesWithName.length > 0}
|
||||
<div class="space-y-1">
|
||||
{#each categoriesWithName as category}
|
||||
<Category
|
||||
info={category}
|
||||
menuIcon={categoryMenuIcon}
|
||||
onclick={onCategoryClick}
|
||||
onMenuClick={onCategoryMenuClick}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -1,26 +0,0 @@
|
||||
<script lang="ts">
|
||||
import type { Component } from "svelte";
|
||||
import type { SvelteHTMLElements } from "svelte/elements";
|
||||
import { ActionEntryButton } from "$lib/components/atoms";
|
||||
import { CategoryLabel } from "$lib/components/molecules";
|
||||
import type { SubCategoryInfo } from "$lib/modules/filesystem";
|
||||
import type { SelectedCategory } from "./service";
|
||||
|
||||
interface Props {
|
||||
info: SubCategoryInfo;
|
||||
menuIcon?: Component<SvelteHTMLElements["svg"]>;
|
||||
onclick: (category: SelectedCategory) => void;
|
||||
onMenuClick?: (category: SelectedCategory) => void;
|
||||
}
|
||||
|
||||
let { info, menuIcon, onclick, onMenuClick }: Props = $props();
|
||||
</script>
|
||||
|
||||
<ActionEntryButton
|
||||
class="h-12"
|
||||
onclick={() => onclick(info)}
|
||||
actionButtonIcon={menuIcon}
|
||||
onActionButtonClick={() => onMenuClick?.(info)}
|
||||
>
|
||||
<CategoryLabel name={info.name} />
|
||||
</ActionEntryButton>
|
||||
@@ -1,2 +0,0 @@
|
||||
export { default } from "./Categories.svelte";
|
||||
export * from "./service";
|
||||
@@ -1,7 +0,0 @@
|
||||
import type { DataKey } from "$lib/modules/filesystem";
|
||||
|
||||
export interface SelectedCategory {
|
||||
id: number;
|
||||
dataKey?: DataKey;
|
||||
name: string;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
export * from "./ActionModal.svelte";
|
||||
export { default as ActionModal } from "./ActionModal.svelte";
|
||||
export * from "./Categories";
|
||||
export { default as Categories } from "./Categories";
|
||||
export * from "./Categories.svelte";
|
||||
export { default as Categories } from "./Categories.svelte";
|
||||
export { default as IconEntryButton } from "./IconEntryButton.svelte";
|
||||
export * from "./labels";
|
||||
export { default as SubCategories } from "./SubCategories.svelte";
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { CheckBox, RowVirtualizer } from "$lib/components/atoms";
|
||||
import { SubCategories, type SelectedCategory } from "$lib/components/molecules";
|
||||
import type { CategoryInfo } from "$lib/modules/filesystem";
|
||||
import { sortEntries } from "$lib/utils";
|
||||
import File from "./File.svelte";
|
||||
import type { SelectedFile } from "./service";
|
||||
|
||||
import IconMoreVert from "~icons/material-symbols/more-vert";
|
||||
|
||||
interface Props {
|
||||
info: CategoryInfo;
|
||||
isFileRecursive: boolean | undefined;
|
||||
onFileClick: (file: SelectedFile) => void;
|
||||
onFileRemoveClick: (file: SelectedFile) => void;
|
||||
onSubCategoryClick: (subCategory: SelectedCategory) => void;
|
||||
onSubCategoryCreateClick: () => void;
|
||||
onSubCategoryMenuClick: (subCategory: SelectedCategory) => void;
|
||||
}
|
||||
|
||||
let {
|
||||
info,
|
||||
onFileClick,
|
||||
onFileRemoveClick,
|
||||
onSubCategoryClick,
|
||||
onSubCategoryCreateClick,
|
||||
onSubCategoryMenuClick,
|
||||
isFileRecursive = $bindable(),
|
||||
}: Props = $props();
|
||||
|
||||
let files = $derived(
|
||||
sortEntries(
|
||||
info.files
|
||||
?.map((file) => ({ name: file.name, details: file }))
|
||||
.filter(({ details }) => isFileRecursive || !details.isRecursive) ?? [],
|
||||
),
|
||||
);
|
||||
</script>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div class="space-y-4 bg-white p-4">
|
||||
{#if info.id !== "root"}
|
||||
<p class="text-lg font-bold text-gray-800">하위 카테고리</p>
|
||||
{/if}
|
||||
<SubCategories
|
||||
{info}
|
||||
{onSubCategoryClick}
|
||||
{onSubCategoryCreateClick}
|
||||
{onSubCategoryMenuClick}
|
||||
subCategoryMenuIcon={IconMoreVert}
|
||||
/>
|
||||
</div>
|
||||
{#if info.id !== "root"}
|
||||
<div class="space-y-4 bg-white p-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<p class="text-lg font-bold text-gray-800">파일</p>
|
||||
<CheckBox bind:checked={isFileRecursive}>
|
||||
<p class="font-medium">하위 카테고리의 파일</p>
|
||||
</CheckBox>
|
||||
</div>
|
||||
<RowVirtualizer
|
||||
count={files.length}
|
||||
itemHeight={(index) => 48 + (index + 1 < files.length ? 4 : 0)}
|
||||
>
|
||||
{#snippet item(index)}
|
||||
{@const { details } = files[index]!}
|
||||
<div class={[index + 1 < files.length && "pb-1"]}>
|
||||
<File
|
||||
info={details}
|
||||
onclick={onFileClick}
|
||||
onRemoveClick={!details.isRecursive ? onFileRemoveClick : undefined}
|
||||
/>
|
||||
</div>
|
||||
{/snippet}
|
||||
{#snippet placeholder()}
|
||||
<p class="text-center text-gray-500">이 카테고리에 추가된 파일이 없어요.</p>
|
||||
{/snippet}
|
||||
</RowVirtualizer>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -1,2 +0,0 @@
|
||||
export { default } from "./Category.svelte";
|
||||
export * from "./service";
|
||||
@@ -1,4 +0,0 @@
|
||||
export interface SelectedFile {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { FileThumbnailButton, RowVirtualizer } from "$lib/components/atoms";
|
||||
import type { SummarizedFileInfo } from "$lib/modules/filesystem";
|
||||
import { formatDate, formatDateSortable, SortBy, sortEntries } from "$lib/utils";
|
||||
|
||||
interface Props {
|
||||
files: SummarizedFileInfo[];
|
||||
onFileClick?: (file: SummarizedFileInfo) => void;
|
||||
}
|
||||
|
||||
let { files, onFileClick }: Props = $props();
|
||||
|
||||
type Row =
|
||||
| { type: "header"; label: string }
|
||||
| { type: "items"; files: SummarizedFileInfo[]; isLast: boolean };
|
||||
|
||||
let rows = $derived.by(() => {
|
||||
const groups = Map.groupBy(
|
||||
files.filter(
|
||||
(file) => file.contentType.startsWith("image/") || file.contentType.startsWith("video/"),
|
||||
),
|
||||
(file) => formatDateSortable(file.createdAt ?? file.lastModifiedAt),
|
||||
);
|
||||
return Array.from(groups.entries())
|
||||
.sort(([dateA], [dateB]) => dateB.localeCompare(dateA))
|
||||
.flatMap(([_, entries]) => {
|
||||
const sortedEntries = [...entries];
|
||||
sortEntries(sortedEntries, SortBy.DATE_DESC);
|
||||
|
||||
return [
|
||||
{
|
||||
type: "header",
|
||||
label: formatDate(sortedEntries[0]!.createdAt ?? sortedEntries[0]!.lastModifiedAt),
|
||||
},
|
||||
...Array.from({ length: Math.ceil(sortedEntries.length / 4) }, (_, i) => {
|
||||
const start = i * 4;
|
||||
const end = start + 4;
|
||||
return {
|
||||
type: "items" as const,
|
||||
files: sortedEntries.slice(start, end),
|
||||
isLast: end >= sortedEntries.length,
|
||||
};
|
||||
}),
|
||||
] satisfies Row[];
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<RowVirtualizer
|
||||
count={rows.length}
|
||||
itemHeight={(index) =>
|
||||
rows[index]!.type === "header"
|
||||
? 28
|
||||
: Math.ceil(rows[index]!.files.length / 4) * 181 +
|
||||
(Math.ceil(rows[index]!.files.length / 4) - 1) * 4 +
|
||||
16}
|
||||
class="flex flex-grow flex-col"
|
||||
>
|
||||
{#snippet item(index)}
|
||||
{@const row = rows[index]!}
|
||||
{#if row.type === "header"}
|
||||
<p class="pb-2 text-sm font-medium">{row.label}</p>
|
||||
{:else}
|
||||
<div class={["grid grid-cols-4 gap-x-1", row.isLast ? "pb-4" : "pb-1"]}>
|
||||
{#each row.files as file}
|
||||
<FileThumbnailButton info={file} onclick={onFileClick} />
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
{#snippet placeholder()}
|
||||
<div class="flex h-full flex-grow items-center justify-center">
|
||||
<p class="text-gray-500">
|
||||
{#if files.length === 0}
|
||||
업로드된 파일이 없어요.
|
||||
{:else}
|
||||
사진 또는 동영상이 없어요.
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
{/snippet}
|
||||
</RowVirtualizer>
|
||||
@@ -1,4 +1 @@
|
||||
export * from "./Category";
|
||||
export { default as Category } from "./Category";
|
||||
export { default as Gallery } from "./Gallery.svelte";
|
||||
export * from "./modals";
|
||||
|
||||
@@ -13,15 +13,15 @@ interface FileInfo {
|
||||
contentType: string;
|
||||
createdAt?: Date;
|
||||
lastModifiedAt: Date;
|
||||
categoryIds: number[];
|
||||
categoryIds?: number[];
|
||||
}
|
||||
|
||||
interface CategoryInfo {
|
||||
id: number;
|
||||
parentId: CategoryId;
|
||||
name: string;
|
||||
files: { id: number; isRecursive: boolean }[];
|
||||
isFileRecursive: boolean;
|
||||
files?: { id: number; isRecursive: boolean }[];
|
||||
isFileRecursive?: boolean;
|
||||
}
|
||||
|
||||
const filesystem = new Dexie("filesystem") as Dexie & {
|
||||
@@ -55,13 +55,23 @@ export const getDirectoryInfo = async (id: number) => {
|
||||
};
|
||||
|
||||
export const storeDirectoryInfo = async (directoryInfo: DirectoryInfo) => {
|
||||
await filesystem.directory.put(directoryInfo);
|
||||
await filesystem.directory.upsert(directoryInfo.id, { ...directoryInfo });
|
||||
};
|
||||
|
||||
export const deleteDirectoryInfo = async (id: number) => {
|
||||
await filesystem.directory.delete(id);
|
||||
};
|
||||
|
||||
export const deleteDanglingDirectoryInfos = async (
|
||||
parentId: DirectoryId,
|
||||
validIds: Set<number>,
|
||||
) => {
|
||||
await filesystem.directory
|
||||
.where({ parentId })
|
||||
.and((directory) => !validIds.has(directory.id))
|
||||
.delete();
|
||||
};
|
||||
|
||||
export const getAllFileInfos = async () => {
|
||||
return await filesystem.file.toArray();
|
||||
};
|
||||
@@ -74,14 +84,29 @@ export const getFileInfo = async (id: number) => {
|
||||
return await filesystem.file.get(id);
|
||||
};
|
||||
|
||||
export const bulkGetFileInfos = async (ids: number[]) => {
|
||||
return await filesystem.file.bulkGet(ids);
|
||||
};
|
||||
|
||||
export const storeFileInfo = async (fileInfo: FileInfo) => {
|
||||
await filesystem.file.put(fileInfo);
|
||||
await filesystem.file.upsert(fileInfo.id, { ...fileInfo });
|
||||
};
|
||||
|
||||
export const deleteFileInfo = async (id: number) => {
|
||||
await filesystem.file.delete(id);
|
||||
};
|
||||
|
||||
export const bulkDeleteFileInfos = async (ids: number[]) => {
|
||||
await filesystem.file.bulkDelete(ids);
|
||||
};
|
||||
|
||||
export const deleteDanglingFileInfos = async (parentId: DirectoryId, validIds: Set<number>) => {
|
||||
await filesystem.file
|
||||
.where({ parentId })
|
||||
.and((file) => !validIds.has(file.id))
|
||||
.delete();
|
||||
};
|
||||
|
||||
export const getCategoryInfos = async (parentId: CategoryId) => {
|
||||
return await filesystem.category.where({ parentId }).toArray();
|
||||
};
|
||||
@@ -91,7 +116,7 @@ export const getCategoryInfo = async (id: number) => {
|
||||
};
|
||||
|
||||
export const storeCategoryInfo = async (categoryInfo: CategoryInfo) => {
|
||||
await filesystem.category.put(categoryInfo);
|
||||
await filesystem.category.upsert(categoryInfo.id, { ...categoryInfo });
|
||||
};
|
||||
|
||||
export const updateCategoryInfo = async (id: number, changes: { isFileRecursive?: boolean }) => {
|
||||
@@ -102,6 +127,13 @@ export const deleteCategoryInfo = async (id: number) => {
|
||||
await filesystem.category.delete(id);
|
||||
};
|
||||
|
||||
export const deleteDanglingCategoryInfos = async (parentId: CategoryId, validIds: Set<number>) => {
|
||||
await filesystem.category
|
||||
.where({ parentId })
|
||||
.and((category) => !validIds.has(category.id))
|
||||
.delete();
|
||||
};
|
||||
|
||||
export const cleanupDanglingInfos = async () => {
|
||||
const validDirectoryIds: number[] = [];
|
||||
const validFileIds: number[] = [];
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import { LRUCache } from "lru-cache";
|
||||
import {
|
||||
getFileCacheIndex as getFileCacheIndexFromIndexedDB,
|
||||
storeFileCacheIndex,
|
||||
deleteFileCacheIndex,
|
||||
type FileCacheIndex,
|
||||
} from "$lib/indexedDB";
|
||||
import { readFile, writeFile, deleteFile, deleteDirectory } from "$lib/modules/opfs";
|
||||
import { getThumbnailUrl } from "$lib/modules/thumbnail";
|
||||
import { readFile, writeFile, deleteFile } from "$lib/modules/opfs";
|
||||
|
||||
const fileCacheIndex = new Map<number, FileCacheIndex>();
|
||||
const loadedThumbnails = new LRUCache<number, string>({ max: 100 });
|
||||
|
||||
export const prepareFileCache = async () => {
|
||||
for (const cache of await getFileCacheIndexFromIndexedDB()) {
|
||||
@@ -51,30 +48,3 @@ export const deleteFileCache = async (fileId: number) => {
|
||||
await deleteFile(`/cache/${fileId}`);
|
||||
await deleteFileCacheIndex(fileId);
|
||||
};
|
||||
|
||||
export const getFileThumbnailCache = async (fileId: number) => {
|
||||
const thumbnail = loadedThumbnails.get(fileId);
|
||||
if (thumbnail) return thumbnail;
|
||||
|
||||
const thumbnailBuffer = await readFile(`/thumbnail/file/${fileId}`);
|
||||
if (!thumbnailBuffer) return null;
|
||||
|
||||
const thumbnailUrl = getThumbnailUrl(thumbnailBuffer);
|
||||
loadedThumbnails.set(fileId, thumbnailUrl);
|
||||
return thumbnailUrl;
|
||||
};
|
||||
|
||||
export const storeFileThumbnailCache = async (fileId: number, thumbnailBuffer: ArrayBuffer) => {
|
||||
await writeFile(`/thumbnail/file/${fileId}`, thumbnailBuffer);
|
||||
loadedThumbnails.set(fileId, getThumbnailUrl(thumbnailBuffer));
|
||||
};
|
||||
|
||||
export const deleteFileThumbnailCache = async (fileId: number) => {
|
||||
loadedThumbnails.delete(fileId);
|
||||
await deleteFile(`/thumbnail/file/${fileId}`);
|
||||
};
|
||||
|
||||
export const deleteAllFileThumbnailCaches = async () => {
|
||||
loadedThumbnails.clear();
|
||||
await deleteDirectory("/thumbnail/file");
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from "./cache";
|
||||
export * from "./download.svelte";
|
||||
export * from "./thumbnail";
|
||||
export * from "./upload.svelte";
|
||||
|
||||
90
src/lib/modules/file/thumbnail.ts
Normal file
90
src/lib/modules/file/thumbnail.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import { LRUCache } from "lru-cache";
|
||||
import { writable, type Writable } from "svelte/store";
|
||||
import { browser } from "$app/environment";
|
||||
import { decryptData } from "$lib/modules/crypto";
|
||||
import type { SummarizedFileInfo } from "$lib/modules/filesystem";
|
||||
import { readFile, writeFile, deleteFile, deleteDirectory } from "$lib/modules/opfs";
|
||||
import { getThumbnailUrl } from "$lib/modules/thumbnail";
|
||||
import { isTRPCClientError, trpc } from "$trpc/client";
|
||||
|
||||
const loadedThumbnails = new LRUCache<number, Writable<string>>({ max: 100 });
|
||||
const loadingThumbnails = new Map<number, Writable<string | undefined>>();
|
||||
|
||||
const fetchFromOpfs = async (fileId: number) => {
|
||||
const thumbnailBuffer = await readFile(`/thumbnail/file/${fileId}`);
|
||||
if (thumbnailBuffer) {
|
||||
return getThumbnailUrl(thumbnailBuffer);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchFromServer = async (fileId: number, dataKey: CryptoKey) => {
|
||||
try {
|
||||
const [thumbnailEncrypted, { contentIv: thumbnailEncryptedIv }] = await Promise.all([
|
||||
fetch(`/api/file/${fileId}/thumbnail/download`),
|
||||
trpc().file.thumbnail.query({ id: fileId }),
|
||||
]);
|
||||
const thumbnailBuffer = await decryptData(
|
||||
await thumbnailEncrypted.arrayBuffer(),
|
||||
thumbnailEncryptedIv,
|
||||
dataKey,
|
||||
);
|
||||
|
||||
void writeFile(`/thumbnail/file/${fileId}`, thumbnailBuffer);
|
||||
return getThumbnailUrl(thumbnailBuffer);
|
||||
} catch (e) {
|
||||
if (isTRPCClientError(e) && e.data?.code === "NOT_FOUND") {
|
||||
return null;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
export const getFileThumbnail = (file: SummarizedFileInfo) => {
|
||||
if (
|
||||
!browser ||
|
||||
!(file.contentType.startsWith("image/") || file.contentType.startsWith("video/"))
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const thumbnail = loadedThumbnails.get(file.id);
|
||||
if (thumbnail) return thumbnail;
|
||||
|
||||
let loadingThumbnail = loadingThumbnails.get(file.id);
|
||||
if (loadingThumbnail) return loadingThumbnail;
|
||||
|
||||
loadingThumbnail = writable(undefined);
|
||||
loadingThumbnails.set(file.id, loadingThumbnail);
|
||||
|
||||
fetchFromOpfs(file.id)
|
||||
.then((thumbnail) => thumbnail ?? (file.dataKey && fetchFromServer(file.id, file.dataKey.key)))
|
||||
.then((thumbnail) => {
|
||||
if (thumbnail) {
|
||||
loadingThumbnail.set(thumbnail);
|
||||
loadedThumbnails.set(file.id, loadingThumbnail as Writable<string>);
|
||||
}
|
||||
loadingThumbnails.delete(file.id);
|
||||
});
|
||||
return loadingThumbnail;
|
||||
};
|
||||
|
||||
export const storeFileThumbnailCache = async (fileId: number, thumbnailBuffer: ArrayBuffer) => {
|
||||
await writeFile(`/thumbnail/file/${fileId}`, thumbnailBuffer);
|
||||
|
||||
const oldThumbnail = loadedThumbnails.get(fileId);
|
||||
if (oldThumbnail) {
|
||||
oldThumbnail.set(getThumbnailUrl(thumbnailBuffer));
|
||||
} else {
|
||||
loadedThumbnails.set(fileId, writable(getThumbnailUrl(thumbnailBuffer)));
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteFileThumbnailCache = async (fileId: number) => {
|
||||
loadedThumbnails.delete(fileId);
|
||||
await deleteFile(`/thumbnail/file/${fileId}`);
|
||||
};
|
||||
|
||||
export const deleteAllFileThumbnailCaches = async () => {
|
||||
loadedThumbnails.clear();
|
||||
await deleteDirectory(`/thumbnail/file`);
|
||||
};
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
digestMessage,
|
||||
signMessageHmac,
|
||||
} from "$lib/modules/crypto";
|
||||
import { Scheduler } from "$lib/modules/scheduler";
|
||||
import { generateThumbnail } from "$lib/modules/thumbnail";
|
||||
import type {
|
||||
FileThumbnailUploadRequest,
|
||||
@@ -23,6 +24,7 @@ export interface FileUploadState {
|
||||
name: string;
|
||||
parentId: DirectoryId;
|
||||
status:
|
||||
| "queued"
|
||||
| "encryption-pending"
|
||||
| "encrypting"
|
||||
| "upload-pending"
|
||||
@@ -36,17 +38,20 @@ export interface FileUploadState {
|
||||
}
|
||||
|
||||
export type LiveFileUploadState = FileUploadState & {
|
||||
status: "encryption-pending" | "encrypting" | "upload-pending" | "uploading";
|
||||
status: "queued" | "encryption-pending" | "encrypting" | "upload-pending" | "uploading";
|
||||
};
|
||||
|
||||
const scheduler = new Scheduler<
|
||||
{ fileId: number; fileBuffer: ArrayBuffer; thumbnailBuffer?: ArrayBuffer } | undefined
|
||||
>();
|
||||
let uploadingFiles: FileUploadState[] = $state([]);
|
||||
|
||||
const isFileUploading = (status: FileUploadState["status"]) =>
|
||||
["encryption-pending", "encrypting", "upload-pending", "uploading"].includes(status);
|
||||
["queued", "encryption-pending", "encrypting", "upload-pending", "uploading"].includes(status);
|
||||
|
||||
export const getUploadingFiles = (parentId?: DirectoryId) => {
|
||||
return uploadingFiles.filter(
|
||||
(file): file is LiveFileUploadState =>
|
||||
(file) =>
|
||||
(parentId === undefined || file.parentId === parentId) && isFileUploading(file.status),
|
||||
);
|
||||
};
|
||||
@@ -183,16 +188,17 @@ export const uploadFile = async (
|
||||
hmacSecret: HmacSecret,
|
||||
masterKey: MasterKey,
|
||||
onDuplicate: () => Promise<boolean>,
|
||||
): Promise<
|
||||
{ fileId: number; fileBuffer: ArrayBuffer; thumbnailBuffer?: ArrayBuffer } | undefined
|
||||
> => {
|
||||
) => {
|
||||
uploadingFiles.push({
|
||||
name: file.name,
|
||||
parentId,
|
||||
status: "encryption-pending",
|
||||
status: "queued",
|
||||
});
|
||||
const state = uploadingFiles.at(-1)!;
|
||||
|
||||
return await scheduler.schedule(file.size, async () => {
|
||||
state.status = "encryption-pending";
|
||||
|
||||
try {
|
||||
const { fileBuffer, fileSigned } = await requestDuplicateFileScan(
|
||||
file,
|
||||
@@ -259,4 +265,5 @@ export const uploadFile = async (
|
||||
state.status = "error";
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import * as IndexedDB from "$lib/indexedDB";
|
||||
import { trpc, isTRPCClientError } from "$trpc/client";
|
||||
import { FilesystemCache, decryptFileMetadata, decryptCategoryMetadata } from "./internal.svelte";
|
||||
import type { CategoryInfo } from "./types";
|
||||
import type { CategoryInfo, MaybeCategoryInfo } from "./types";
|
||||
|
||||
const cache = new FilesystemCache<CategoryId, CategoryInfo, Partial<CategoryInfo>>();
|
||||
|
||||
const fetchFromIndexedDB = async (id: CategoryId) => {
|
||||
const cache = new FilesystemCache<CategoryId, MaybeCategoryInfo>({
|
||||
async fetchFromIndexedDB(id) {
|
||||
const [category, subCategories] = await Promise.all([
|
||||
id !== "root" ? IndexedDB.getCategoryInfo(id) : undefined,
|
||||
IndexedDB.getCategoryInfos(id),
|
||||
]);
|
||||
const files = category
|
||||
const files = category?.files
|
||||
? await Promise.all(
|
||||
category.files.map(async (file) => {
|
||||
const fileInfo = await IndexedDB.getFileInfo(file.id);
|
||||
return fileInfo
|
||||
? {
|
||||
id: file.id,
|
||||
parentId: fileInfo.parentId,
|
||||
contentType: fileInfo.contentType,
|
||||
name: fileInfo.name,
|
||||
createdAt: fileInfo.createdAt,
|
||||
@@ -29,76 +29,93 @@ const fetchFromIndexedDB = async (id: CategoryId) => {
|
||||
: undefined;
|
||||
|
||||
if (id === "root") {
|
||||
return { id, subCategories };
|
||||
return {
|
||||
id,
|
||||
exists: true,
|
||||
subCategories,
|
||||
};
|
||||
} else if (category) {
|
||||
return {
|
||||
id,
|
||||
exists: true,
|
||||
parentId: category.parentId,
|
||||
name: category.name,
|
||||
subCategories,
|
||||
files: files!.filter((file) => !!file),
|
||||
isFileRecursive: category.isFileRecursive,
|
||||
files: files?.filter((file) => !!file) ?? [],
|
||||
isFileRecursive: category.isFileRecursive ?? false,
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
const fetchFromServer = async (id: CategoryId, masterKey: CryptoKey) => {
|
||||
async fetchFromServer(id, cachedInfo, masterKey) {
|
||||
try {
|
||||
const {
|
||||
metadata,
|
||||
subCategories: subCategoriesRaw,
|
||||
files: filesRaw,
|
||||
} = await trpc().category.get.query({ id });
|
||||
const [subCategories, files] = await Promise.all([
|
||||
const category = await trpc().category.get.query({ id, recurse: true });
|
||||
const [subCategories, files, metadata] = await Promise.all([
|
||||
Promise.all(
|
||||
subCategoriesRaw.map(async (category) => ({
|
||||
category.subCategories.map(async (category) => ({
|
||||
id: category.id,
|
||||
parentId: id,
|
||||
...(await decryptCategoryMetadata(category, masterKey)),
|
||||
})),
|
||||
),
|
||||
filesRaw
|
||||
? Promise.all(
|
||||
filesRaw.map(async (file) => ({
|
||||
category.files &&
|
||||
Promise.all(
|
||||
category.files.map(async (file) => ({
|
||||
id: file.id,
|
||||
parentId: file.parent,
|
||||
contentType: file.contentType,
|
||||
isRecursive: file.isRecursive,
|
||||
...(await decryptFileMetadata(file, masterKey)),
|
||||
})),
|
||||
)
|
||||
: undefined,
|
||||
),
|
||||
category.metadata && decryptCategoryMetadata(category.metadata, masterKey),
|
||||
]);
|
||||
|
||||
if (id === "root") {
|
||||
return { id, subCategories };
|
||||
} else {
|
||||
return {
|
||||
return storeToIndexedDB(
|
||||
id !== "root"
|
||||
? {
|
||||
id,
|
||||
parentId: category.metadata!.parent,
|
||||
subCategories,
|
||||
files,
|
||||
...(await decryptCategoryMetadata(metadata!, masterKey)),
|
||||
};
|
||||
files: files!,
|
||||
isFileRecursive: cachedInfo?.isFileRecursive ?? false,
|
||||
...metadata!,
|
||||
}
|
||||
: { id, subCategories },
|
||||
);
|
||||
} catch (e) {
|
||||
if (isTRPCClientError(e) && e.data?.code === "NOT_FOUND") {
|
||||
cache.delete(id);
|
||||
await IndexedDB.deleteCategoryInfo(id as number);
|
||||
return;
|
||||
return { id, exists: false };
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
export const getCategoryInfo = async (id: CategoryId, masterKey: CryptoKey) => {
|
||||
return await cache.get(id, async (isInitial, resolve) => {
|
||||
if (isInitial) {
|
||||
const info = await fetchFromIndexedDB(id);
|
||||
if (info) {
|
||||
resolve(info);
|
||||
}
|
||||
}
|
||||
|
||||
const info = await fetchFromServer(id, masterKey);
|
||||
if (info) {
|
||||
resolve(info);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const storeToIndexedDB = (info: CategoryInfo) => {
|
||||
if (info.id !== "root") {
|
||||
void IndexedDB.storeCategoryInfo(info);
|
||||
|
||||
// TODO: Bulk Upsert
|
||||
new Map(info.files.map((file) => [file.id, file])).forEach((file) => {
|
||||
void IndexedDB.storeFileInfo(file);
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Bulk Upsert
|
||||
info.subCategories.forEach((category) => {
|
||||
void IndexedDB.storeCategoryInfo(category);
|
||||
});
|
||||
|
||||
void IndexedDB.deleteDanglingCategoryInfos(
|
||||
info.id,
|
||||
new Set(info.subCategories.map(({ id }) => id)),
|
||||
);
|
||||
|
||||
return { ...info, exists: true as const };
|
||||
};
|
||||
|
||||
export const getCategoryInfo = (id: CategoryId, masterKey: CryptoKey) => {
|
||||
return cache.get(id, masterKey);
|
||||
};
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import * as IndexedDB from "$lib/indexedDB";
|
||||
import { monotonicResolve } from "$lib/utils";
|
||||
import { trpc, isTRPCClientError } from "$trpc/client";
|
||||
import { FilesystemCache, decryptDirectoryMetadata, decryptFileMetadata } from "./internal.svelte";
|
||||
import type { DirectoryInfo } from "./types";
|
||||
import type { DirectoryInfo, MaybeDirectoryInfo } from "./types";
|
||||
|
||||
const cache = new FilesystemCache<DirectoryId, DirectoryInfo>();
|
||||
|
||||
const fetchFromIndexedDB = async (id: DirectoryId) => {
|
||||
const cache = new FilesystemCache<DirectoryId, MaybeDirectoryInfo>({
|
||||
async fetchFromIndexedDB(id) {
|
||||
const [directory, subDirectories, files] = await Promise.all([
|
||||
id !== "root" ? IndexedDB.getDirectoryInfo(id) : undefined,
|
||||
IndexedDB.getDirectoryInfos(id),
|
||||
@@ -14,61 +12,91 @@ const fetchFromIndexedDB = async (id: DirectoryId) => {
|
||||
]);
|
||||
|
||||
if (id === "root") {
|
||||
return { id, subDirectories, files };
|
||||
} else if (directory) {
|
||||
return { id, parentId: directory.parentId, name: directory.name, subDirectories, files };
|
||||
}
|
||||
return {
|
||||
id,
|
||||
exists: true,
|
||||
subDirectories,
|
||||
files,
|
||||
};
|
||||
} else if (directory) {
|
||||
return {
|
||||
id,
|
||||
exists: true,
|
||||
parentId: directory.parentId,
|
||||
name: directory.name,
|
||||
subDirectories,
|
||||
files,
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
const fetchFromServer = async (id: DirectoryId, masterKey: CryptoKey) => {
|
||||
async fetchFromServer(id, _cachedInfo, masterKey) {
|
||||
try {
|
||||
const {
|
||||
metadata,
|
||||
subDirectories: subDirectoriesRaw,
|
||||
files: filesRaw,
|
||||
} = await trpc().directory.get.query({ id });
|
||||
const [subDirectories, files] = await Promise.all([
|
||||
const directory = await trpc().directory.get.query({ id });
|
||||
const [subDirectories, files, metadata] = await Promise.all([
|
||||
Promise.all(
|
||||
subDirectoriesRaw.map(async (directory) => ({
|
||||
directory.subDirectories.map(async (directory) => ({
|
||||
id: directory.id,
|
||||
parentId: id,
|
||||
...(await decryptDirectoryMetadata(directory, masterKey)),
|
||||
})),
|
||||
),
|
||||
Promise.all(
|
||||
filesRaw.map(async (file) => ({
|
||||
directory.files.map(async (file) => ({
|
||||
id: file.id,
|
||||
parentId: id,
|
||||
contentType: file.contentType,
|
||||
...(await decryptFileMetadata(file, masterKey)),
|
||||
})),
|
||||
),
|
||||
directory.metadata && decryptDirectoryMetadata(directory.metadata, masterKey),
|
||||
]);
|
||||
|
||||
if (id === "root") {
|
||||
return { id, subDirectories, files };
|
||||
} else {
|
||||
return {
|
||||
return storeToIndexedDB(
|
||||
id !== "root"
|
||||
? {
|
||||
id,
|
||||
parentId: metadata!.parent,
|
||||
parentId: directory.metadata!.parent,
|
||||
subDirectories,
|
||||
files,
|
||||
...(await decryptDirectoryMetadata(metadata!, masterKey)),
|
||||
};
|
||||
...metadata!,
|
||||
}
|
||||
: { id, subDirectories, files },
|
||||
);
|
||||
} catch (e) {
|
||||
if (isTRPCClientError(e) && e.data?.code === "NOT_FOUND") {
|
||||
cache.delete(id);
|
||||
await IndexedDB.deleteDirectoryInfo(id as number);
|
||||
return;
|
||||
return { id, exists: false as const };
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const storeToIndexedDB = (info: DirectoryInfo) => {
|
||||
if (info.id !== "root") {
|
||||
void IndexedDB.storeDirectoryInfo(info);
|
||||
}
|
||||
|
||||
// TODO: Bulk Upsert
|
||||
info.subDirectories.forEach((subDirectory) => {
|
||||
void IndexedDB.storeDirectoryInfo(subDirectory);
|
||||
});
|
||||
|
||||
// TODO: Bulk Upsert
|
||||
info.files.forEach((file) => {
|
||||
void IndexedDB.storeFileInfo(file);
|
||||
});
|
||||
|
||||
void IndexedDB.deleteDanglingDirectoryInfos(
|
||||
info.id,
|
||||
new Set(info.subDirectories.map(({ id }) => id)),
|
||||
);
|
||||
void IndexedDB.deleteDanglingFileInfos(info.id, new Set(info.files.map(({ id }) => id)));
|
||||
|
||||
return { ...info, exists: true as const };
|
||||
};
|
||||
|
||||
export const getDirectoryInfo = async (id: DirectoryId, masterKey: CryptoKey) => {
|
||||
return await cache.get(id, (isInitial, resolve) =>
|
||||
monotonicResolve(
|
||||
[isInitial && fetchFromIndexedDB(id), fetchFromServer(id, masterKey)],
|
||||
resolve,
|
||||
),
|
||||
);
|
||||
export const getDirectoryInfo = (id: DirectoryId, masterKey: CryptoKey) => {
|
||||
return cache.get(id, masterKey);
|
||||
};
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import * as IndexedDB from "$lib/indexedDB";
|
||||
import { monotonicResolve } from "$lib/utils";
|
||||
import { trpc, isTRPCClientError } from "$trpc/client";
|
||||
import { FilesystemCache, decryptFileMetadata, decryptCategoryMetadata } from "./internal.svelte";
|
||||
import type { FileInfo } from "./types";
|
||||
import type { FileInfo, MaybeFileInfo } from "./types";
|
||||
|
||||
const cache = new FilesystemCache<number, FileInfo>();
|
||||
|
||||
const fetchFromIndexedDB = async (id: number) => {
|
||||
const cache = new FilesystemCache<number, MaybeFileInfo>({
|
||||
async fetchFromIndexedDB(id) {
|
||||
const file = await IndexedDB.getFileInfo(id);
|
||||
const categories = file
|
||||
const categories = file?.categoryIds
|
||||
? await Promise.all(
|
||||
file.categoryIds.map(async (categoryId) => {
|
||||
const category = await IndexedDB.getCategoryInfo(categoryId);
|
||||
return category ? { id: category.id, name: category.name } : undefined;
|
||||
return category
|
||||
? { id: category.id, parentId: category.parentId, name: category.name }
|
||||
: undefined;
|
||||
}),
|
||||
)
|
||||
: undefined;
|
||||
@@ -20,51 +20,158 @@ const fetchFromIndexedDB = async (id: number) => {
|
||||
if (file) {
|
||||
return {
|
||||
id,
|
||||
exists: true,
|
||||
parentId: file.parentId,
|
||||
contentType: file.contentType,
|
||||
name: file.name,
|
||||
createdAt: file.createdAt,
|
||||
lastModifiedAt: file.lastModifiedAt,
|
||||
categories: categories!.filter((category) => !!category),
|
||||
categories: categories?.filter((category) => !!category) ?? [],
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
const fetchFromServer = async (id: number, masterKey: CryptoKey) => {
|
||||
async fetchFromServer(id, _cachedInfo, masterKey) {
|
||||
try {
|
||||
const { categories: categoriesRaw, ...metadata } = await trpc().file.get.query({ id });
|
||||
const [categories] = await Promise.all([
|
||||
const file = await trpc().file.get.query({ id });
|
||||
const [categories, metadata] = await Promise.all([
|
||||
Promise.all(
|
||||
categoriesRaw.map(async (category) => ({
|
||||
file.categories.map(async (category) => ({
|
||||
id: category.id,
|
||||
parentId: category.parent,
|
||||
...(await decryptCategoryMetadata(category, masterKey)),
|
||||
})),
|
||||
),
|
||||
decryptFileMetadata(file, masterKey),
|
||||
]);
|
||||
|
||||
return storeToIndexedDB({
|
||||
id,
|
||||
parentId: file.parent,
|
||||
dataKey: metadata.dataKey,
|
||||
contentType: file.contentType,
|
||||
contentIv: file.contentIv,
|
||||
name: metadata.name,
|
||||
createdAt: metadata.createdAt,
|
||||
lastModifiedAt: metadata.lastModifiedAt,
|
||||
categories,
|
||||
});
|
||||
} catch (e) {
|
||||
if (isTRPCClientError(e) && e.data?.code === "NOT_FOUND") {
|
||||
await IndexedDB.deleteFileInfo(id);
|
||||
return { id, exists: false as const };
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
},
|
||||
|
||||
async bulkFetchFromIndexedDB(ids) {
|
||||
const files = await IndexedDB.bulkGetFileInfos([...ids]);
|
||||
const categories = await Promise.all(
|
||||
files.map(async (file) =>
|
||||
file?.categoryIds
|
||||
? await Promise.all(
|
||||
file.categoryIds.map(async (categoryId) => {
|
||||
const category = await IndexedDB.getCategoryInfo(categoryId);
|
||||
return category
|
||||
? { id: category.id, parentId: category.parentId, name: category.name }
|
||||
: undefined;
|
||||
}),
|
||||
)
|
||||
: undefined,
|
||||
),
|
||||
);
|
||||
|
||||
return new Map(
|
||||
files
|
||||
.filter((file) => !!file)
|
||||
.map((file, index) => [
|
||||
file.id,
|
||||
{
|
||||
...file,
|
||||
exists: true,
|
||||
categories: categories[index]?.filter((category) => !!category) ?? [],
|
||||
},
|
||||
]),
|
||||
);
|
||||
},
|
||||
|
||||
async bulkFetchFromServer(ids, masterKey) {
|
||||
const idsArray = [...ids.keys()];
|
||||
|
||||
const filesRaw = await trpc().file.bulkGet.query({ ids: idsArray });
|
||||
const files = await Promise.all(
|
||||
filesRaw.map(async ({ id, categories: categoriesRaw, ...metadataRaw }) => {
|
||||
const [categories, metadata] = await Promise.all([
|
||||
Promise.all(
|
||||
categoriesRaw.map(async (category) => ({
|
||||
id: category.id,
|
||||
parentId: category.parent,
|
||||
...(await decryptCategoryMetadata(category, masterKey)),
|
||||
})),
|
||||
),
|
||||
decryptFileMetadata(metadataRaw, masterKey),
|
||||
]);
|
||||
|
||||
return {
|
||||
id,
|
||||
parentId: metadata.parent,
|
||||
contentType: metadata.contentType,
|
||||
contentIv: metadata.contentIv,
|
||||
exists: true as const,
|
||||
parentId: metadataRaw.parent,
|
||||
contentType: metadataRaw.contentType,
|
||||
contentIv: metadataRaw.contentIv,
|
||||
categories,
|
||||
...(await decryptFileMetadata(metadata, masterKey)),
|
||||
...metadata,
|
||||
};
|
||||
} catch (e) {
|
||||
if (isTRPCClientError(e) && e.data?.code === "NOT_FOUND") {
|
||||
cache.delete(id);
|
||||
await IndexedDB.deleteFileInfo(id);
|
||||
return;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
const existingIds = new Set(filesRaw.map(({ id }) => id));
|
||||
const deletedIds = idsArray.filter((id) => !existingIds.has(id));
|
||||
|
||||
void IndexedDB.bulkDeleteFileInfos(deletedIds);
|
||||
return new Map<number, MaybeFileInfo>([
|
||||
...bulkStoreToIndexedDB(files),
|
||||
...deletedIds.map((id) => [id, { id, exists: false }] as const),
|
||||
]);
|
||||
},
|
||||
});
|
||||
|
||||
const storeToIndexedDB = (info: FileInfo) => {
|
||||
void IndexedDB.storeFileInfo({
|
||||
...info,
|
||||
categoryIds: info.categories.map(({ id }) => id),
|
||||
});
|
||||
|
||||
info.categories.forEach((category) => {
|
||||
void IndexedDB.storeCategoryInfo(category);
|
||||
});
|
||||
|
||||
return { ...info, exists: true as const };
|
||||
};
|
||||
|
||||
export const getFileInfo = async (id: number, masterKey: CryptoKey) => {
|
||||
return await cache.get(id, (isInitial, resolve) =>
|
||||
monotonicResolve(
|
||||
[isInitial && fetchFromIndexedDB(id), fetchFromServer(id, masterKey)],
|
||||
resolve,
|
||||
),
|
||||
);
|
||||
const bulkStoreToIndexedDB = (infos: FileInfo[]) => {
|
||||
// TODO: Bulk Upsert
|
||||
infos.forEach((info) => {
|
||||
void IndexedDB.storeFileInfo({
|
||||
...info,
|
||||
categoryIds: info.categories.map(({ id }) => id),
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: Bulk Upsert
|
||||
new Map(
|
||||
infos.flatMap(({ categories }) => categories).map((category) => [category.id, category]),
|
||||
).forEach((category) => {
|
||||
void IndexedDB.storeCategoryInfo(category);
|
||||
});
|
||||
|
||||
return infos.map((info) => [info.id, { ...info, exists: true }] as const);
|
||||
};
|
||||
|
||||
export const getFileInfo = (id: number, masterKey: CryptoKey) => {
|
||||
return cache.get(id, masterKey);
|
||||
};
|
||||
|
||||
export const bulkGetFileInfo = (ids: number[], masterKey: CryptoKey) => {
|
||||
return cache.bulkGet(new Set(ids), masterKey);
|
||||
};
|
||||
|
||||
@@ -1,38 +1,124 @@
|
||||
import { untrack } from "svelte";
|
||||
import { unwrapDataKey, decryptString } from "$lib/modules/crypto";
|
||||
|
||||
export class FilesystemCache<K, V extends RV, RV = V> {
|
||||
private map = new Map<K, V | Promise<V>>();
|
||||
|
||||
get(key: K, loader: (isInitial: boolean, resolve: (value: RV | undefined) => void) => void) {
|
||||
const info = this.map.get(key);
|
||||
if (info instanceof Promise) {
|
||||
return info;
|
||||
interface FilesystemCacheOptions<K, V> {
|
||||
fetchFromIndexedDB: (key: K) => Promise<V | undefined>;
|
||||
fetchFromServer: (key: K, cachedValue: V | undefined, masterKey: CryptoKey) => Promise<V>;
|
||||
bulkFetchFromIndexedDB?: (keys: Set<K>) => Promise<Map<K, V>>;
|
||||
bulkFetchFromServer?: (
|
||||
keys: Map<K, { cachedValue: V | undefined }>,
|
||||
masterKey: CryptoKey,
|
||||
) => Promise<Map<K, V>>;
|
||||
}
|
||||
|
||||
const { promise, resolve } = Promise.withResolvers<V>();
|
||||
if (!info) {
|
||||
this.map.set(key, promise);
|
||||
export class FilesystemCache<K, V extends object> {
|
||||
private map = new Map<K, { value?: V; promise?: Promise<V> }>();
|
||||
|
||||
constructor(private readonly options: FilesystemCacheOptions<K, V>) {}
|
||||
|
||||
get(key: K, masterKey: CryptoKey) {
|
||||
return untrack(() => {
|
||||
let state = this.map.get(key);
|
||||
if (state?.promise) return state.value ?? state.promise;
|
||||
|
||||
const { promise: newPromise, resolve } = Promise.withResolvers<V>();
|
||||
|
||||
if (!state) {
|
||||
const newState = $state({});
|
||||
state = newState;
|
||||
this.map.set(key, newState);
|
||||
}
|
||||
|
||||
loader(!info, (loadedInfo) => {
|
||||
if (!loadedInfo) return;
|
||||
|
||||
let info = this.map.get(key)!;
|
||||
if (info instanceof Promise) {
|
||||
const state = $state(loadedInfo);
|
||||
this.map.set(key, state as V);
|
||||
resolve(state as V);
|
||||
(state.value
|
||||
? Promise.resolve(state.value)
|
||||
: this.options.fetchFromIndexedDB(key).then((loadedInfo) => {
|
||||
if (loadedInfo) {
|
||||
state.value = loadedInfo;
|
||||
resolve(state.value);
|
||||
}
|
||||
return loadedInfo;
|
||||
})
|
||||
)
|
||||
.then((cachedInfo) => this.options.fetchFromServer(key, cachedInfo, masterKey))
|
||||
.then((loadedInfo) => {
|
||||
if (state.value) {
|
||||
Object.assign(state.value, loadedInfo);
|
||||
} else {
|
||||
Object.assign(info, loadedInfo);
|
||||
resolve(info);
|
||||
state.value = loadedInfo;
|
||||
}
|
||||
resolve(state.value);
|
||||
})
|
||||
.finally(() => {
|
||||
state.promise = undefined;
|
||||
});
|
||||
|
||||
state.promise = newPromise;
|
||||
return state.value ?? newPromise;
|
||||
});
|
||||
}
|
||||
|
||||
bulkGet(keys: Set<K>, masterKey: CryptoKey) {
|
||||
return untrack(() => {
|
||||
const newPromises = new Map(
|
||||
keys
|
||||
.keys()
|
||||
.filter((key) => this.map.get(key)?.promise === undefined)
|
||||
.map((key) => [key, Promise.withResolvers<V>()]),
|
||||
);
|
||||
newPromises.forEach(({ promise }, key) => {
|
||||
const state = this.map.get(key);
|
||||
if (state) {
|
||||
state.promise = promise;
|
||||
} else {
|
||||
const newState = $state({ promise });
|
||||
this.map.set(key, newState);
|
||||
}
|
||||
});
|
||||
|
||||
return info ?? promise;
|
||||
const resolve = (loadedInfos: Map<K, V>) => {
|
||||
loadedInfos.forEach((loadedInfo, key) => {
|
||||
const state = this.map.get(key)!;
|
||||
if (state.value) {
|
||||
Object.assign(state.value, loadedInfo);
|
||||
} else {
|
||||
state.value = loadedInfo;
|
||||
}
|
||||
newPromises.get(key)!.resolve(state.value);
|
||||
});
|
||||
return loadedInfos;
|
||||
};
|
||||
|
||||
delete(key: K) {
|
||||
this.map.delete(key);
|
||||
this.options.bulkFetchFromIndexedDB!(
|
||||
new Set(newPromises.keys().filter((key) => this.map.get(key)!.value === undefined)),
|
||||
)
|
||||
.then(resolve)
|
||||
.then(() =>
|
||||
this.options.bulkFetchFromServer!(
|
||||
new Map(
|
||||
newPromises.keys().map((key) => [key, { cachedValue: this.map.get(key)!.value }]),
|
||||
),
|
||||
masterKey,
|
||||
),
|
||||
)
|
||||
.then(resolve)
|
||||
.finally(() => {
|
||||
newPromises.forEach((_, key) => {
|
||||
this.map.get(key)!.promise = undefined;
|
||||
});
|
||||
});
|
||||
|
||||
const bottleneckPromises = Array.from(
|
||||
keys
|
||||
.keys()
|
||||
.filter((key) => this.map.get(key)!.value === undefined)
|
||||
.map((key) => this.map.get(key)!.promise!),
|
||||
);
|
||||
const makeResult = () =>
|
||||
new Map(keys.keys().map((key) => [key, this.map.get(key)!.value!] as const));
|
||||
return bottleneckPromises.length > 0
|
||||
? Promise.all(bottleneckPromises).then(makeResult)
|
||||
: makeResult();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export type DataKey = { key: CryptoKey; version: Date };
|
||||
type AllUndefined<T> = { [K in keyof T]?: undefined };
|
||||
|
||||
interface LocalDirectoryInfo {
|
||||
id: number;
|
||||
@@ -19,7 +20,11 @@ interface RootDirectoryInfo {
|
||||
}
|
||||
|
||||
export type DirectoryInfo = LocalDirectoryInfo | RootDirectoryInfo;
|
||||
export type SubDirectoryInfo = Omit<LocalDirectoryInfo, "parentId" | "subDirectories" | "files">;
|
||||
export type MaybeDirectoryInfo =
|
||||
| (DirectoryInfo & { exists: true })
|
||||
| ({ id: DirectoryId; exists: false } & AllUndefined<Omit<DirectoryInfo, "id">>);
|
||||
|
||||
export type SubDirectoryInfo = Omit<LocalDirectoryInfo, "subDirectories" | "files">;
|
||||
|
||||
export interface FileInfo {
|
||||
id: number;
|
||||
@@ -30,14 +35,19 @@ export interface FileInfo {
|
||||
name: string;
|
||||
createdAt?: Date;
|
||||
lastModifiedAt: Date;
|
||||
categories: { id: number; name: string }[];
|
||||
categories: FileCategoryInfo[];
|
||||
}
|
||||
|
||||
export type SummarizedFileInfo = Omit<FileInfo, "parentId" | "contentIv" | "categories">;
|
||||
export type MaybeFileInfo =
|
||||
| (FileInfo & { exists: true })
|
||||
| ({ id: number; exists: false } & AllUndefined<Omit<FileInfo, "id">>);
|
||||
|
||||
export type SummarizedFileInfo = Omit<FileInfo, "contentIv" | "categories">;
|
||||
export type CategoryFileInfo = SummarizedFileInfo & { isRecursive: boolean };
|
||||
|
||||
interface LocalCategoryInfo {
|
||||
id: number;
|
||||
parentId: DirectoryId;
|
||||
dataKey?: DataKey;
|
||||
name: string;
|
||||
subCategories: SubCategoryInfo[];
|
||||
@@ -47,6 +57,7 @@ interface LocalCategoryInfo {
|
||||
|
||||
interface RootCategoryInfo {
|
||||
id: "root";
|
||||
parentId?: undefined;
|
||||
dataKey?: undefined;
|
||||
name?: undefined;
|
||||
subCategories: SubCategoryInfo[];
|
||||
@@ -55,7 +66,12 @@ interface RootCategoryInfo {
|
||||
}
|
||||
|
||||
export type CategoryInfo = LocalCategoryInfo | RootCategoryInfo;
|
||||
export type MaybeCategoryInfo =
|
||||
| (CategoryInfo & { exists: true })
|
||||
| ({ id: CategoryId; exists: false } & AllUndefined<Omit<CategoryInfo, "id">>);
|
||||
|
||||
export type SubCategoryInfo = Omit<
|
||||
LocalCategoryInfo,
|
||||
"subCategories" | "files" | "isFileRecursive"
|
||||
>;
|
||||
export type FileCategoryInfo = Omit<SubCategoryInfo, "dataKey">;
|
||||
|
||||
48
src/lib/modules/scheduler.ts
Normal file
48
src/lib/modules/scheduler.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
export class Scheduler<T = void> {
|
||||
private isEstimating = false;
|
||||
private memoryUsage = 0;
|
||||
private queue: (() => void)[] = [];
|
||||
|
||||
constructor(public readonly memoryLimit = 100 * 1024 * 1024 /* 100 MiB */) {}
|
||||
|
||||
private next() {
|
||||
if (!this.isEstimating && this.memoryUsage < this.memoryLimit) {
|
||||
const resolve = this.queue.shift();
|
||||
if (resolve) {
|
||||
this.isEstimating = true;
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async schedule(
|
||||
estimateMemoryUsage: number | (() => number | Promise<number>),
|
||||
task: () => Promise<T>,
|
||||
) {
|
||||
if (this.isEstimating || this.memoryUsage >= this.memoryLimit) {
|
||||
await new Promise<void>((resolve) => {
|
||||
this.queue.push(resolve);
|
||||
});
|
||||
} else {
|
||||
this.isEstimating = true;
|
||||
}
|
||||
|
||||
let taskMemoryUsage = 0;
|
||||
|
||||
try {
|
||||
taskMemoryUsage =
|
||||
typeof estimateMemoryUsage === "number" ? estimateMemoryUsage : await estimateMemoryUsage();
|
||||
this.memoryUsage += taskMemoryUsage;
|
||||
} finally {
|
||||
this.isEstimating = false;
|
||||
this.next();
|
||||
}
|
||||
|
||||
try {
|
||||
return await task();
|
||||
} finally {
|
||||
this.memoryUsage -= taskMemoryUsage;
|
||||
this.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { sql } from "kysely";
|
||||
import { jsonArrayFrom } from "kysely/helpers/postgres";
|
||||
import pg from "pg";
|
||||
import { IntegrityError } from "./error";
|
||||
import db from "./kysely";
|
||||
@@ -36,6 +37,15 @@ interface File {
|
||||
|
||||
export type NewFile = Omit<File, "id">;
|
||||
|
||||
interface FileCategory {
|
||||
id: number;
|
||||
parentId: CategoryId;
|
||||
mekVersion: number;
|
||||
encDek: string;
|
||||
dekVersion: Date;
|
||||
encName: Ciphertext;
|
||||
}
|
||||
|
||||
export const registerDirectory = async (params: NewDirectory) => {
|
||||
await db.transaction().execute(async (trx) => {
|
||||
const mek = await trx
|
||||
@@ -400,6 +410,52 @@ export const getFile = async (userId: number, fileId: number) => {
|
||||
: null;
|
||||
};
|
||||
|
||||
export const getFilesWithCategories = async (userId: number, fileIds: number[]) => {
|
||||
const files = await db
|
||||
.selectFrom("file")
|
||||
.selectAll()
|
||||
.select((eb) =>
|
||||
jsonArrayFrom(
|
||||
eb
|
||||
.selectFrom("file_category")
|
||||
.innerJoin("category", "file_category.category_id", "category.id")
|
||||
.where("file_category.file_id", "=", eb.ref("file.id"))
|
||||
.selectAll("category"),
|
||||
).as("categories"),
|
||||
)
|
||||
.where("id", "=", (eb) => eb.fn.any(eb.val(fileIds)))
|
||||
.where("user_id", "=", userId)
|
||||
.execute();
|
||||
return files.map(
|
||||
(file) =>
|
||||
({
|
||||
id: file.id,
|
||||
parentId: file.parent_id ?? "root",
|
||||
userId: file.user_id,
|
||||
path: file.path,
|
||||
mekVersion: file.master_encryption_key_version,
|
||||
encDek: file.encrypted_data_encryption_key,
|
||||
dekVersion: file.data_encryption_key_version,
|
||||
hskVersion: file.hmac_secret_key_version,
|
||||
contentHmac: file.content_hmac,
|
||||
contentType: file.content_type,
|
||||
encContentIv: file.encrypted_content_iv,
|
||||
encContentHash: file.encrypted_content_hash,
|
||||
encName: file.encrypted_name,
|
||||
encCreatedAt: file.encrypted_created_at,
|
||||
encLastModifiedAt: file.encrypted_last_modified_at,
|
||||
categories: file.categories.map((category) => ({
|
||||
id: category.id,
|
||||
parentId: category.parent_id ?? "root",
|
||||
mekVersion: category.master_encryption_key_version,
|
||||
encDek: category.encrypted_data_encryption_key,
|
||||
dekVersion: new Date(category.data_encryption_key_version),
|
||||
encName: category.encrypted_name,
|
||||
})),
|
||||
}) satisfies File & { categories: FileCategory[] },
|
||||
);
|
||||
};
|
||||
|
||||
export const setFileEncName = async (
|
||||
userId: number,
|
||||
fileId: number,
|
||||
@@ -490,13 +546,17 @@ export const getAllFileCategories = async (fileId: number) => {
|
||||
.selectAll("category")
|
||||
.where("file_id", "=", fileId)
|
||||
.execute();
|
||||
return categories.map((category) => ({
|
||||
return categories.map(
|
||||
(category) =>
|
||||
({
|
||||
id: category.id,
|
||||
parentId: category.parent_id ?? "root",
|
||||
mekVersion: category.master_encryption_key_version,
|
||||
encDek: category.encrypted_data_encryption_key,
|
||||
dekVersion: category.data_encryption_key_version,
|
||||
encName: category.encrypted_name,
|
||||
}));
|
||||
}) satisfies FileCategory,
|
||||
);
|
||||
};
|
||||
|
||||
export const removeFileFromCategory = async (fileId: number, categoryId: number) => {
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
import { getAllFileInfos } from "$lib/indexedDB/filesystem";
|
||||
import { decryptData } from "$lib/modules/crypto";
|
||||
import {
|
||||
getFileCache,
|
||||
storeFileCache,
|
||||
deleteFileCache,
|
||||
getFileThumbnailCache,
|
||||
storeFileThumbnailCache,
|
||||
deleteFileThumbnailCache,
|
||||
downloadFile,
|
||||
deleteFileThumbnailCache,
|
||||
} from "$lib/modules/file";
|
||||
import { getThumbnailUrl } from "$lib/modules/thumbnail";
|
||||
import type { FileThumbnailUploadRequest } from "$lib/server/schemas";
|
||||
import { trpc } from "$trpc/client";
|
||||
|
||||
@@ -44,29 +40,6 @@ export const requestFileThumbnailUpload = async (
|
||||
return await fetch(`/api/file/${fileId}/thumbnail/upload`, { method: "POST", body: form });
|
||||
};
|
||||
|
||||
export const requestFileThumbnailDownload = async (fileId: number, dataKey?: CryptoKey) => {
|
||||
const cache = await getFileThumbnailCache(fileId);
|
||||
if (cache || !dataKey) return cache;
|
||||
|
||||
let thumbnailInfo;
|
||||
try {
|
||||
thumbnailInfo = await trpc().file.thumbnail.query({ id: fileId });
|
||||
} catch {
|
||||
// TODO: Error Handling
|
||||
return null;
|
||||
}
|
||||
const { contentIv: thumbnailEncryptedIv } = thumbnailInfo;
|
||||
|
||||
const res = await fetch(`/api/file/${fileId}/thumbnail/download`);
|
||||
if (!res.ok) return null;
|
||||
|
||||
const thumbnailEncrypted = await res.arrayBuffer();
|
||||
const thumbnailBuffer = await decryptData(thumbnailEncrypted, thumbnailEncryptedIv, dataKey);
|
||||
|
||||
storeFileThumbnailCache(fileId, thumbnailBuffer); // Intended
|
||||
return getThumbnailUrl(thumbnailBuffer);
|
||||
};
|
||||
|
||||
export const requestDeletedFilesCleanup = async () => {
|
||||
let liveFiles;
|
||||
try {
|
||||
|
||||
93
src/lib/utils/HybridPromise.ts
Normal file
93
src/lib/utils/HybridPromise.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
type MaybePromise<T> = T | Promise<T> | HybridPromise<T>;
|
||||
|
||||
type HybridPromiseState<T> =
|
||||
| { mode: "sync"; status: "fulfilled"; value: T }
|
||||
| { mode: "sync"; status: "rejected"; reason: unknown }
|
||||
| { mode: "async"; promise: Promise<T> };
|
||||
|
||||
export class HybridPromise<T> implements PromiseLike<T> {
|
||||
private isConsumed = false;
|
||||
|
||||
private constructor(private readonly state: HybridPromiseState<T>) {
|
||||
if (state.mode === "sync" && state.status === "rejected") {
|
||||
queueMicrotask(() => {
|
||||
if (!this.isConsumed) {
|
||||
throw state.reason;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isSync(): boolean {
|
||||
return this.state.mode === "sync";
|
||||
}
|
||||
|
||||
toPromise(): Promise<T> {
|
||||
this.isConsumed = true;
|
||||
|
||||
if (this.state.mode === "async") return this.state.promise;
|
||||
return this.state.status === "fulfilled"
|
||||
? Promise.resolve(this.state.value)
|
||||
: Promise.reject(this.state.reason);
|
||||
}
|
||||
|
||||
static resolve<T>(value: MaybePromise<T>): HybridPromise<T> {
|
||||
if (value instanceof HybridPromise) return value;
|
||||
return new HybridPromise(
|
||||
value instanceof Promise
|
||||
? { mode: "async", promise: value }
|
||||
: { mode: "sync", status: "fulfilled", value },
|
||||
);
|
||||
}
|
||||
|
||||
static reject<T = never>(reason?: unknown): HybridPromise<T> {
|
||||
return new HybridPromise({ mode: "sync", status: "rejected", reason });
|
||||
}
|
||||
|
||||
then<TResult1 = T, TResult2 = never>(
|
||||
onfulfilled?: ((value: T) => MaybePromise<TResult1>) | null | undefined,
|
||||
onrejected?: ((reason: unknown) => MaybePromise<TResult2>) | null | undefined,
|
||||
): HybridPromise<TResult1 | TResult2> {
|
||||
this.isConsumed = true;
|
||||
|
||||
if (this.state.mode === "async") {
|
||||
return new HybridPromise({
|
||||
mode: "async",
|
||||
promise: this.state.promise.then(onfulfilled, onrejected) as any,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.state.status === "fulfilled") {
|
||||
if (!onfulfilled) return HybridPromise.resolve(this.state.value as any);
|
||||
return HybridPromise.resolve(onfulfilled(this.state.value));
|
||||
} else {
|
||||
if (!onrejected) return HybridPromise.reject(this.state.reason);
|
||||
return HybridPromise.resolve(onrejected(this.state.reason));
|
||||
}
|
||||
} catch (e) {
|
||||
return HybridPromise.reject(e);
|
||||
}
|
||||
}
|
||||
|
||||
catch<TResult = never>(
|
||||
onrejected?: ((reason: unknown) => MaybePromise<TResult>) | null | undefined,
|
||||
): HybridPromise<T | TResult> {
|
||||
return this.then<T, TResult>(null, onrejected);
|
||||
}
|
||||
|
||||
finally(onfinally?: (() => void) | null | undefined): HybridPromise<T> {
|
||||
this.isConsumed = true;
|
||||
|
||||
if (this.state.mode === "async") {
|
||||
return new HybridPromise({ mode: "async", promise: this.state.promise.finally(onfinally) });
|
||||
}
|
||||
|
||||
try {
|
||||
onfinally?.();
|
||||
return new HybridPromise(this.state);
|
||||
} catch (e) {
|
||||
return HybridPromise.reject(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from "./format";
|
||||
export * from "./gotoStateful";
|
||||
export * from "./promise";
|
||||
export * from "./HybridPromise";
|
||||
export * from "./sort";
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
export const monotonicResolve = <T>(
|
||||
promises: (Promise<T> | false)[],
|
||||
callback: (value: T) => void,
|
||||
) => {
|
||||
let latestResolvedIndex = -1;
|
||||
promises
|
||||
.filter((promise) => !!promise)
|
||||
.forEach((promise, index) => {
|
||||
promise.then((value) => {
|
||||
if (index > latestResolvedIndex) {
|
||||
latestResolvedIndex = index;
|
||||
callback(value);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -48,10 +48,11 @@ export const sortEntries = <T extends SortEntry>(entries: T[], sortBy = SortBy.N
|
||||
case SortBy.DATE_DESC:
|
||||
sortFunc = sortByDateDesc;
|
||||
break;
|
||||
default:
|
||||
default: {
|
||||
const exhaustive: never = sortBy;
|
||||
sortFunc = exhaustive;
|
||||
}
|
||||
}
|
||||
|
||||
entries.sort(sortFunc);
|
||||
return entries;
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
import { page } from "$app/state";
|
||||
import { FullscreenDiv } from "$lib/components/atoms";
|
||||
import { Categories, IconEntryButton, TopBar } from "$lib/components/molecules";
|
||||
import { getFileInfo, type FileInfo } from "$lib/modules/filesystem";
|
||||
import { getFileInfo, type FileInfo, type MaybeFileInfo } from "$lib/modules/filesystem";
|
||||
import { captureVideoThumbnail } from "$lib/modules/thumbnail";
|
||||
import { getFileDownloadState } from "$lib/modules/file";
|
||||
import { masterKeyStore } from "$lib/stores";
|
||||
import { HybridPromise } from "$lib/utils";
|
||||
import AddToCategoryBottomSheet from "./AddToCategoryBottomSheet.svelte";
|
||||
import DownloadStatus from "./DownloadStatus.svelte";
|
||||
import {
|
||||
@@ -26,8 +27,7 @@
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
let infoPromise: Promise<FileInfo | null> | undefined = $state();
|
||||
let info: FileInfo | null = $state(null);
|
||||
let info: MaybeFileInfo | undefined = $state();
|
||||
let downloadState = $derived(getFileDownloadState(data.id));
|
||||
|
||||
let isMenuOpen = $state(false);
|
||||
@@ -65,20 +65,20 @@
|
||||
const addToCategory = async (categoryId: number) => {
|
||||
await requestFileAdditionToCategory(data.id, categoryId);
|
||||
isAddToCategoryBottomSheetOpen = false;
|
||||
infoPromise = getFileInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
void getFileInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
};
|
||||
|
||||
const removeFromCategory = async (categoryId: number) => {
|
||||
await requestFileRemovalFromCategory(data.id, categoryId);
|
||||
infoPromise = getFileInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
void getFileInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
};
|
||||
|
||||
$effect(() => {
|
||||
infoPromise = getFileInfo(data.id, $masterKeyStore?.get(1)?.key!).then((fileInfo) => {
|
||||
info = fileInfo;
|
||||
return fileInfo;
|
||||
HybridPromise.resolve(getFileInfo(data.id, $masterKeyStore?.get(1)?.key!)).then((result) => {
|
||||
if (data.id === result.id) {
|
||||
info = result;
|
||||
}
|
||||
});
|
||||
info = null;
|
||||
isDownloadRequested = false;
|
||||
viewerType = undefined;
|
||||
});
|
||||
@@ -109,8 +109,8 @@
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (info && downloadState?.status === "decrypted") {
|
||||
untrack(() => !isDownloadRequested && updateViewer(downloadState.result!, info!.contentType));
|
||||
if (info?.exists && downloadState?.status === "decrypted") {
|
||||
untrack(() => !isDownloadRequested && updateViewer(downloadState.result!, info!.contentIv!));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -121,8 +121,7 @@
|
||||
<title>파일</title>
|
||||
</svelte:head>
|
||||
|
||||
{#if info}
|
||||
<TopBar title={info.name}>
|
||||
<TopBar title={info?.name}>
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<div onclick={(e) => e.stopPropagation()}>
|
||||
@@ -135,10 +134,10 @@
|
||||
<TopBarMenu
|
||||
bind:isOpen={isMenuOpen}
|
||||
directoryId={["category", "gallery"].includes(page.url.searchParams.get("from") ?? "")
|
||||
? info.parentId
|
||||
? info?.parentId
|
||||
: undefined}
|
||||
{fileBlob}
|
||||
filename={info.name}
|
||||
filename={info?.name}
|
||||
/>
|
||||
</div>
|
||||
</TopBar>
|
||||
@@ -147,7 +146,7 @@
|
||||
{#if downloadState}
|
||||
<DownloadStatus state={downloadState} />
|
||||
{/if}
|
||||
{#if viewerType}
|
||||
{#if info && viewerType}
|
||||
<div class="flex w-full justify-center">
|
||||
{#snippet viewerLoading(message: string)}
|
||||
<p class="text-gray-500">{message}</p>
|
||||
@@ -162,7 +161,6 @@
|
||||
{:else if viewerType === "video"}
|
||||
{#if fileBlobUrl}
|
||||
<div class="flex flex-col space-y-2">
|
||||
<!-- svelte-ignore a11y_media_has_caption -->
|
||||
<video bind:this={videoElement} src={fileBlobUrl} controls muted></video>
|
||||
<IconEntryButton
|
||||
icon={IconCamera}
|
||||
@@ -182,7 +180,7 @@
|
||||
<p class="text-lg font-bold">카테고리</p>
|
||||
<div class="space-y-1">
|
||||
<Categories
|
||||
categories={info.categories}
|
||||
categories={info?.categories ?? []}
|
||||
categoryMenuIcon={IconClose}
|
||||
onCategoryClick={({ id }) => goto(`/category/${id}`)}
|
||||
onCategoryMenuClick={({ id }) => removeFromCategory(id)}
|
||||
@@ -205,4 +203,3 @@
|
||||
bind:isOpen={isAddToCategoryBottomSheetOpen}
|
||||
onAddToCategoryClick={addToCategory}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
import { BottomDiv, BottomSheet, Button, FullscreenDiv } from "$lib/components/atoms";
|
||||
import { SubCategories } from "$lib/components/molecules";
|
||||
import { CategoryCreateModal } from "$lib/components/organisms";
|
||||
import { getCategoryInfo, type CategoryInfo } from "$lib/modules/filesystem";
|
||||
import { getCategoryInfo, type MaybeCategoryInfo } from "$lib/modules/filesystem";
|
||||
import { masterKeyStore } from "$lib/stores";
|
||||
import { HybridPromise } from "$lib/utils";
|
||||
import { requestCategoryCreation } from "./service";
|
||||
|
||||
interface Props {
|
||||
@@ -13,48 +14,50 @@
|
||||
|
||||
let { onAddToCategoryClick, isOpen = $bindable() }: Props = $props();
|
||||
|
||||
let categoryInfoPromise: Promise<CategoryInfo | null> | undefined = $state();
|
||||
let categoryInfo: MaybeCategoryInfo | undefined = $state();
|
||||
|
||||
let isCategoryCreateModalOpen = $state(false);
|
||||
|
||||
$effect(() => {
|
||||
if (isOpen) {
|
||||
categoryInfoPromise = getCategoryInfo("root", $masterKeyStore?.get(1)?.key!);
|
||||
HybridPromise.resolve(getCategoryInfo("root", $masterKeyStore?.get(1)?.key!)).then(
|
||||
(result) => (categoryInfo = result),
|
||||
);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
{#await categoryInfoPromise then categoryInfo}
|
||||
{#if categoryInfo}
|
||||
{#if categoryInfo?.exists}
|
||||
<BottomSheet bind:isOpen class="flex flex-col">
|
||||
<FullscreenDiv>
|
||||
<SubCategories
|
||||
class="py-4"
|
||||
info={categoryInfo}
|
||||
onSubCategoryClick={({ id }) =>
|
||||
(categoryInfoPromise = getCategoryInfo(id, $masterKeyStore?.get(1)?.key!))}
|
||||
HybridPromise.resolve(getCategoryInfo(id, $masterKeyStore?.get(1)?.key!)).then(
|
||||
(result) => (categoryInfo = result),
|
||||
)}
|
||||
onSubCategoryCreateClick={() => (isCategoryCreateModalOpen = true)}
|
||||
subCategoryCreatePosition="top"
|
||||
/>
|
||||
{#if categoryInfo.id !== "root"}
|
||||
<BottomDiv>
|
||||
<Button onclick={() => onAddToCategoryClick(categoryInfo.id)} class="w-full">
|
||||
이 카테고리에 추가하기
|
||||
<Button onclick={() => onAddToCategoryClick(categoryInfo!.id as number)} class="w-full">
|
||||
{categoryInfo!.name} 카테고리에 추가하기
|
||||
</Button>
|
||||
</BottomDiv>
|
||||
{/if}
|
||||
</FullscreenDiv>
|
||||
</BottomSheet>
|
||||
{/if}
|
||||
|
||||
<CategoryCreateModal
|
||||
bind:isOpen={isCategoryCreateModalOpen}
|
||||
onCreateClick={async (name: string) => {
|
||||
if (await requestCategoryCreation(name, categoryInfo.id, $masterKeyStore?.get(1)!)) {
|
||||
categoryInfoPromise = getCategoryInfo(categoryInfo.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
if (await requestCategoryCreation(name, categoryInfo!.id, $masterKeyStore?.get(1)!)) {
|
||||
void getCategoryInfo(categoryInfo!.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
{/await}
|
||||
|
||||
@@ -1,15 +1,29 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { FullscreenDiv } from "$lib/components/atoms";
|
||||
import { TopBar } from "$lib/components/molecules";
|
||||
import { getDownloadingFiles, clearDownloadedFiles } from "$lib/modules/file";
|
||||
import { getFileInfo } from "$lib/modules/filesystem";
|
||||
import {
|
||||
getDownloadingFiles,
|
||||
clearDownloadedFiles,
|
||||
type FileDownloadState,
|
||||
} from "$lib/modules/file";
|
||||
import { bulkGetFileInfo, type MaybeFileInfo } from "$lib/modules/filesystem";
|
||||
import { masterKeyStore } from "$lib/stores";
|
||||
import File from "./File.svelte";
|
||||
|
||||
const downloadingFiles = getDownloadingFiles();
|
||||
const filesPromise = $derived(
|
||||
Promise.all(downloadingFiles.map(({ id }) => getFileInfo(id, $masterKeyStore?.get(1)?.key!))),
|
||||
let downloadingFiles: { info: MaybeFileInfo; state: FileDownloadState }[] = $state([]);
|
||||
|
||||
onMount(async () => {
|
||||
const states = getDownloadingFiles();
|
||||
const infos = await bulkGetFileInfo(
|
||||
states.map(({ id }) => id),
|
||||
$masterKeyStore?.get(1)?.key!,
|
||||
);
|
||||
downloadingFiles = states.map((state) => ({
|
||||
info: infos.get(state.id)!,
|
||||
state,
|
||||
}));
|
||||
});
|
||||
|
||||
$effect(() => clearDownloadedFiles);
|
||||
</script>
|
||||
@@ -20,11 +34,11 @@
|
||||
|
||||
<TopBar />
|
||||
<FullscreenDiv>
|
||||
{#await filesPromise then files}
|
||||
<div class="space-y-2 pb-4">
|
||||
{#each files as file, index}
|
||||
<File state={downloadingFiles[index]!} info={file} />
|
||||
{#each downloadingFiles as { info, state } (info.id)}
|
||||
{#if info.exists}
|
||||
<File {info} {state} />
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
{/await}
|
||||
</FullscreenDiv>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import type { FileDownloadState } from "$lib/modules/file";
|
||||
import type { FileInfo } from "$lib/modules/filesystem";
|
||||
import type { SummarizedFileInfo } from "$lib/modules/filesystem";
|
||||
import { formatNetworkSpeed } from "$lib/utils";
|
||||
|
||||
import IconCloud from "~icons/material-symbols/cloud";
|
||||
@@ -11,7 +11,7 @@
|
||||
import IconError from "~icons/material-symbols/error";
|
||||
|
||||
interface Props {
|
||||
info: FileInfo;
|
||||
info: SummarizedFileInfo;
|
||||
state: FileDownloadState;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
<div class="flex h-14 items-center gap-x-4 p-2">
|
||||
<div class="flex-shrink-0 text-lg text-gray-600">
|
||||
{#if state.status === "encryption-pending"}
|
||||
{#if state.status === "queued" || state.status === "encryption-pending"}
|
||||
<IconPending />
|
||||
{:else if state.status === "encrypting"}
|
||||
<IconLockClock />
|
||||
@@ -37,7 +37,9 @@
|
||||
{state.name}
|
||||
</p>
|
||||
<p class="text-xs text-gray-800">
|
||||
{#if state.status === "encryption-pending"}
|
||||
{#if state.status === "queued"}
|
||||
대기 중
|
||||
{:else if state.status === "encryption-pending"}
|
||||
준비 중
|
||||
{:else if state.status === "encrypting"}
|
||||
암호화하는 중
|
||||
|
||||
@@ -1,20 +1,57 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import { FullscreenDiv } from "$lib/components/atoms";
|
||||
import { FileThumbnailButton, FullscreenDiv, RowVirtualizer } from "$lib/components/atoms";
|
||||
import { TopBar } from "$lib/components/molecules";
|
||||
import { Gallery } from "$lib/components/organisms";
|
||||
import { getFileInfo, type FileInfo } from "$lib/modules/filesystem";
|
||||
import {
|
||||
bulkGetFileInfo,
|
||||
type MaybeFileInfo,
|
||||
type SummarizedFileInfo,
|
||||
} from "$lib/modules/filesystem";
|
||||
import { masterKeyStore } from "$lib/stores";
|
||||
import { formatDate, formatDateSortable, SortBy, sortEntries } from "$lib/utils";
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
let files: (FileInfo | null)[] = $state([]);
|
||||
type Row =
|
||||
| { type: "header"; label: string }
|
||||
| { type: "items"; files: SummarizedFileInfo[]; isLast: boolean };
|
||||
|
||||
let files: MaybeFileInfo[] = $state([]);
|
||||
let rows: Row[] = $derived.by(() => {
|
||||
const groups = Map.groupBy(
|
||||
files
|
||||
.filter((file) => file.exists)
|
||||
.filter(
|
||||
(file) => file.contentType.startsWith("image/") || file.contentType.startsWith("video/"),
|
||||
)
|
||||
.map((file) => ({ ...file, date: file.createdAt ?? file.lastModifiedAt })),
|
||||
(file) => formatDateSortable(file.date),
|
||||
);
|
||||
return Array.from(groups.entries())
|
||||
.sort(([dateA], [dateB]) => dateB.localeCompare(dateA))
|
||||
.flatMap(([, entries]) => {
|
||||
const sortedEntries = sortEntries([...entries], SortBy.DATE_DESC);
|
||||
return [
|
||||
{
|
||||
type: "header",
|
||||
label: formatDate(sortedEntries[0]!.date),
|
||||
},
|
||||
...Array.from({ length: Math.ceil(sortedEntries.length / 4) }, (_, i) => {
|
||||
const start = i * 4;
|
||||
const end = start + 4;
|
||||
return {
|
||||
type: "items" as const,
|
||||
files: sortedEntries.slice(start, end),
|
||||
isLast: end >= sortedEntries.length,
|
||||
};
|
||||
}),
|
||||
];
|
||||
});
|
||||
});
|
||||
|
||||
onMount(async () => {
|
||||
files = await Promise.all(
|
||||
data.files.map((file) => getFileInfo(file, $masterKeyStore?.get(1)?.key!)),
|
||||
);
|
||||
files = Array.from((await bulkGetFileInfo(data.files, $masterKeyStore?.get(1)?.key!)).values());
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -24,8 +61,37 @@
|
||||
|
||||
<TopBar title="사진 및 동영상" />
|
||||
<FullscreenDiv>
|
||||
<Gallery
|
||||
files={files.filter((file) => !!file)}
|
||||
onFileClick={({ id }) => goto(`/file/${id}?from=gallery`)}
|
||||
<RowVirtualizer
|
||||
count={rows.length}
|
||||
itemHeight={(index) =>
|
||||
rows[index]!.type === "header" ? 28 : 181 + (rows[index]!.isLast ? 16 : 4)}
|
||||
class="flex flex-grow flex-col"
|
||||
>
|
||||
{#snippet item(index)}
|
||||
{@const row = rows[index]!}
|
||||
{#if row.type === "header"}
|
||||
<p class="pb-2 text-sm font-medium">{row.label}</p>
|
||||
{:else}
|
||||
<div class={["grid grid-cols-4 gap-x-1", row.isLast ? "pb-4" : "pb-1"]}>
|
||||
{#each row.files as file (file.id)}
|
||||
<FileThumbnailButton
|
||||
info={file}
|
||||
onclick={() => goto(`/file/${file.id}?from=gallery`)}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
{#snippet placeholder()}
|
||||
<div class="flex h-full flex-grow items-center justify-center">
|
||||
<p class="text-gray-500">
|
||||
{#if files.length === 0}
|
||||
업로드된 파일이 없어요.
|
||||
{:else}
|
||||
사진 또는 동영상이 없어요.
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
{/snippet}
|
||||
</RowVirtualizer>
|
||||
</FullscreenDiv>
|
||||
|
||||
@@ -4,18 +4,20 @@
|
||||
import { TopBar } from "$lib/components/molecules";
|
||||
import type { FileCacheIndex } from "$lib/indexedDB";
|
||||
import { getFileCacheIndex, deleteFileCache as doDeleteFileCache } from "$lib/modules/file";
|
||||
import { getFileInfo, type FileInfo } from "$lib/modules/filesystem";
|
||||
import { bulkGetFileInfo, type MaybeFileInfo } from "$lib/modules/filesystem";
|
||||
import { masterKeyStore } from "$lib/stores";
|
||||
import { formatFileSize } from "$lib/utils";
|
||||
import File from "./File.svelte";
|
||||
|
||||
interface FileCache {
|
||||
index: FileCacheIndex;
|
||||
fileInfo: FileInfo | null;
|
||||
info: MaybeFileInfo;
|
||||
}
|
||||
|
||||
let fileCache: FileCache[] | undefined = $state();
|
||||
let fileCacheTotalSize = $state(0);
|
||||
let fileCacheTotalSize = $derived(
|
||||
fileCache?.reduce((acc, { index }) => acc + index.size, 0) ?? 0,
|
||||
);
|
||||
|
||||
const deleteFileCache = async (fileId: number) => {
|
||||
await doDeleteFileCache(fileId);
|
||||
@@ -23,19 +25,14 @@
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
fileCache = await Promise.all(
|
||||
getFileCacheIndex().map(async (index) => ({
|
||||
index,
|
||||
fileInfo: await getFileInfo(index.fileId, $masterKeyStore?.get(1)?.key!),
|
||||
})),
|
||||
const indexes = getFileCacheIndex();
|
||||
const infos = await bulkGetFileInfo(
|
||||
indexes.map(({ fileId }) => fileId),
|
||||
$masterKeyStore?.get(1)?.key!,
|
||||
);
|
||||
fileCache.sort((a, b) => a.index.lastRetrievedAt.getTime() - b.index.lastRetrievedAt.getTime());
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (fileCache) {
|
||||
fileCacheTotalSize = fileCache.reduce((acc, { index }) => acc + index.size, 0);
|
||||
}
|
||||
fileCache = indexes
|
||||
.map((index) => ({ index, info: infos.get(index.fileId)! }))
|
||||
.sort((a, b) => a.index.lastRetrievedAt.getTime() - b.index.lastRetrievedAt.getTime());
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -55,8 +52,8 @@
|
||||
<p>캐시를 삭제하더라도 원본 파일은 삭제되지 않아요.</p>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
{#each fileCache as { index, fileInfo }}
|
||||
<File {index} info={fileInfo} onDeleteClick={deleteFileCache} />
|
||||
{#each fileCache as { index, info } (info.id)}
|
||||
<File {index} {info} onDeleteClick={deleteFileCache} />
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import type { FileCacheIndex } from "$lib/indexedDB";
|
||||
import type { SummarizedFileInfo } from "$lib/modules/filesystem";
|
||||
import type { MaybeFileInfo } from "$lib/modules/filesystem";
|
||||
import { formatDate, formatFileSize } from "$lib/utils";
|
||||
|
||||
import IconDraft from "~icons/material-symbols/draft";
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
interface Props {
|
||||
index: FileCacheIndex;
|
||||
info: SummarizedFileInfo | null;
|
||||
info: MaybeFileInfo;
|
||||
onDeleteClick: (fileId: number) => void;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
</script>
|
||||
|
||||
<div class="flex h-14 items-center gap-x-4 p-2">
|
||||
{#if info}
|
||||
{#if info.exists}
|
||||
<div class="flex-shrink-0 rounded-full bg-blue-100 p-1 text-xl">
|
||||
<IconDraft class="text-blue-400" />
|
||||
</div>
|
||||
@@ -27,7 +27,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
<div class="flex-grow overflow-hidden">
|
||||
{#if info}
|
||||
{#if info.exists}
|
||||
<p title={info.name} class="truncate font-medium">{info.name}</p>
|
||||
{:else}
|
||||
<p class="font-medium">삭제된 파일</p>
|
||||
|
||||
@@ -1,40 +1,52 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { get } from "svelte/store";
|
||||
import { goto } from "$app/navigation";
|
||||
import { BottomDiv, Button, FullscreenDiv } from "$lib/components/atoms";
|
||||
import { IconEntryButton, TopBar } from "$lib/components/molecules";
|
||||
import { deleteAllFileThumbnailCaches } from "$lib/modules/file";
|
||||
import { getFileInfo } from "$lib/modules/filesystem";
|
||||
import { bulkGetFileInfo, type MaybeFileInfo } from "$lib/modules/filesystem";
|
||||
import { masterKeyStore } from "$lib/stores";
|
||||
import { sortEntries } from "$lib/utils";
|
||||
import File from "./File.svelte";
|
||||
import {
|
||||
persistentStates,
|
||||
getGenerationStatus,
|
||||
getThumbnailGenerationStatus,
|
||||
clearThumbnailGenerationStatuses,
|
||||
requestThumbnailGeneration,
|
||||
} from "./service.svelte";
|
||||
type GenerationStatus,
|
||||
} from "./service";
|
||||
|
||||
import IconDelete from "~icons/material-symbols/delete";
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
let fileInfos: MaybeFileInfo[] = $state([]);
|
||||
let files = $derived(
|
||||
fileInfos
|
||||
.map((info) => ({
|
||||
info,
|
||||
status: getThumbnailGenerationStatus(info.id),
|
||||
}))
|
||||
.filter(
|
||||
(file): file is { info: MaybeFileInfo; status: Exclude<GenerationStatus, "uploaded"> } =>
|
||||
file.status !== "uploaded",
|
||||
),
|
||||
);
|
||||
|
||||
const generateAllThumbnails = () => {
|
||||
persistentStates.files.forEach(({ info }) => {
|
||||
if (info) {
|
||||
files.forEach(({ info }) => {
|
||||
if (info.exists) {
|
||||
requestThumbnailGeneration(info);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
persistentStates.files = await Promise.all(
|
||||
data.files.map(async (fileId) => ({
|
||||
id: fileId,
|
||||
info: await getFileInfo(fileId, $masterKeyStore?.get(1)?.key!),
|
||||
status: getGenerationStatus(fileId),
|
||||
})),
|
||||
fileInfos = sortEntries(
|
||||
Array.from((await bulkGetFileInfo(data.files, $masterKeyStore?.get(1)?.key!)).values()),
|
||||
);
|
||||
});
|
||||
|
||||
$effect(() => clearThumbnailGenerationStatuses);
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -49,28 +61,30 @@
|
||||
저장된 썸네일 모두 삭제하기
|
||||
</IconEntryButton>
|
||||
</div>
|
||||
{#if persistentStates.files.length > 0}
|
||||
{#if files.length > 0}
|
||||
<div class="flex-grow space-y-2 bg-white p-4">
|
||||
<p class="text-lg font-bold text-gray-800">썸네일이 누락된 파일</p>
|
||||
<div class="space-y-4">
|
||||
<p class="break-keep text-gray-800">
|
||||
{persistentStates.files.length}개 파일의 썸네일이 존재하지 않아요.
|
||||
{files.length}개 파일의 썸네일이 존재하지 않아요.
|
||||
</p>
|
||||
<div class="space-y-2">
|
||||
{#each persistentStates.files as { info, status }}
|
||||
{#each files as { info, status } (info.id)}
|
||||
{#if info.exists}
|
||||
<File
|
||||
{info}
|
||||
generationStatus={status}
|
||||
{status}
|
||||
onclick={({ id }) => goto(`/file/${id}`)}
|
||||
onGenerateThumbnailClick={requestThumbnailGeneration}
|
||||
/>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#if persistentStates.files.length > 0}
|
||||
{#if files.length > 0}
|
||||
<BottomDiv class="px-4">
|
||||
<Button onclick={generateAllThumbnails} class="w-full">모두 썸네일 생성하기</Button>
|
||||
</BottomDiv>
|
||||
|
||||
@@ -10,12 +10,11 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type { Writable } from "svelte/store";
|
||||
import { ActionEntryButton } from "$lib/components/atoms";
|
||||
import { DirectoryEntryLabel } from "$lib/components/molecules";
|
||||
import type { FileInfo } from "$lib/modules/filesystem";
|
||||
import { formatDateTime } from "$lib/utils";
|
||||
import type { GenerationStatus } from "./service.svelte";
|
||||
import type { GenerationStatus } from "./service";
|
||||
|
||||
import IconCamera from "~icons/material-symbols/camera";
|
||||
|
||||
@@ -23,22 +22,21 @@
|
||||
info: FileInfo;
|
||||
onclick: (file: FileInfo) => void;
|
||||
onGenerateThumbnailClick: (file: FileInfo) => void;
|
||||
generationStatus?: Writable<GenerationStatus>;
|
||||
status: Exclude<GenerationStatus, "uploaded"> | undefined;
|
||||
}
|
||||
|
||||
let { info, onclick, onGenerateThumbnailClick, generationStatus }: Props = $props();
|
||||
let { info, onclick, onGenerateThumbnailClick, status }: Props = $props();
|
||||
</script>
|
||||
|
||||
<ActionEntryButton
|
||||
class="h-14"
|
||||
onclick={() => onclick(info)}
|
||||
actionButtonIcon={!$generationStatus || $generationStatus === "error" ? IconCamera : undefined}
|
||||
actionButtonIcon={!status || status === "error" ? IconCamera : undefined}
|
||||
onActionButtonClick={() => onGenerateThumbnailClick(info)}
|
||||
actionButtonClass="text-gray-800"
|
||||
>
|
||||
{@const subtext =
|
||||
$generationStatus && $generationStatus !== "uploaded"
|
||||
? subtexts[$generationStatus]
|
||||
{@const subtext = status
|
||||
? subtexts[status]
|
||||
: formatDateTime(info.createdAt ?? info.lastModifiedAt)}
|
||||
<DirectoryEntryLabel type="file" name={info.name} {subtext} />
|
||||
</ActionEntryButton>
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
import { limitFunction } from "p-limit";
|
||||
import { get, writable, type Writable } from "svelte/store";
|
||||
import { encryptData } from "$lib/modules/crypto";
|
||||
import { storeFileThumbnailCache } from "$lib/modules/file";
|
||||
import type { FileInfo } from "$lib/modules/filesystem";
|
||||
import { generateThumbnail as doGenerateThumbnail } from "$lib/modules/thumbnail";
|
||||
import { requestFileDownload, requestFileThumbnailUpload } from "$lib/services/file";
|
||||
|
||||
export type GenerationStatus =
|
||||
| "queued"
|
||||
| "generation-pending"
|
||||
| "generating"
|
||||
| "upload-pending"
|
||||
| "uploading"
|
||||
| "uploaded"
|
||||
| "error";
|
||||
|
||||
interface File {
|
||||
id: number;
|
||||
info: FileInfo;
|
||||
status?: Writable<GenerationStatus>;
|
||||
}
|
||||
|
||||
const workingFiles = new Map<number, Writable<GenerationStatus>>();
|
||||
|
||||
let queue: (() => void)[] = [];
|
||||
let memoryUsage = 0;
|
||||
const memoryLimit = 100 * 1024 * 1024; // 100 MiB
|
||||
|
||||
export const persistentStates = $state({
|
||||
files: [] as File[],
|
||||
});
|
||||
|
||||
export const getGenerationStatus = (fileId: number) => {
|
||||
return workingFiles.get(fileId);
|
||||
};
|
||||
|
||||
const generateThumbnail = limitFunction(
|
||||
async (
|
||||
status: Writable<GenerationStatus>,
|
||||
fileBuffer: ArrayBuffer,
|
||||
fileType: string,
|
||||
dataKey: CryptoKey,
|
||||
) => {
|
||||
status.set("generating");
|
||||
|
||||
const thumbnail = await doGenerateThumbnail(fileBuffer, fileType);
|
||||
if (!thumbnail) return null;
|
||||
|
||||
const thumbnailBuffer = await thumbnail.arrayBuffer();
|
||||
const thumbnailEncrypted = await encryptData(thumbnailBuffer, dataKey);
|
||||
status.set("upload-pending");
|
||||
return { plaintext: thumbnailBuffer, ...thumbnailEncrypted };
|
||||
},
|
||||
{ concurrency: 4 },
|
||||
);
|
||||
|
||||
const requestThumbnailUpload = limitFunction(
|
||||
async (
|
||||
status: Writable<GenerationStatus>,
|
||||
fileId: number,
|
||||
dataKeyVersion: Date,
|
||||
thumbnail: { plaintext: ArrayBuffer; ciphertext: ArrayBuffer; iv: string },
|
||||
) => {
|
||||
status.set("uploading");
|
||||
|
||||
const res = await requestFileThumbnailUpload(fileId, dataKeyVersion, thumbnail);
|
||||
if (!res.ok) return false;
|
||||
|
||||
status.set("uploaded");
|
||||
workingFiles.delete(fileId);
|
||||
persistentStates.files = persistentStates.files.filter(({ id }) => id != fileId);
|
||||
|
||||
storeFileThumbnailCache(fileId, thumbnail.plaintext); // Intended
|
||||
return true;
|
||||
},
|
||||
{ concurrency: 4 },
|
||||
);
|
||||
|
||||
const enqueue = async (
|
||||
status: Writable<GenerationStatus> | undefined,
|
||||
fileInfo: FileInfo,
|
||||
priority = false,
|
||||
) => {
|
||||
if (status) {
|
||||
status.set("queued");
|
||||
} else {
|
||||
status = writable("queued");
|
||||
workingFiles.set(fileInfo.id, status);
|
||||
persistentStates.files = persistentStates.files.map((file) =>
|
||||
file.id === fileInfo.id ? { ...file, status } : file,
|
||||
);
|
||||
}
|
||||
|
||||
let resolver;
|
||||
const promise = new Promise((resolve) => {
|
||||
resolver = resolve;
|
||||
});
|
||||
|
||||
if (priority) {
|
||||
queue = [resolver!, ...queue];
|
||||
} else {
|
||||
queue.push(resolver!);
|
||||
}
|
||||
|
||||
await promise;
|
||||
};
|
||||
|
||||
export const requestThumbnailGeneration = async (fileInfo: FileInfo) => {
|
||||
let status = workingFiles.get(fileInfo.id);
|
||||
if (status && get(status) !== "error") return;
|
||||
|
||||
if (workingFiles.values().some((status) => get(status) !== "error")) {
|
||||
await enqueue(status, fileInfo);
|
||||
}
|
||||
while (memoryUsage >= memoryLimit) {
|
||||
await enqueue(status, fileInfo, true);
|
||||
}
|
||||
|
||||
if (status) {
|
||||
status.set("generation-pending");
|
||||
} else {
|
||||
status = writable("generation-pending");
|
||||
workingFiles.set(fileInfo.id, status);
|
||||
persistentStates.files = persistentStates.files.map((file) =>
|
||||
file.id === fileInfo.id ? { ...file, status } : file,
|
||||
);
|
||||
}
|
||||
|
||||
let fileSize = 0;
|
||||
try {
|
||||
const file = await requestFileDownload(
|
||||
fileInfo.id,
|
||||
fileInfo.contentIv!,
|
||||
fileInfo.dataKey?.key!,
|
||||
);
|
||||
fileSize = file.byteLength;
|
||||
|
||||
memoryUsage += fileSize;
|
||||
if (memoryUsage < memoryLimit) {
|
||||
queue.shift()?.();
|
||||
}
|
||||
|
||||
const thumbnail = await generateThumbnail(
|
||||
status,
|
||||
file,
|
||||
fileInfo.contentType,
|
||||
fileInfo.dataKey?.key!,
|
||||
);
|
||||
if (
|
||||
!thumbnail ||
|
||||
!(await requestThumbnailUpload(status, fileInfo.id, fileInfo.dataKey?.version!, thumbnail))
|
||||
) {
|
||||
status.set("error");
|
||||
}
|
||||
} catch {
|
||||
status.set("error");
|
||||
} finally {
|
||||
memoryUsage -= fileSize;
|
||||
queue.shift()?.();
|
||||
}
|
||||
};
|
||||
102
src/routes/(fullscreen)/settings/thumbnail/service.ts
Normal file
102
src/routes/(fullscreen)/settings/thumbnail/service.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
import { limitFunction } from "p-limit";
|
||||
import { SvelteMap } from "svelte/reactivity";
|
||||
import { encryptData } from "$lib/modules/crypto";
|
||||
import { storeFileThumbnailCache } from "$lib/modules/file";
|
||||
import type { FileInfo } from "$lib/modules/filesystem";
|
||||
import { Scheduler } from "$lib/modules/scheduler";
|
||||
import { generateThumbnail as doGenerateThumbnail } from "$lib/modules/thumbnail";
|
||||
import { requestFileDownload, requestFileThumbnailUpload } from "$lib/services/file";
|
||||
|
||||
export type GenerationStatus =
|
||||
| "queued"
|
||||
| "generation-pending"
|
||||
| "generating"
|
||||
| "upload-pending"
|
||||
| "uploading"
|
||||
| "uploaded"
|
||||
| "error";
|
||||
|
||||
const scheduler = new Scheduler();
|
||||
const statuses = new SvelteMap<number, GenerationStatus>();
|
||||
|
||||
export const getThumbnailGenerationStatus = (fileId: number) => {
|
||||
return statuses.get(fileId);
|
||||
};
|
||||
|
||||
export const clearThumbnailGenerationStatuses = () => {
|
||||
for (const [id, status] of statuses) {
|
||||
if (status === "uploaded" || status === "error") {
|
||||
statuses.delete(id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const generateThumbnail = limitFunction(
|
||||
async (fileId: number, fileBuffer: ArrayBuffer, fileType: string, dataKey: CryptoKey) => {
|
||||
statuses.set(fileId, "generating");
|
||||
|
||||
const thumbnail = await doGenerateThumbnail(fileBuffer, fileType);
|
||||
if (!thumbnail) return null;
|
||||
|
||||
const thumbnailBuffer = await thumbnail.arrayBuffer();
|
||||
const thumbnailEncrypted = await encryptData(thumbnailBuffer, dataKey);
|
||||
statuses.set(fileId, "upload-pending");
|
||||
return { plaintext: thumbnailBuffer, ...thumbnailEncrypted };
|
||||
},
|
||||
{ concurrency: 4 },
|
||||
);
|
||||
|
||||
const requestThumbnailUpload = limitFunction(
|
||||
async (
|
||||
fileId: number,
|
||||
dataKeyVersion: Date,
|
||||
thumbnail: { plaintext: ArrayBuffer; ciphertext: ArrayBuffer; iv: string },
|
||||
) => {
|
||||
statuses.set(fileId, "uploading");
|
||||
|
||||
const res = await requestFileThumbnailUpload(fileId, dataKeyVersion, thumbnail);
|
||||
if (!res.ok) return false;
|
||||
statuses.set(fileId, "uploaded");
|
||||
storeFileThumbnailCache(fileId, thumbnail.plaintext); // Intended
|
||||
return true;
|
||||
},
|
||||
{ concurrency: 4 },
|
||||
);
|
||||
|
||||
export const requestThumbnailGeneration = async (fileInfo: FileInfo) => {
|
||||
const status = statuses.get(fileInfo.id);
|
||||
if (status) {
|
||||
if (status !== "error") return;
|
||||
} else {
|
||||
statuses.set(fileInfo.id, "queued");
|
||||
}
|
||||
|
||||
try {
|
||||
let file: ArrayBuffer | undefined;
|
||||
|
||||
await scheduler.schedule(
|
||||
async () => {
|
||||
statuses.set(fileInfo.id, "generation-pending");
|
||||
file = await requestFileDownload(fileInfo.id, fileInfo.contentIv!, fileInfo.dataKey?.key!);
|
||||
return file.byteLength;
|
||||
},
|
||||
async () => {
|
||||
const thumbnail = await generateThumbnail(
|
||||
fileInfo.id,
|
||||
file!,
|
||||
fileInfo.contentType,
|
||||
fileInfo.dataKey?.key!,
|
||||
);
|
||||
if (
|
||||
!thumbnail ||
|
||||
!(await requestThumbnailUpload(fileInfo.id, fileInfo.dataKey?.version!, thumbnail))
|
||||
) {
|
||||
statuses.set(fileInfo.id, "error");
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
statuses.set(fileInfo.id, "error");
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
@@ -1,12 +1,16 @@
|
||||
<script lang="ts">
|
||||
import { goto } from "$app/navigation";
|
||||
import { TopBar } from "$lib/components/molecules";
|
||||
import { Category, CategoryCreateModal } from "$lib/components/organisms";
|
||||
import { getCategoryInfo, type CategoryInfo } from "$lib/modules/filesystem";
|
||||
import { CheckBox, RowVirtualizer } from "$lib/components/atoms";
|
||||
import { SubCategories, TopBar } from "$lib/components/molecules";
|
||||
import { CategoryCreateModal } from "$lib/components/organisms";
|
||||
import { updateCategoryInfo } from "$lib/indexedDB";
|
||||
import { getCategoryInfo, type MaybeCategoryInfo } from "$lib/modules/filesystem";
|
||||
import { masterKeyStore } from "$lib/stores";
|
||||
import { HybridPromise, sortEntries } from "$lib/utils";
|
||||
import CategoryDeleteModal from "./CategoryDeleteModal.svelte";
|
||||
import CategoryMenuBottomSheet from "./CategoryMenuBottomSheet.svelte";
|
||||
import CategoryRenameModal from "./CategoryRenameModal.svelte";
|
||||
import File from "./File.svelte";
|
||||
import {
|
||||
createContext,
|
||||
requestCategoryCreation,
|
||||
@@ -15,18 +19,50 @@
|
||||
requestCategoryDeletion,
|
||||
} from "./service.svelte";
|
||||
|
||||
import IconMoreVert from "~icons/material-symbols/more-vert";
|
||||
|
||||
let { data } = $props();
|
||||
let context = createContext();
|
||||
|
||||
let infoPromise: Promise<CategoryInfo> | undefined = $state();
|
||||
let info: MaybeCategoryInfo | undefined = $state();
|
||||
|
||||
let isCategoryCreateModalOpen = $state(false);
|
||||
let isCategoryMenuBottomSheetOpen = $state(false);
|
||||
let isCategoryRenameModalOpen = $state(false);
|
||||
let isCategoryDeleteModalOpen = $state(false);
|
||||
|
||||
let lastCategoryId: CategoryId | undefined = $state();
|
||||
let lastIsFileRecursive: boolean | undefined = $state();
|
||||
|
||||
let files = $derived(
|
||||
sortEntries(
|
||||
info?.files
|
||||
?.map((file) => ({ name: file.name, details: file }))
|
||||
.filter(({ details }) => info?.isFileRecursive || !details.isRecursive) ?? [],
|
||||
),
|
||||
);
|
||||
|
||||
$effect(() => {
|
||||
infoPromise = getCategoryInfo(data.id, $masterKeyStore?.get(1)?.key!);
|
||||
if (!info || info.id === "root" || info.isFileRecursive === undefined) return;
|
||||
if (lastCategoryId !== info.id) {
|
||||
lastCategoryId = info.id;
|
||||
lastIsFileRecursive = info.isFileRecursive;
|
||||
return;
|
||||
}
|
||||
if (lastIsFileRecursive === info.isFileRecursive) return;
|
||||
|
||||
lastIsFileRecursive = info.isFileRecursive;
|
||||
void updateCategoryInfo(info.id, { isFileRecursive: info.isFileRecursive });
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
HybridPromise.resolve(getCategoryInfo(data.id, $masterKeyStore?.get(1)?.key!)).then(
|
||||
(result) => {
|
||||
if (data.id === result.id) {
|
||||
info = result;
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -34,34 +70,64 @@
|
||||
<title>카테고리</title>
|
||||
</svelte:head>
|
||||
|
||||
{#await infoPromise then info}
|
||||
{#if info}
|
||||
{#if info.id !== "root"}
|
||||
<TopBar title={info.name} />
|
||||
{#if info?.id !== "root"}
|
||||
<TopBar title={info?.name} />
|
||||
{/if}
|
||||
<div class="min-h-full bg-gray-100 pb-[5.5em]">
|
||||
<Category
|
||||
bind:isFileRecursive={info.isFileRecursive}
|
||||
{#if info?.exists}
|
||||
<div class="space-y-4">
|
||||
<div class="space-y-4 bg-white p-4">
|
||||
{#if info.id !== "root"}
|
||||
<p class="text-lg font-bold text-gray-800">하위 카테고리</p>
|
||||
{/if}
|
||||
<SubCategories
|
||||
{info}
|
||||
onFileClick={({ id }) => goto(`/file/${id}?from=category`)}
|
||||
onFileRemoveClick={async ({ id }) => {
|
||||
await requestFileRemovalFromCategory(id, data.id as number);
|
||||
infoPromise = getCategoryInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
}}
|
||||
onSubCategoryClick={({ id }) => goto(`/category/${id}`)}
|
||||
onSubCategoryCreateClick={() => (isCategoryCreateModalOpen = true)}
|
||||
onSubCategoryMenuClick={(subCategory) => {
|
||||
context.selectedCategory = subCategory;
|
||||
isCategoryMenuBottomSheetOpen = true;
|
||||
}}
|
||||
subCategoryMenuIcon={IconMoreVert}
|
||||
/>
|
||||
</div>
|
||||
{#if info.id !== "root"}
|
||||
<div class="space-y-4 bg-white p-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<p class="text-lg font-bold text-gray-800">파일</p>
|
||||
<CheckBox bind:checked={info.isFileRecursive}>
|
||||
<p class="font-medium">하위 카테고리의 파일</p>
|
||||
</CheckBox>
|
||||
</div>
|
||||
<RowVirtualizer count={files.length} itemHeight={() => 48} itemGap={4}>
|
||||
{#snippet item(index)}
|
||||
{@const { details } = files[index]!}
|
||||
<File
|
||||
info={details}
|
||||
onclick={({ id }) => goto(`/file/${id}?from=category`)}
|
||||
onRemoveClick={!details.isRecursive
|
||||
? async ({ id }) => {
|
||||
await requestFileRemovalFromCategory(id, data.id as number);
|
||||
void getCategoryInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
}
|
||||
: undefined}
|
||||
/>
|
||||
{/snippet}
|
||||
{#snippet placeholder()}
|
||||
<p class="text-center text-gray-500">이 카테고리에 추가된 파일이 없어요.</p>
|
||||
{/snippet}
|
||||
</RowVirtualizer>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<CategoryCreateModal
|
||||
bind:isOpen={isCategoryCreateModalOpen}
|
||||
onCreateClick={async (name: string) => {
|
||||
if (await requestCategoryCreation(name, data.id, $masterKeyStore?.get(1)!)) {
|
||||
infoPromise = getCategoryInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
void getCategoryInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -83,7 +149,7 @@
|
||||
bind:isOpen={isCategoryRenameModalOpen}
|
||||
onRenameClick={async (newName: string) => {
|
||||
if (await requestCategoryRename(context.selectedCategory!, newName)) {
|
||||
infoPromise = getCategoryInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
void getCategoryInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -93,11 +159,9 @@
|
||||
bind:isOpen={isCategoryDeleteModalOpen}
|
||||
onDeleteClick={async () => {
|
||||
if (await requestCategoryDeletion(context.selectedCategory!)) {
|
||||
infoPromise = getCategoryInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
void getCategoryInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
{/await}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { browser } from "$app/environment";
|
||||
import { ActionEntryButton } from "$lib/components/atoms";
|
||||
import { DirectoryEntryLabel } from "$lib/components/molecules";
|
||||
import { getFileThumbnail } from "$lib/modules/file";
|
||||
import type { CategoryFileInfo } from "$lib/modules/filesystem";
|
||||
import { requestFileThumbnailDownload } from "$lib/services/file";
|
||||
import type { SelectedFile } from "./service";
|
||||
import type { SelectedFile } from "./service.svelte";
|
||||
|
||||
import IconClose from "~icons/material-symbols/close";
|
||||
|
||||
@@ -16,12 +15,7 @@
|
||||
|
||||
let { info, onclick, onRemoveClick }: Props = $props();
|
||||
|
||||
let showThumbnail = $derived(
|
||||
browser && (info.contentType.startsWith("image/") || info.contentType.startsWith("video/")),
|
||||
);
|
||||
let thumbnailPromise = $derived(
|
||||
showThumbnail ? requestFileThumbnailDownload(info.id, info.dataKey?.key) : null,
|
||||
);
|
||||
let thumbnail = $derived(getFileThumbnail(info));
|
||||
</script>
|
||||
|
||||
<ActionEntryButton
|
||||
@@ -30,9 +24,5 @@
|
||||
actionButtonIcon={onRemoveClick && IconClose}
|
||||
onActionButtonClick={() => onRemoveClick?.(info)}
|
||||
>
|
||||
{#await thumbnailPromise}
|
||||
<DirectoryEntryLabel type="file" name={info.name} />
|
||||
{:then thumbnail}
|
||||
<DirectoryEntryLabel type="file" thumbnail={thumbnail ?? undefined} name={info.name} />
|
||||
{/await}
|
||||
<DirectoryEntryLabel type="file" thumbnail={$thumbnail} name={info.name} />
|
||||
</ActionEntryButton>
|
||||
@@ -5,6 +5,11 @@ import { trpc } from "$trpc/client";
|
||||
|
||||
export { requestCategoryCreation, requestFileRemovalFromCategory } from "$lib/services/category";
|
||||
|
||||
export interface SelectedFile {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export const createContext = () => {
|
||||
const context = $state({
|
||||
selectedCategory: undefined as SelectedCategory | undefined,
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
import { page } from "$app/state";
|
||||
import { FloatingButton } from "$lib/components/atoms";
|
||||
import { TopBar } from "$lib/components/molecules";
|
||||
import { getDirectoryInfo, type DirectoryInfo } from "$lib/modules/filesystem";
|
||||
import { getDirectoryInfo, type MaybeDirectoryInfo } from "$lib/modules/filesystem";
|
||||
import { masterKeyStore, hmacSecretStore } from "$lib/stores";
|
||||
import { HybridPromise } from "$lib/utils";
|
||||
import DirectoryCreateModal from "./DirectoryCreateModal.svelte";
|
||||
import DirectoryEntries from "./DirectoryEntries";
|
||||
import DownloadStatusCard from "./DownloadStatusCard.svelte";
|
||||
@@ -29,7 +30,7 @@
|
||||
let { data } = $props();
|
||||
let context = createContext();
|
||||
|
||||
let infoPromise: Promise<DirectoryInfo> | undefined = $state();
|
||||
let info: MaybeDirectoryInfo | undefined = $state();
|
||||
let fileInput: HTMLInputElement | undefined = $state();
|
||||
let duplicatedFile: File | undefined = $state();
|
||||
let resolveForDuplicateFileModal: ((res: boolean) => void) | undefined = $state();
|
||||
@@ -60,7 +61,7 @@
|
||||
.then((res) => {
|
||||
if (!res) return;
|
||||
// TODO: FIXME
|
||||
infoPromise = getDirectoryInfo(data.id, $masterKeyStore?.get(1)?.key!);
|
||||
void getDirectoryInfo(data.id, $masterKeyStore?.get(1)?.key!);
|
||||
})
|
||||
.catch((e: Error) => {
|
||||
// TODO: FIXME
|
||||
@@ -78,7 +79,13 @@
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
infoPromise = getDirectoryInfo(data.id, $masterKeyStore?.get(1)?.key!);
|
||||
HybridPromise.resolve(getDirectoryInfo(data.id, $masterKeyStore?.get(1)?.key!)).then(
|
||||
(result) => {
|
||||
if (data.id === result.id) {
|
||||
info = result;
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -88,17 +95,17 @@
|
||||
|
||||
<input bind:this={fileInput} onchange={uploadFile} type="file" multiple class="hidden" />
|
||||
|
||||
{#await infoPromise then info}
|
||||
{#if info}
|
||||
<div class="flex h-full flex-col">
|
||||
{#if showTopBar}
|
||||
<TopBar title={info.name} class="flex-shrink-0" />
|
||||
<TopBar title={info?.name} class="flex-shrink-0" />
|
||||
{/if}
|
||||
{#if info?.exists}
|
||||
<div class={["flex flex-grow flex-col px-4 pb-4", !showTopBar && "pt-4"]}>
|
||||
<div class="flex gap-x-2">
|
||||
<UploadStatusCard onclick={() => goto("/file/uploads")} />
|
||||
<DownloadStatusCard onclick={() => goto("/file/downloads")} />
|
||||
</div>
|
||||
{#key info.id}
|
||||
<DirectoryEntries
|
||||
{info}
|
||||
onEntryClick={({ type, id }) => goto(`/${type}/${id}`)}
|
||||
@@ -109,12 +116,14 @@
|
||||
showParentEntry={isFromFilePage && info.parentId !== undefined}
|
||||
onParentClick={() =>
|
||||
goto(
|
||||
info.parentId === "root"
|
||||
info!.parentId === "root"
|
||||
? "/directory?from=file"
|
||||
: `/directory/${info.parentId}?from=file`,
|
||||
: `/directory/${info!.parentId}?from=file`,
|
||||
)}
|
||||
/>
|
||||
{/key}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<FloatingButton
|
||||
@@ -139,7 +148,7 @@
|
||||
bind:isOpen={isDirectoryCreateModalOpen}
|
||||
onCreateClick={async (name) => {
|
||||
if (await requestDirectoryCreation(name, data.id, $masterKeyStore?.get(1)!)) {
|
||||
infoPromise = getDirectoryInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
void getDirectoryInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -173,7 +182,7 @@
|
||||
bind:isOpen={isEntryRenameModalOpen}
|
||||
onRenameClick={async (newName: string) => {
|
||||
if (await requestEntryRename(context.selectedEntry!, newName)) {
|
||||
infoPromise = getDirectoryInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
void getDirectoryInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -183,11 +192,9 @@
|
||||
bind:isOpen={isEntryDeleteModalOpen}
|
||||
onDeleteClick={async () => {
|
||||
if (await requestEntryDeletion(context.selectedEntry!)) {
|
||||
infoPromise = getDirectoryInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
void getDirectoryInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
{/await}
|
||||
|
||||
@@ -33,31 +33,22 @@
|
||||
|
||||
const toEntry =
|
||||
<T extends Exclude<Entry["type"], "parent">>(type: T) =>
|
||||
(details: Extract<Entry, { type: T }>["details"]) => ({
|
||||
type,
|
||||
name: details.name,
|
||||
details,
|
||||
});
|
||||
(details: Extract<Entry, { type: T }>["details"]) => ({ type, name: details.name, details });
|
||||
|
||||
let entries = $derived([
|
||||
...(showParentEntry ? ([{ type: "parent" }] as const) : []),
|
||||
...sortEntries(info.subDirectories.map(toEntry("directory"))),
|
||||
...sortEntries([
|
||||
...info.files.map(toEntry("file")),
|
||||
...getUploadingFiles(info.id).map(toEntry("uploading-file")),
|
||||
...(getUploadingFiles(info.id) as LiveFileUploadState[]).map(toEntry("uploading-file")),
|
||||
]),
|
||||
]);
|
||||
</script>
|
||||
|
||||
{#if entries.length > 0}
|
||||
<div class="pb-[4.5rem]">
|
||||
<RowVirtualizer
|
||||
count={entries.length}
|
||||
itemHeight={(index) => 56 + (index + 1 < entries.length ? 4 : 0)}
|
||||
>
|
||||
<RowVirtualizer count={entries.length} itemHeight={() => 56} itemGap={4} class="pb-[4.5rem]">
|
||||
{#snippet item(index)}
|
||||
{@const entry = entries[index]!}
|
||||
<div class={index + 1 < entries.length ? "pb-1" : ""}>
|
||||
{#if entry.type === "parent"}
|
||||
<ActionEntryButton class="h-14" onclick={onParentClick}>
|
||||
<DirectoryEntryLabel type="parent-directory" name=".." />
|
||||
@@ -73,10 +64,8 @@
|
||||
{:else}
|
||||
<UploadingFile state={entry.details} />
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
</RowVirtualizer>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex flex-grow items-center justify-center">
|
||||
<p class="text-gray-500">폴더가 비어 있어요.</p>
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { browser } from "$app/environment";
|
||||
import { ActionEntryButton } from "$lib/components/atoms";
|
||||
import { DirectoryEntryLabel } from "$lib/components/molecules";
|
||||
import { getFileThumbnail } from "$lib/modules/file";
|
||||
import type { SummarizedFileInfo } from "$lib/modules/filesystem";
|
||||
import { requestFileThumbnailDownload } from "$lib/services/file";
|
||||
import { formatDateTime } from "$lib/utils";
|
||||
import type { SelectedEntry } from "../service.svelte";
|
||||
|
||||
@@ -17,12 +16,7 @@
|
||||
|
||||
let { info, onclick, onOpenMenuClick }: Props = $props();
|
||||
|
||||
let showThumbnail = $derived(
|
||||
browser && (info.contentType.startsWith("image/") || info.contentType.startsWith("video/")),
|
||||
);
|
||||
let thumbnailPromise = $derived(
|
||||
showThumbnail ? requestFileThumbnailDownload(info.id, info.dataKey?.key) : null,
|
||||
);
|
||||
let thumbnail = $derived(getFileThumbnail(info));
|
||||
|
||||
const action = (callback: typeof onclick) => {
|
||||
callback({ type: "file", id: info.id, dataKey: info.dataKey, name: info.name });
|
||||
@@ -35,18 +29,10 @@
|
||||
actionButtonIcon={IconMoreVert}
|
||||
onActionButtonClick={() => action(onOpenMenuClick)}
|
||||
>
|
||||
{#await thumbnailPromise}
|
||||
<DirectoryEntryLabel
|
||||
type="file"
|
||||
thumbnail={$thumbnail}
|
||||
name={info.name}
|
||||
subtext={formatDateTime(info.createdAt ?? info.lastModifiedAt)}
|
||||
/>
|
||||
{:then thumbnail}
|
||||
<DirectoryEntryLabel
|
||||
type="file"
|
||||
thumbnail={thumbnail ?? undefined}
|
||||
name={info.name}
|
||||
subtext={formatDateTime(info.createdAt ?? info.lastModifiedAt)}
|
||||
/>
|
||||
{/await}
|
||||
</ActionEntryButton>
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
{state.name}
|
||||
</p>
|
||||
<p class="text-xs">
|
||||
{#if state.status === "encryption-pending"}
|
||||
{#if state.status === "queued"}
|
||||
대기 중
|
||||
{:else if state.status === "encryption-pending"}
|
||||
준비 중
|
||||
{:else if state.status === "encrypting"}
|
||||
암호화하는 중
|
||||
|
||||
@@ -2,17 +2,13 @@
|
||||
import { onMount } from "svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import { EntryButton, FileThumbnailButton } from "$lib/components/atoms";
|
||||
import { getFileInfo, type FileInfo } from "$lib/modules/filesystem";
|
||||
import { masterKeyStore } from "$lib/stores";
|
||||
import { type SummarizedFileInfo } from "$lib/modules/filesystem";
|
||||
import { requestFreshMediaFilesRetrieval } from "./service";
|
||||
|
||||
let mediaFiles: (FileInfo | null)[] = $state([]);
|
||||
let mediaFiles: SummarizedFileInfo[] = $state([]);
|
||||
|
||||
onMount(async () => {
|
||||
const files = await requestFreshMediaFilesRetrieval();
|
||||
mediaFiles = await Promise.all(
|
||||
files.map(({ id }) => getFileInfo(id, $masterKeyStore?.get(1)?.key!)),
|
||||
);
|
||||
mediaFiles = await requestFreshMediaFilesRetrieval();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -28,10 +24,8 @@
|
||||
</EntryButton>
|
||||
{#if mediaFiles.length > 0}
|
||||
<div class="grid grid-cols-4 gap-2 p-2">
|
||||
{#each mediaFiles as file}
|
||||
{#if file}
|
||||
{#each mediaFiles as file (file.id)}
|
||||
<FileThumbnailButton info={file} onclick={({ id }) => goto(`/file/${id}`)} />
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { RequestHandler } from "./$types";
|
||||
const trpcHandler: RequestHandler = (event) =>
|
||||
fetchRequestHandler({
|
||||
endpoint: "/api/trpc",
|
||||
allowMethodOverride: true,
|
||||
req: event.request,
|
||||
router: appRouter,
|
||||
createContext: () => createContext(event),
|
||||
|
||||
@@ -9,6 +9,7 @@ const createClient = (fetch: typeof globalThis.fetch) =>
|
||||
httpBatchLink({
|
||||
url: "/api/trpc",
|
||||
maxURLLength: 4096,
|
||||
methodOverride: "POST",
|
||||
transformer: superjson,
|
||||
fetch,
|
||||
}),
|
||||
|
||||
@@ -46,6 +46,7 @@ const categoryRouter = router({
|
||||
})),
|
||||
files: files?.map((file) => ({
|
||||
id: file.id,
|
||||
parent: file.parentId,
|
||||
mekVersion: file.mekVersion,
|
||||
dek: file.encDek,
|
||||
dekVersion: file.dekVersion,
|
||||
|
||||
@@ -33,6 +33,7 @@ const fileRouter = router({
|
||||
lastModifiedAtIv: file.encLastModifiedAt.iv,
|
||||
categories: categories.map((category) => ({
|
||||
id: category.id,
|
||||
parent: category.parentId,
|
||||
mekVersion: category.mekVersion,
|
||||
dek: category.encDek,
|
||||
dekVersion: category.dekVersion,
|
||||
@@ -42,6 +43,40 @@ const fileRouter = router({
|
||||
};
|
||||
}),
|
||||
|
||||
bulkGet: roleProcedure["activeClient"]
|
||||
.input(
|
||||
z.object({
|
||||
ids: z.number().positive().array(),
|
||||
}),
|
||||
)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const files = await FileRepo.getFilesWithCategories(ctx.session.userId, input.ids);
|
||||
return files.map((file) => ({
|
||||
id: file.id,
|
||||
parent: file.parentId,
|
||||
mekVersion: file.mekVersion,
|
||||
dek: file.encDek,
|
||||
dekVersion: file.dekVersion,
|
||||
contentType: file.contentType,
|
||||
contentIv: file.encContentIv,
|
||||
name: file.encName.ciphertext,
|
||||
nameIv: file.encName.iv,
|
||||
createdAt: file.encCreatedAt?.ciphertext,
|
||||
createdAtIv: file.encCreatedAt?.iv,
|
||||
lastModifiedAt: file.encLastModifiedAt.ciphertext,
|
||||
lastModifiedAtIv: file.encLastModifiedAt.iv,
|
||||
categories: file.categories.map((category) => ({
|
||||
id: category.id,
|
||||
parent: category.parentId,
|
||||
mekVersion: category.mekVersion,
|
||||
dek: category.encDek,
|
||||
dekVersion: category.dekVersion,
|
||||
name: category.encName.ciphertext,
|
||||
nameIv: category.encName.iv,
|
||||
})),
|
||||
}));
|
||||
}),
|
||||
|
||||
list: roleProcedure["activeClient"].query(async ({ ctx }) => {
|
||||
return await FileRepo.getAllFileIds(ctx.session.userId);
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user