diff --git a/src/lib/components/admin/Pagination.svelte b/src/lib/components/admin/Pagination.svelte
new file mode 100644
index 0000000..5c25aa4
--- /dev/null
+++ b/src/lib/components/admin/Pagination.svelte
@@ -0,0 +1,60 @@
+
+
+{#if totalPages > 1}
+
+{/if}
+
+
diff --git a/src/routes/admin/files/+page.server.ts b/src/routes/admin/files/+page.server.ts
index 1680a84..8aa78bc 100644
--- a/src/routes/admin/files/+page.server.ts
+++ b/src/routes/admin/files/+page.server.ts
@@ -11,30 +11,49 @@ type Attachment = {
created_at: string;
};
-export const load: PageServerLoad = async ({ platform }) => {
+export const load: PageServerLoad = async ({ url, platform }) => {
const db = platform?.env.DB;
- if (!db) return { files: [], r2Domain: '' };
+ if (!db)
+ return { files: [], pagination: { page: 1, totalPages: 0, totalItems: 0 }, r2Domain: '' };
+
+ const page = Number(url.searchParams.get('page')) || 1;
+ const limit = 24;
+ const offset = (page - 1) * limit;
try {
const domainResult = await db
.prepare('SELECT value FROM settings WHERE key = ?')
.bind('r2.public_domain')
.first<{ value: string }>();
+
+ const countResult = await db
+ .prepare('SELECT COUNT(*) as count FROM attachments')
+ .first<{ count: number }>();
+ const totalItems = countResult?.count || 0;
+ const totalPages = Math.ceil(totalItems / limit);
+
const { results } = await db
.prepare(
`SELECT id, filename, key, mime_type, size, created_at
FROM attachments
- ORDER BY created_at DESC`
+ ORDER BY created_at DESC
+ LIMIT ? OFFSET ?`
)
+ .bind(limit, offset)
.all();
return {
files: results,
+ pagination: { page, totalPages, totalItems },
r2Domain: domainResult?.value || 'https://assets.yourdomain.com'
};
} catch (cause) {
console.error('Error fetching attachments:', cause);
- return { files: [], r2Domain: 'https://assets.yourdomain.com' };
+ return {
+ files: [],
+ pagination: { page: 1, totalPages: 0, totalItems: 0 },
+ r2Domain: 'https://assets.yourdomain.com'
+ };
}
};
diff --git a/src/routes/admin/files/+page.svelte b/src/routes/admin/files/+page.svelte
index ecc5fb3..348b198 100644
--- a/src/routes/admin/files/+page.svelte
+++ b/src/routes/admin/files/+page.svelte
@@ -7,6 +7,7 @@
import { addToast } from '$lib/stores/toast.svelte';
import { confirmState } from '$lib/stores/confirm.svelte';
import { prepareUpload } from '$lib/uploads';
+ import Pagination from '$lib/components/admin/Pagination.svelte';
let { data, form } = $props<{ data: PageData; form: ActionData }>();
@@ -213,6 +214,12 @@
{/if}
+
+