mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-03 23:56:53 +00:00
Compare commits
8 Commits
b7a7536461
...
576d41da7f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
576d41da7f | ||
|
|
9eb67d5877 | ||
|
|
a9da8435cb | ||
|
|
3e98e3d591 | ||
|
|
27a46bcc2e | ||
|
|
a1f30ee154 | ||
|
|
6d02178c69 | ||
|
|
ed21a9cd31 |
@@ -1,21 +1,24 @@
|
||||
import prettier from "eslint-config-prettier";
|
||||
import js from "@eslint/js";
|
||||
import { includeIgnoreFile } from "@eslint/compat";
|
||||
import js from "@eslint/js";
|
||||
import { defineConfig } from "eslint/config";
|
||||
import prettier from "eslint-config-prettier";
|
||||
import svelte from "eslint-plugin-svelte";
|
||||
import tailwind from "eslint-plugin-tailwindcss";
|
||||
import globals from "globals";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import ts from "typescript-eslint";
|
||||
import { fileURLToPath } from "url";
|
||||
import svelteConfig from "./svelte.config.js";
|
||||
|
||||
const gitignorePath = fileURLToPath(new URL("./.gitignore", import.meta.url));
|
||||
|
||||
export default ts.config(
|
||||
export default defineConfig(
|
||||
includeIgnoreFile(gitignorePath),
|
||||
js.configs.recommended,
|
||||
...ts.configs.recommended,
|
||||
...svelte.configs["flat/recommended"],
|
||||
...svelte.configs.recommended,
|
||||
...tailwind.configs["flat/recommended"],
|
||||
prettier,
|
||||
...svelte.configs["flat/prettier"],
|
||||
...svelte.configs.prettier,
|
||||
{
|
||||
languageOptions: {
|
||||
globals: {
|
||||
@@ -23,13 +26,18 @@ export default ts.config(
|
||||
...globals.node,
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
"no-undef": "off",
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["**/*.svelte"],
|
||||
|
||||
files: ["**/*.svelte", "**/*.svelte.ts", "**/*.svelte.js"],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
projectService: true,
|
||||
extraFileExtensions: [".svelte"],
|
||||
parser: ts.parser,
|
||||
svelteConfig,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "arkvault",
|
||||
"private": true,
|
||||
"version": "0.5.1",
|
||||
"version": "0.6.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
@@ -16,11 +16,12 @@
|
||||
"db:migrate": "kysely migrate"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^1.4.1",
|
||||
"@eslint/compat": "^2.0.0",
|
||||
"@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",
|
||||
"@trpc/client": "^11.8.1",
|
||||
"@types/file-saver": "^2.0.7",
|
||||
"@types/ms": "^0.7.34",
|
||||
|
||||
40
pnpm-lock.yaml
generated
40
pnpm-lock.yaml
generated
@@ -40,8 +40,8 @@ importers:
|
||||
version: 4.2.1
|
||||
devDependencies:
|
||||
'@eslint/compat':
|
||||
specifier: ^1.4.1
|
||||
version: 1.4.1(eslint@9.39.2(jiti@1.21.7))
|
||||
specifier: ^2.0.0
|
||||
version: 2.0.0(eslint@9.39.2(jiti@1.21.7))
|
||||
'@iconify-json/material-symbols':
|
||||
specifier: ^1.2.50
|
||||
version: 1.2.50
|
||||
@@ -54,6 +54,9 @@ importers:
|
||||
'@sveltejs/vite-plugin-svelte':
|
||||
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)
|
||||
'@trpc/client':
|
||||
specifier: ^11.8.1
|
||||
version: 11.8.1(@trpc/server@11.8.1(typescript@5.9.3))(typescript@5.9.3)
|
||||
@@ -323,9 +326,9 @@ packages:
|
||||
resolution: {integrity: sha512-EriSTlt5OC9/7SXkRSCAhfSxxoSUgBm33OH+IkwbdpgoqsSsUg7y3uh+IICI/Qg4BBWr3U2i39RpmycbxMq4ew==}
|
||||
engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0}
|
||||
|
||||
'@eslint/compat@1.4.1':
|
||||
resolution: {integrity: sha512-cfO82V9zxxGBxcQDr1lfaYB7wykTa0b00mGa36FrJl7iTFd0Z2cHfEYuxcBRP/iNijCsWsEkA+jzT8hGYmv33w==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
'@eslint/compat@2.0.0':
|
||||
resolution: {integrity: sha512-T9AfE1G1uv4wwq94ozgTGio5EUQBqAVe1X9qsQtSNVEYW6j3hvtZVm8Smr4qL1qDPFg+lOB2cL5RxTRMzq4CTA==}
|
||||
engines: {node: ^20.19.0 || ^22.13.0 || >=24}
|
||||
peerDependencies:
|
||||
eslint: ^8.40 || 9
|
||||
peerDependenciesMeta:
|
||||
@@ -344,6 +347,10 @@ packages:
|
||||
resolution: {integrity: sha512-yL/sLrpmtDaFEiUj1osRP4TI2MDz1AddJL+jZ7KSqvBuliN4xqYY54IfdN8qD8Toa6g1iloph1fxQNkjOxrrpQ==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
|
||||
'@eslint/core@1.0.0':
|
||||
resolution: {integrity: sha512-PRfWP+8FOldvbApr6xL7mNCw4cJcSTq4GA7tYbgq15mRb0kWKO/wEB2jr+uwjFH3sZvEZneZyCUGTxsv4Sahyw==}
|
||||
engines: {node: ^20.19.0 || ^22.13.0 || >=24}
|
||||
|
||||
'@eslint/eslintrc@3.3.3':
|
||||
resolution: {integrity: sha512-Kr+LPIUVKz2qkx1HAMH8q1q6azbqBAsXJUxBl/ODDuVPX45Z9DfwB8tPjTi6nNZ8BuM3nbJxC5zCAg5elnBUTQ==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
@@ -610,6 +617,14 @@ packages:
|
||||
svelte: ^5.0.0
|
||||
vite: ^6.3.0 || ^7.0.0
|
||||
|
||||
'@tanstack/svelte-virtual@3.13.13':
|
||||
resolution: {integrity: sha512-VDOvbRw3R+XBQdFodEJ4E7AOmEyo3Bmr4zL4DLVnJ0fxICdbvY5F5t8zSwJ4f7lqjckXi0yKFzY8WBtjaNbsGQ==}
|
||||
peerDependencies:
|
||||
svelte: ^3.48.0 || ^4.0.0 || ^5.0.0
|
||||
|
||||
'@tanstack/virtual-core@3.13.13':
|
||||
resolution: {integrity: sha512-uQFoSdKKf5S8k51W5t7b2qpfkyIbdHMzAn+AMQvHPxKUPeo1SsGaA4JRISQT87jm28b7z8OEqPcg1IOZagQHcA==}
|
||||
|
||||
'@trpc/client@11.8.1':
|
||||
resolution: {integrity: sha512-L/SJFGanr9xGABmuDoeXR4xAdHJmsXsiF9OuH+apecJ+8sUITzVT1EPeqp0ebqA6lBhEl5pPfg3rngVhi/h60Q==}
|
||||
peerDependencies:
|
||||
@@ -2106,9 +2121,9 @@ snapshots:
|
||||
|
||||
'@eslint-community/regexpp@4.12.2': {}
|
||||
|
||||
'@eslint/compat@1.4.1(eslint@9.39.2(jiti@1.21.7))':
|
||||
'@eslint/compat@2.0.0(eslint@9.39.2(jiti@1.21.7))':
|
||||
dependencies:
|
||||
'@eslint/core': 0.17.0
|
||||
'@eslint/core': 1.0.0
|
||||
optionalDependencies:
|
||||
eslint: 9.39.2(jiti@1.21.7)
|
||||
|
||||
@@ -2128,6 +2143,10 @@ snapshots:
|
||||
dependencies:
|
||||
'@types/json-schema': 7.0.15
|
||||
|
||||
'@eslint/core@1.0.0':
|
||||
dependencies:
|
||||
'@types/json-schema': 7.0.15
|
||||
|
||||
'@eslint/eslintrc@3.3.3':
|
||||
dependencies:
|
||||
ajv: 6.12.6
|
||||
@@ -2367,6 +2386,13 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@tanstack/svelte-virtual@3.13.13(svelte@5.46.1)':
|
||||
dependencies:
|
||||
'@tanstack/virtual-core': 3.13.13
|
||||
svelte: 5.46.1
|
||||
|
||||
'@tanstack/virtual-core@3.13.13': {}
|
||||
|
||||
'@trpc/client@11.8.1(@trpc/server@11.8.1(typescript@5.9.3))(typescript@5.9.3)':
|
||||
dependencies:
|
||||
'@trpc/server': 11.8.1(typescript@5.9.3)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import type { SvelteHTMLElements } from "svelte/elements";
|
||||
import { get, type Writable } from "svelte/store";
|
||||
import type { CategoryInfo } from "$lib/modules/filesystem";
|
||||
import { SortBy, sortEntries } from "$lib/modules/util";
|
||||
import { SortBy, sortEntries } from "$lib/utils";
|
||||
import Category from "./Category.svelte";
|
||||
import type { SelectedCategory } from "./service";
|
||||
|
||||
|
||||
42
src/lib/components/molecules/FileThumbnailButton.svelte
Normal file
42
src/lib/components/molecules/FileThumbnailButton.svelte
Normal file
@@ -0,0 +1,42 @@
|
||||
<script lang="ts">
|
||||
import type { Writable } from "svelte/store";
|
||||
import type { FileInfo } from "$lib/modules/filesystem";
|
||||
import { requestFileThumbnailDownload } from "$lib/services/file";
|
||||
|
||||
interface Props {
|
||||
info: Writable<FileInfo | null>;
|
||||
onclick?: (file: FileInfo) => void;
|
||||
}
|
||||
|
||||
let { info, onclick }: Props = $props();
|
||||
|
||||
let thumbnail: string | undefined = $state();
|
||||
|
||||
$effect(() => {
|
||||
if ($info) {
|
||||
requestFileThumbnailDownload($info.id, $info.dataKey)
|
||||
.then((thumbnailUrl) => {
|
||||
thumbnail = thumbnailUrl ?? undefined;
|
||||
})
|
||||
.catch(() => {
|
||||
// TODO: Error Handling
|
||||
thumbnail = undefined;
|
||||
});
|
||||
} else {
|
||||
thumbnail = undefined;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if $info}
|
||||
<button
|
||||
onclick={() => onclick?.($info)}
|
||||
class="relative aspect-square w-full overflow-hidden rounded transition active:scale-95 active:brightness-90"
|
||||
>
|
||||
{#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}
|
||||
</button>
|
||||
{/if}
|
||||
@@ -2,6 +2,7 @@ export * from "./ActionModal.svelte";
|
||||
export { default as ActionModal } from "./ActionModal.svelte";
|
||||
export * from "./Categories";
|
||||
export { default as Categories } from "./Categories";
|
||||
export { default as FileThumbnailButton } from "./FileThumbnailButton.svelte";
|
||||
export { default as IconEntryButton } from "./IconEntryButton.svelte";
|
||||
export * from "./labels";
|
||||
export { default as SubCategories } from "./SubCategories.svelte";
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { IconLabel } from "$lib/components/molecules";
|
||||
|
||||
import IconFolder from "~icons/material-symbols/folder";
|
||||
import IconDriveFolderUpload from "~icons/material-symbols/drive-folder-upload";
|
||||
import IconDraft from "~icons/material-symbols/draft";
|
||||
|
||||
interface Props {
|
||||
@@ -11,7 +12,7 @@
|
||||
subtext?: string;
|
||||
textClass?: ClassValue;
|
||||
thumbnail?: string;
|
||||
type: "directory" | "file";
|
||||
type: "directory" | "parent-directory" | "file";
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -30,6 +31,8 @@
|
||||
<img src={thumbnail} alt={name} loading="lazy" class="aspect-square rounded object-cover" />
|
||||
{:else if type === "directory"}
|
||||
<IconFolder />
|
||||
{:else if type === "parent-directory"}
|
||||
<IconDriveFolderUpload class="text-yellow-500" />
|
||||
{:else}
|
||||
<IconDraft class="text-blue-400" />
|
||||
{/if}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
import { CheckBox } from "$lib/components/atoms";
|
||||
import { SubCategories, type SelectedCategory } from "$lib/components/molecules";
|
||||
import { getFileInfo, type FileInfo, type CategoryInfo } from "$lib/modules/filesystem";
|
||||
import { SortBy, sortEntries } from "$lib/modules/util";
|
||||
import { masterKeyStore } from "$lib/stores";
|
||||
import { SortBy, sortEntries } from "$lib/utils";
|
||||
import File from "./File.svelte";
|
||||
import type { SelectedFile } from "./service";
|
||||
|
||||
|
||||
148
src/lib/components/organisms/Gallery.svelte
Normal file
148
src/lib/components/organisms/Gallery.svelte
Normal file
@@ -0,0 +1,148 @@
|
||||
<script lang="ts">
|
||||
import { createWindowVirtualizer } from "@tanstack/svelte-virtual";
|
||||
import { untrack } from "svelte";
|
||||
import { get, type Writable } from "svelte/store";
|
||||
import { FileThumbnailButton } from "$lib/components/molecules";
|
||||
import type { FileInfo } from "$lib/modules/filesystem";
|
||||
import { formatDate, formatDateSortable, SortBy, sortEntries } from "$lib/utils";
|
||||
|
||||
interface Props {
|
||||
files: Writable<FileInfo | null>[];
|
||||
onFileClick?: (file: FileInfo) => void;
|
||||
}
|
||||
|
||||
let { files, onFileClick }: Props = $props();
|
||||
|
||||
type FileEntry =
|
||||
| { date?: undefined; contentType?: undefined; info: Writable<FileInfo | null> }
|
||||
| { date: Date; contentType: string; info: Writable<FileInfo | null> };
|
||||
type Row =
|
||||
| { type: "header"; key: string; label: string }
|
||||
| { type: "items"; key: string; items: FileEntry[] };
|
||||
|
||||
let filesWithDate: FileEntry[] = $state([]);
|
||||
let rows: Row[] = $state([]);
|
||||
let listElement: HTMLDivElement | undefined = $state();
|
||||
|
||||
const virtualizer = createWindowVirtualizer({
|
||||
count: 0,
|
||||
getItemKey: (index) => rows[index]!.key,
|
||||
estimateSize: () => 1000, // TODO
|
||||
});
|
||||
|
||||
const measureRow = (node: HTMLElement) => {
|
||||
$virtualizer.measureElement(node);
|
||||
return {
|
||||
update: () => $virtualizer.measureElement(node),
|
||||
};
|
||||
};
|
||||
|
||||
$effect(() => {
|
||||
filesWithDate = files.map((file) => {
|
||||
const info = get(file);
|
||||
if (info) {
|
||||
return {
|
||||
date: info.createdAt ?? info.lastModifiedAt,
|
||||
contentType: info.contentType,
|
||||
info: file,
|
||||
};
|
||||
} else {
|
||||
return { info: file };
|
||||
}
|
||||
});
|
||||
|
||||
const buildRows = () => {
|
||||
const map = new Map<string, FileEntry[]>();
|
||||
|
||||
for (const file of filesWithDate) {
|
||||
if (
|
||||
!file.date ||
|
||||
!(file.contentType.startsWith("image/") || file.contentType.startsWith("video/"))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const date = formatDateSortable(file.date);
|
||||
const entries = map.get(date) ?? [];
|
||||
entries.push(file);
|
||||
map.set(date, entries);
|
||||
}
|
||||
|
||||
const newRows: Row[] = [];
|
||||
const sortedDates = Array.from(map.keys()).sort((a, b) => b.localeCompare(a));
|
||||
for (const date of sortedDates) {
|
||||
const entries = map.get(date)!;
|
||||
sortEntries(entries, SortBy.DATE_DESC);
|
||||
|
||||
newRows.push({
|
||||
type: "header",
|
||||
key: `header-${date}`,
|
||||
label: formatDate(entries[0]!.date!),
|
||||
});
|
||||
newRows.push({
|
||||
type: "items",
|
||||
key: `items-${date}`,
|
||||
items: entries,
|
||||
});
|
||||
}
|
||||
|
||||
rows = newRows;
|
||||
$virtualizer.setOptions({ count: rows.length });
|
||||
};
|
||||
return untrack(() => {
|
||||
buildRows();
|
||||
|
||||
const unsubscribes = filesWithDate.map((file) =>
|
||||
file.info.subscribe((value) => {
|
||||
const newDate = value?.createdAt ?? value?.lastModifiedAt;
|
||||
const newContentType = value?.contentType;
|
||||
if (file.date?.getTime() === newDate?.getTime() && file.contentType === newContentType) {
|
||||
return;
|
||||
}
|
||||
|
||||
file.date = newDate;
|
||||
file.contentType = newContentType;
|
||||
buildRows();
|
||||
}),
|
||||
);
|
||||
return () => unsubscribes.forEach((unsubscribe) => unsubscribe());
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div bind:this={listElement} class="relative flex flex-grow flex-col">
|
||||
<div style="height: {$virtualizer.getTotalSize()}px;">
|
||||
{#each $virtualizer.getVirtualItems() as virtualRow (virtualRow.key)}
|
||||
{@const row = rows[virtualRow.index]!}
|
||||
<div
|
||||
use:measureRow
|
||||
data-index={virtualRow.index}
|
||||
class="absolute left-0 top-0 w-full"
|
||||
style="transform: translateY({virtualRow.start}px);"
|
||||
>
|
||||
{#if row.type === "header"}
|
||||
<p class="pb-2 font-medium">{row.label}</p>
|
||||
{:else}
|
||||
<div class="grid grid-cols-4 gap-1 pb-4">
|
||||
{#each row.items as { info }}
|
||||
<FileThumbnailButton {info} onclick={onFileClick} />
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{#if $virtualizer.getVirtualItems().length === 0}
|
||||
<div class="flex h-full flex-grow items-center justify-center">
|
||||
<p class="text-gray-500">
|
||||
{#if files.length === 0}
|
||||
업로드된 파일이 없어요.
|
||||
{:else if filesWithDate.length === 0}
|
||||
파일 목록을 불러오고 있어요.
|
||||
{:else}
|
||||
사진 또는 동영상이 없어요.
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from "./Category";
|
||||
export { default as Category } from "./Category";
|
||||
export { default as Gallery } from "./Gallery.svelte";
|
||||
export * from "./modals";
|
||||
|
||||
@@ -23,6 +23,7 @@ import { trpc } from "$trpc/client";
|
||||
export type DirectoryInfo =
|
||||
| {
|
||||
id: "root";
|
||||
parentId?: undefined;
|
||||
dataKey?: undefined;
|
||||
dataKeyVersion?: undefined;
|
||||
name?: undefined;
|
||||
@@ -31,6 +32,7 @@ export type DirectoryInfo =
|
||||
}
|
||||
| {
|
||||
id: number;
|
||||
parentId: DirectoryId;
|
||||
dataKey?: CryptoKey;
|
||||
dataKeyVersion?: Date;
|
||||
name: string;
|
||||
@@ -40,6 +42,7 @@ export type DirectoryInfo =
|
||||
|
||||
export interface FileInfo {
|
||||
id: number;
|
||||
parentId: DirectoryId;
|
||||
dataKey?: CryptoKey;
|
||||
dataKeyVersion?: Date;
|
||||
contentType: string;
|
||||
@@ -92,7 +95,13 @@ const fetchDirectoryInfoFromIndexedDB = async (
|
||||
info.set({ id, subDirectoryIds, fileIds });
|
||||
} else {
|
||||
if (!directory) return;
|
||||
info.set({ id, name: directory.name, subDirectoryIds, fileIds });
|
||||
info.set({
|
||||
id,
|
||||
parentId: directory.parentId,
|
||||
name: directory.name,
|
||||
subDirectoryIds,
|
||||
fileIds,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -123,6 +132,7 @@ const fetchDirectoryInfoFromServer = async (
|
||||
|
||||
info.set({
|
||||
id,
|
||||
parentId: metadata!.parent,
|
||||
dataKey,
|
||||
dataKeyVersion: new Date(metadata!.dekVersion),
|
||||
name,
|
||||
@@ -199,6 +209,7 @@ const fetchFileInfoFromServer = async (
|
||||
|
||||
info.set({
|
||||
id,
|
||||
parentId: metadata.parent,
|
||||
dataKey,
|
||||
dataKeyVersion: new Date(metadata.dekVersion),
|
||||
contentType: metadata.contentType,
|
||||
|
||||
@@ -7,6 +7,13 @@ export const formatDate = (date: Date) => {
|
||||
return `${year}. ${month}. ${day}.`;
|
||||
};
|
||||
|
||||
export const formatDateSortable = (date: Date) => {
|
||||
const year = date.getFullYear();
|
||||
const month = pad2(date.getMonth() + 1);
|
||||
const day = pad2(date.getDate());
|
||||
return `${year}${month}${day}`;
|
||||
};
|
||||
|
||||
export const formatDateTime = (date: Date) => {
|
||||
const dateFormatted = formatDate(date);
|
||||
const hours = date.getHours();
|
||||
@@ -32,32 +39,3 @@ export const truncateString = (str: string, maxLength = 20) => {
|
||||
if (str.length <= maxLength) return str;
|
||||
return `${str.slice(0, maxLength)}...`;
|
||||
};
|
||||
|
||||
export enum SortBy {
|
||||
NAME_ASC,
|
||||
NAME_DESC,
|
||||
}
|
||||
|
||||
type SortFunc = (a?: string, b?: string) => number;
|
||||
|
||||
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
||||
|
||||
const sortByNameAsc: SortFunc = (a, b) => {
|
||||
if (a && b) return collator.compare(a, b);
|
||||
if (a) return -1;
|
||||
if (b) return 1;
|
||||
return 0;
|
||||
};
|
||||
|
||||
const sortByNameDesc: SortFunc = (a, b) => -sortByNameAsc(a, b);
|
||||
|
||||
export const sortEntries = <T extends { name?: string }>(entries: T[], sortBy: SortBy) => {
|
||||
let sortFunc: SortFunc;
|
||||
if (sortBy === SortBy.NAME_ASC) {
|
||||
sortFunc = sortByNameAsc;
|
||||
} else {
|
||||
sortFunc = sortByNameDesc;
|
||||
}
|
||||
|
||||
entries.sort((a, b) => sortFunc(a.name, b.name));
|
||||
};
|
||||
@@ -1 +1,3 @@
|
||||
export * from "./format";
|
||||
export * from "./gotoStateful";
|
||||
export * from "./sort";
|
||||
|
||||
57
src/lib/utils/sort.ts
Normal file
57
src/lib/utils/sort.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
interface SortEntry {
|
||||
name?: string;
|
||||
date?: Date;
|
||||
}
|
||||
|
||||
export enum SortBy {
|
||||
NAME_ASC,
|
||||
NAME_DESC,
|
||||
DATE_ASC,
|
||||
DATE_DESC,
|
||||
}
|
||||
|
||||
type SortFunc = (a: SortEntry, b: SortEntry) => number;
|
||||
|
||||
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
||||
|
||||
const sortByNameAsc: SortFunc = ({ name: a }, { name: b }) => {
|
||||
if (a && b) return collator.compare(a, b);
|
||||
if (a) return -1;
|
||||
if (b) return 1;
|
||||
return 0;
|
||||
};
|
||||
|
||||
const sortByNameDesc: SortFunc = (a, b) => -sortByNameAsc(a, b);
|
||||
|
||||
const sortByDateAsc: SortFunc = ({ date: a }, { date: b }) => {
|
||||
if (a && b) return a.getTime() - b.getTime();
|
||||
if (a) return -1;
|
||||
if (b) return 1;
|
||||
return 0;
|
||||
};
|
||||
|
||||
const sortByDateDesc: SortFunc = (a, b) => -sortByDateAsc(a, b);
|
||||
|
||||
export const sortEntries = <T extends SortEntry>(entries: T[], sortBy: SortBy) => {
|
||||
let sortFunc: SortFunc;
|
||||
|
||||
switch (sortBy) {
|
||||
case SortBy.NAME_ASC:
|
||||
sortFunc = sortByNameAsc;
|
||||
break;
|
||||
case SortBy.NAME_DESC:
|
||||
sortFunc = sortByNameDesc;
|
||||
break;
|
||||
case SortBy.DATE_ASC:
|
||||
sortFunc = sortByDateAsc;
|
||||
break;
|
||||
case SortBy.DATE_DESC:
|
||||
sortFunc = sortByDateDesc;
|
||||
break;
|
||||
default:
|
||||
const exhaustive: never = sortBy;
|
||||
sortFunc = exhaustive;
|
||||
}
|
||||
|
||||
entries.sort(sortFunc);
|
||||
};
|
||||
@@ -3,6 +3,7 @@
|
||||
import { untrack } from "svelte";
|
||||
import { get, type Writable } from "svelte/store";
|
||||
import { goto } from "$app/navigation";
|
||||
import { page } from "$app/state";
|
||||
import { FullscreenDiv } from "$lib/components/atoms";
|
||||
import { Categories, IconEntryButton, TopBar } from "$lib/components/molecules";
|
||||
import {
|
||||
@@ -21,7 +22,9 @@
|
||||
requestThumbnailUpload,
|
||||
requestFileAdditionToCategory,
|
||||
} from "./service";
|
||||
import TopBarMenu from "./TopBarMenu.svelte";
|
||||
|
||||
import IconMoreVert from "~icons/material-symbols/more-vert";
|
||||
import IconCamera from "~icons/material-symbols/camera";
|
||||
import IconClose from "~icons/material-symbols/close";
|
||||
import IconAddCircle from "~icons/material-symbols/add-circle";
|
||||
@@ -31,6 +34,7 @@
|
||||
let info: Writable<FileInfo | null> | undefined = $state();
|
||||
let categories: Writable<CategoryInfo | null>[] = $state([]);
|
||||
|
||||
let isMenuOpen = $state(false);
|
||||
let isAddToCategoryBottomSheetOpen = $state(false);
|
||||
|
||||
let downloadStatus = $derived(
|
||||
@@ -42,30 +46,26 @@
|
||||
|
||||
let isDownloadRequested = $state(false);
|
||||
let viewerType: "image" | "video" | undefined = $state();
|
||||
let fileBlob: Blob | undefined = $state();
|
||||
let fileBlobUrl: string | undefined = $state();
|
||||
let heicBlob: Blob | undefined = $state();
|
||||
let videoElement: HTMLVideoElement | undefined = $state();
|
||||
|
||||
const updateViewer = async (buffer: ArrayBuffer, contentType: string) => {
|
||||
const fileBlob = new Blob([buffer], { type: contentType });
|
||||
if (viewerType) {
|
||||
fileBlobUrl = URL.createObjectURL(fileBlob);
|
||||
heicBlob = contentType === "image/heic" ? fileBlob : undefined;
|
||||
}
|
||||
fileBlob = new Blob([buffer], { type: contentType });
|
||||
fileBlobUrl = URL.createObjectURL(fileBlob);
|
||||
return fileBlob;
|
||||
};
|
||||
|
||||
const convertHeicToJpeg = async () => {
|
||||
if (!heicBlob) return;
|
||||
if (fileBlob?.type !== "image/heic") return;
|
||||
|
||||
URL.revokeObjectURL(fileBlobUrl!);
|
||||
fileBlobUrl = undefined;
|
||||
|
||||
const { default: heic2any } = await import("heic2any");
|
||||
fileBlobUrl = URL.createObjectURL(
|
||||
(await heic2any({ blob: heicBlob, toType: "image/jpeg" })) as Blob,
|
||||
(await heic2any({ blob: fileBlob, toType: "image/jpeg" })) as Blob,
|
||||
);
|
||||
heicBlob = undefined;
|
||||
};
|
||||
|
||||
const updateThumbnail = async (dataKey: CryptoKey, dataKeyVersion: Date) => {
|
||||
@@ -133,7 +133,24 @@
|
||||
<title>파일</title>
|
||||
</svelte:head>
|
||||
|
||||
<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()}>
|
||||
<button
|
||||
onclick={() => (isMenuOpen = !isMenuOpen)}
|
||||
class="w-[2.3rem] flex-shrink-0 rounded-full p-1 active:bg-black active:bg-opacity-[0.04]"
|
||||
>
|
||||
<IconMoreVert class="text-2xl" />
|
||||
</button>
|
||||
<TopBarMenu
|
||||
bind:isOpen={isMenuOpen}
|
||||
directoryId={page.url.searchParams.get("from") === "category" ? $info?.parentId : undefined}
|
||||
{fileBlob}
|
||||
filename={$info?.name}
|
||||
/>
|
||||
</div>
|
||||
</TopBar>
|
||||
<FullscreenDiv>
|
||||
<div class="space-y-4 pb-4">
|
||||
<DownloadStatus status={downloadStatus} />
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import type { Writable } from "svelte/store";
|
||||
import { formatNetworkSpeed } from "$lib/modules/util";
|
||||
import { isFileDownloading, type FileDownloadStatus } from "$lib/stores";
|
||||
import { formatNetworkSpeed } from "$lib/utils";
|
||||
|
||||
interface Props {
|
||||
status?: Writable<FileDownloadStatus>;
|
||||
|
||||
59
src/routes/(fullscreen)/file/[id]/TopBarMenu.svelte
Normal file
59
src/routes/(fullscreen)/file/[id]/TopBarMenu.svelte
Normal file
@@ -0,0 +1,59 @@
|
||||
<script lang="ts">
|
||||
import FileSaver from "file-saver";
|
||||
import type { Component } from "svelte";
|
||||
import type { SvelteHTMLElements } from "svelte/elements";
|
||||
import { fly } from "svelte/transition";
|
||||
import { goto } from "$app/navigation";
|
||||
|
||||
import IconFolderOpen from "~icons/material-symbols/folder-open";
|
||||
import IconCloudDownload from "~icons/material-symbols/cloud-download";
|
||||
|
||||
interface Props {
|
||||
directoryId?: "root" | number;
|
||||
fileBlob?: Blob;
|
||||
filename?: string;
|
||||
isOpen: boolean;
|
||||
}
|
||||
|
||||
let { directoryId, fileBlob, filename, isOpen = $bindable() }: Props = $props();
|
||||
</script>
|
||||
|
||||
<svelte:window onclick={() => (isOpen = false)} />
|
||||
|
||||
{#if isOpen && (directoryId || fileBlob)}
|
||||
<div
|
||||
class="absolute right-2 top-full z-20 space-y-1 rounded-lg bg-white px-1 py-2 shadow-2xl"
|
||||
transition:fly={{ y: -8, duration: 200 }}
|
||||
>
|
||||
<p class="px-3 pt-2 text-sm font-semibold text-gray-600">더보기</p>
|
||||
<div class="flex flex-col">
|
||||
{#snippet menuButton(
|
||||
Icon: Component<SvelteHTMLElements["svg"]>,
|
||||
text: string,
|
||||
onclick: () => void,
|
||||
)}
|
||||
<button {onclick} class="rounded-xl active:bg-gray-100">
|
||||
<div
|
||||
class="flex items-center gap-x-3 px-3 py-2 text-lg text-gray-700 transition active:scale-95"
|
||||
>
|
||||
<Icon />
|
||||
<p class="font-medium">{text}</p>
|
||||
</div>
|
||||
</button>
|
||||
{/snippet}
|
||||
|
||||
{#if directoryId}
|
||||
{@render menuButton(IconFolderOpen, "폴더에서 보기", () =>
|
||||
goto(
|
||||
directoryId === "root" ? "/directory?from=file" : `/directory/${directoryId}?from=file`,
|
||||
),
|
||||
)}
|
||||
{/if}
|
||||
{#if fileBlob}
|
||||
{@render menuButton(IconCloudDownload, "다운로드", () => {
|
||||
FileSaver.saveAs(fileBlob, filename);
|
||||
})}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -1,8 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { get, type Writable } from "svelte/store";
|
||||
import { getFileInfo, type FileInfo } from "$lib/modules/filesystem";
|
||||
import { formatNetworkSpeed } from "$lib/modules/util";
|
||||
import { masterKeyStore, type FileDownloadStatus } from "$lib/stores";
|
||||
import { formatNetworkSpeed } from "$lib/utils";
|
||||
|
||||
import IconCloud from "~icons/material-symbols/cloud";
|
||||
import IconCloudDownload from "~icons/material-symbols/cloud-download";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import type { Writable } from "svelte/store";
|
||||
import { formatNetworkSpeed } from "$lib/modules/util";
|
||||
import type { FileUploadStatus } from "$lib/stores";
|
||||
import { formatNetworkSpeed } from "$lib/utils";
|
||||
|
||||
import IconPending from "~icons/material-symbols/pending";
|
||||
import IconLockClock from "~icons/material-symbols/lock-clock";
|
||||
|
||||
26
src/routes/(fullscreen)/gallery/+page.svelte
Normal file
26
src/routes/(fullscreen)/gallery/+page.svelte
Normal file
@@ -0,0 +1,26 @@
|
||||
<script lang="ts">
|
||||
import type { Writable } from "svelte/store";
|
||||
import { goto } from "$app/navigation";
|
||||
import { FullscreenDiv } 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 { masterKeyStore } from "$lib/stores";
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
let files: Writable<FileInfo | null>[] = $state([]);
|
||||
|
||||
$effect(() => {
|
||||
files = data.files.map((file) => getFileInfo(file, $masterKeyStore?.get(1)?.key!));
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>사진 및 동영상</title>
|
||||
</svelte:head>
|
||||
|
||||
<TopBar title="사진 및 동영상" />
|
||||
<FullscreenDiv>
|
||||
<Gallery {files} onFileClick={({ id }) => goto(`/file/${id}`)} />
|
||||
</FullscreenDiv>
|
||||
7
src/routes/(fullscreen)/gallery/+page.ts
Normal file
7
src/routes/(fullscreen)/gallery/+page.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { trpc } from "$trpc/client";
|
||||
import type { PageLoad } from "./$types";
|
||||
|
||||
export const load: PageLoad = async ({ fetch }) => {
|
||||
const files = await trpc(fetch).file.list.query();
|
||||
return { files };
|
||||
};
|
||||
@@ -6,8 +6,8 @@
|
||||
import type { FileCacheIndex } from "$lib/indexedDB";
|
||||
import { getFileCacheIndex, deleteFileCache as doDeleteFileCache } from "$lib/modules/file";
|
||||
import { getFileInfo, type FileInfo } from "$lib/modules/filesystem";
|
||||
import { formatFileSize } from "$lib/modules/util";
|
||||
import { masterKeyStore } from "$lib/stores";
|
||||
import { formatFileSize } from "$lib/utils";
|
||||
import File from "./File.svelte";
|
||||
|
||||
interface FileCache {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import type { Writable } from "svelte/store";
|
||||
import type { FileCacheIndex } from "$lib/indexedDB";
|
||||
import type { FileInfo } from "$lib/modules/filesystem";
|
||||
import { formatDate, formatFileSize } from "$lib/modules/util";
|
||||
import { formatDate, formatFileSize } from "$lib/utils";
|
||||
|
||||
import IconDraft from "~icons/material-symbols/draft";
|
||||
import IconScanDelete from "~icons/material-symbols/scan-delete";
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { error } from "@sveltejs/kit";
|
||||
import { trpc } from "$trpc/client";
|
||||
import type { PageLoad } from "./$types";
|
||||
|
||||
export const load: PageLoad = async ({ fetch }) => {
|
||||
try {
|
||||
const files = await trpc(fetch).file.listWithoutThumbnail.query();
|
||||
return { files };
|
||||
} catch {
|
||||
// TODO: Error Handling
|
||||
error(500, "Internal server error");
|
||||
}
|
||||
const files = await trpc(fetch).file.listWithoutThumbnail.query();
|
||||
return { files };
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
import { ActionEntryButton } from "$lib/components/atoms";
|
||||
import { DirectoryEntryLabel } from "$lib/components/molecules";
|
||||
import type { FileInfo } from "$lib/modules/filesystem";
|
||||
import { formatDateTime } from "$lib/modules/util";
|
||||
import { formatDateTime } from "$lib/utils";
|
||||
import type { GenerationStatus } from "./service.svelte";
|
||||
|
||||
import IconCamera from "~icons/material-symbols/camera";
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<AdaptiveDiv class="flex justify-evenly px-4 py-2">
|
||||
{#each pages as { path, label, icon: Icon }}
|
||||
<button
|
||||
onclick={() => goto(path)}
|
||||
onclick={() => goto(path, { replaceState: true })}
|
||||
class={[
|
||||
"w-16 active:rounded-xl active:bg-gray-100",
|
||||
!page.url.pathname.startsWith(path) && "text-gray-600",
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
<Category
|
||||
bind:isFileRecursive
|
||||
info={$info}
|
||||
onFileClick={({ id }) => goto(`/file/${id}`)}
|
||||
onFileClick={({ id }) => goto(`/file/${id}?from=category`)}
|
||||
onFileRemoveClick={async ({ id }) => {
|
||||
await requestFileRemovalFromCategory(id, data.id as number);
|
||||
info = getCategoryInfo(data.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { ActionModal } from "$lib/components/molecules";
|
||||
import { truncateString } from "$lib/modules/util";
|
||||
import { truncateString } from "$lib/utils";
|
||||
import { useContext } from "./service.svelte";
|
||||
|
||||
interface Props {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { onMount } from "svelte";
|
||||
import type { Writable } from "svelte/store";
|
||||
import { goto } from "$app/navigation";
|
||||
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";
|
||||
@@ -42,6 +43,9 @@
|
||||
let isEntryRenameModalOpen = $state(false);
|
||||
let isEntryDeleteModalOpen = $state(false);
|
||||
|
||||
let isFromFilePage = $derived(page.url.searchParams.get("from") === "file");
|
||||
let showTopBar = $derived(data.id !== "root" || isFromFilePage);
|
||||
|
||||
const uploadFile = () => {
|
||||
const files = fileInput?.files;
|
||||
if (!files || files.length === 0) return;
|
||||
@@ -86,11 +90,11 @@
|
||||
<input bind:this={fileInput} onchange={uploadFile} type="file" multiple class="hidden" />
|
||||
|
||||
<div class="flex h-full flex-col">
|
||||
{#if data.id !== "root"}
|
||||
{#if showTopBar}
|
||||
<TopBar title={$info?.name} class="flex-shrink-0" />
|
||||
{/if}
|
||||
{#if $info}
|
||||
<div class={["flex flex-grow flex-col px-4 pb-4", data.id === "root" && "pt-4"]}>
|
||||
<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")} />
|
||||
@@ -103,6 +107,13 @@
|
||||
context.selectedEntry = entry;
|
||||
isEntryMenuBottomSheetOpen = true;
|
||||
}}
|
||||
showParentEntry={isFromFilePage && $info.parentId !== undefined}
|
||||
onParentClick={() =>
|
||||
goto(
|
||||
$info.parentId === "root"
|
||||
? "/directory?from=file"
|
||||
: `/directory/${$info.parentId}?from=file`,
|
||||
)}
|
||||
/>
|
||||
{/key}
|
||||
</div>
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<script lang="ts">
|
||||
import { untrack } from "svelte";
|
||||
import { get, type Writable } from "svelte/store";
|
||||
import { ActionEntryButton } from "$lib/components/atoms";
|
||||
import { DirectoryEntryLabel } from "$lib/components/molecules";
|
||||
import {
|
||||
getDirectoryInfo,
|
||||
getFileInfo,
|
||||
type DirectoryInfo,
|
||||
type FileInfo,
|
||||
} from "$lib/modules/filesystem";
|
||||
import { SortBy, sortEntries } from "$lib/modules/util";
|
||||
import {
|
||||
fileUploadStatusStore,
|
||||
isFileUploading,
|
||||
masterKeyStore,
|
||||
type FileUploadStatus,
|
||||
} from "$lib/stores";
|
||||
import { SortBy, sortEntries } from "$lib/utils";
|
||||
import File from "./File.svelte";
|
||||
import SubDirectory from "./SubDirectory.svelte";
|
||||
import UploadingFile from "./UploadingFile.svelte";
|
||||
@@ -23,10 +25,19 @@
|
||||
info: DirectoryInfo;
|
||||
onEntryClick: (entry: SelectedEntry) => void;
|
||||
onEntryMenuClick: (entry: SelectedEntry) => void;
|
||||
onParentClick?: () => void;
|
||||
showParentEntry?: boolean;
|
||||
sortBy?: SortBy;
|
||||
}
|
||||
|
||||
let { info, onEntryClick, onEntryMenuClick, sortBy = SortBy.NAME_ASC }: Props = $props();
|
||||
let {
|
||||
info,
|
||||
onEntryClick,
|
||||
onEntryMenuClick,
|
||||
onParentClick,
|
||||
showParentEntry = false,
|
||||
sortBy = SortBy.NAME_ASC,
|
||||
}: Props = $props();
|
||||
|
||||
interface DirectoryEntry {
|
||||
name?: string;
|
||||
@@ -106,8 +117,13 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if subDirectories.length + files.length > 0}
|
||||
{#if subDirectories.length + files.length > 0 || showParentEntry}
|
||||
<div class="space-y-1 pb-[4.5rem]">
|
||||
{#if showParentEntry}
|
||||
<ActionEntryButton class="h-14" onclick={onParentClick}>
|
||||
<DirectoryEntryLabel type="parent-directory" name=".." />
|
||||
</ActionEntryButton>
|
||||
{/if}
|
||||
{#each subDirectories as { info }}
|
||||
<SubDirectory {info} onclick={onEntryClick} onOpenMenuClick={onEntryMenuClick} />
|
||||
{/each}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { ActionEntryButton } from "$lib/components/atoms";
|
||||
import { DirectoryEntryLabel } from "$lib/components/molecules";
|
||||
import type { FileInfo } from "$lib/modules/filesystem";
|
||||
import { formatDateTime } from "$lib/modules/util";
|
||||
import { formatDateTime } from "$lib/utils";
|
||||
import { requestFileThumbnailDownload } from "./service";
|
||||
import type { SelectedEntry } from "../service.svelte";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import type { Writable } from "svelte/store";
|
||||
import { formatNetworkSpeed } from "$lib/modules/util";
|
||||
import { isFileUploading, type FileUploadStatus } from "$lib/stores";
|
||||
import { formatNetworkSpeed } from "$lib/utils";
|
||||
|
||||
import IconDraft from "~icons/material-symbols/draft";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { ActionModal } from "$lib/components/molecules";
|
||||
import { truncateString } from "$lib/modules/util";
|
||||
import { truncateString } from "$lib/utils";
|
||||
|
||||
interface Props {
|
||||
file: File | undefined;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { ActionModal } from "$lib/components/molecules";
|
||||
import { truncateString } from "$lib/modules/util";
|
||||
import { truncateString } from "$lib/utils";
|
||||
import { useContext } from "./service.svelte";
|
||||
|
||||
interface Props {
|
||||
|
||||
@@ -1,3 +1,35 @@
|
||||
<div class="flex h-full items-center justify-center p-4">
|
||||
<p class="text-gray-500">아직 개발 중이에요.</p>
|
||||
<script lang="ts">
|
||||
import type { Writable } from "svelte/store";
|
||||
import { goto } from "$app/navigation";
|
||||
import { EntryButton } from "$lib/components/atoms";
|
||||
import { FileThumbnailButton } from "$lib/components/molecules";
|
||||
import { getFileInfo, type FileInfo } from "$lib/modules/filesystem";
|
||||
import { masterKeyStore } from "$lib/stores";
|
||||
import { requestFreshMediaFilesRetrieval } from "./service";
|
||||
|
||||
let mediaFiles: Writable<FileInfo | null>[] = $state([]);
|
||||
|
||||
$effect(() => {
|
||||
requestFreshMediaFilesRetrieval().then((files) => {
|
||||
mediaFiles = files.map(({ id }) => getFileInfo(id, $masterKeyStore?.get(1)?.key!));
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>홈</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="min-h-full space-y-4 bg-gray-100 px-4 pb-[5.5em] pt-4">
|
||||
<p class="px-2 text-2xl font-bold text-gray-800">ArkVault</p>
|
||||
<div class="space-y-2 rounded-xl bg-white px-2 pb-4 pt-2">
|
||||
<EntryButton onclick={() => goto("/gallery")} class="w-full">
|
||||
<p class="text-left font-semibold">사진 및 동영상</p>
|
||||
</EntryButton>
|
||||
<div class="grid grid-cols-4 gap-2 px-2">
|
||||
{#each mediaFiles as file}
|
||||
<FileThumbnailButton info={file} onclick={({ id }) => goto(`/file/${id}`)} />
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
14
src/routes/(main)/home/service.ts
Normal file
14
src/routes/(main)/home/service.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { getAllFileInfos } from "$lib/indexedDB";
|
||||
|
||||
export const requestFreshMediaFilesRetrieval = async (limit = 8) => {
|
||||
const files = await getAllFileInfos();
|
||||
files.sort(
|
||||
(a, b) =>
|
||||
(b.createdAt ?? b.lastModifiedAt).getTime() - (a.createdAt ?? a.lastModifiedAt).getTime(),
|
||||
);
|
||||
return files
|
||||
.filter(
|
||||
({ contentType }) => contentType.startsWith("image/") || contentType.startsWith("video/"),
|
||||
)
|
||||
.slice(0, limit);
|
||||
};
|
||||
@@ -1,13 +1,7 @@
|
||||
import { error } from "@sveltejs/kit";
|
||||
import { trpc } from "$trpc/client";
|
||||
import type { PageLoad } from "./$types";
|
||||
|
||||
export const load: PageLoad = async ({ fetch }) => {
|
||||
try {
|
||||
const { nickname } = await trpc(fetch).user.get.query();
|
||||
return { nickname };
|
||||
} catch {
|
||||
// TODO: Error Handling
|
||||
error(500, "Internal server error");
|
||||
}
|
||||
const { nickname } = await trpc(fetch).user.get.query();
|
||||
return { nickname };
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ const createClient = (fetch: typeof globalThis.fetch) =>
|
||||
links: [
|
||||
httpBatchLink({
|
||||
url: "/api/trpc",
|
||||
maxURLLength: 4096,
|
||||
transformer: superjson,
|
||||
fetch,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user