diff --git a/cmd/files.ts b/cmd/files.ts index 5a58e94..1e0fbf7 100644 --- a/cmd/files.ts +++ b/cmd/files.ts @@ -16,11 +16,12 @@ export const data = new SlashCommandBuilder() ); export async function renderList(user: User, userId: string, page: number): Promise { - const amount = 4; + const amount = 3; const { count } = await db.get<{ count: number }>` SELECT COUNT(*) as count FROM files WHERE owner = ${userId} `; + const totalPages = Math.max(1, Math.ceil(count / amount)); const pages = Math.max(1, Math.min(page, totalPages)); @@ -37,12 +38,16 @@ export async function renderList(user: User, userId: string, page: number): Prom const embed = createEmbed(user) .setTitle("your files") .addFields(...files.map(file => ({ - name: file.name, + name: `\`${file.name}\``, value: `${formatSize(file.size)}\n${new Date(file.created_at).toLocaleString()}\n[open in browser](${process.env.API}/${file.id})`, inline: true }))) .setFooter({ text: `page ${pages} of ${totalPages}` }); + if (totalPages <= 1) { + return { embeds: [embed] } + } + const row = new ActionRowBuilder() .addComponents( new ButtonBuilder()