Skip to content

Commit

Permalink
v.0.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
urania-dev committed Aug 19, 2024
1 parent 6b49302 commit 9846e7b
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 36 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,7 @@
- 0.8.3
- Restored Forgotten Umami Integration in settings, added to .env.example
- Restore QRCode Creation and download
- Fixed some minor UI Issues
- Fixed some minor UI Issues
- 0.8.4
- Re-added snapp select and bulk delete
- Fixed some inconsistencies during import, now it import creation date and visits
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]

ENV APPNAME="Snapp.li"
ENV PUBLIC_SNAPP_VERSION="0.8.3"
ENV PUBLIC_SNAPP_VERSION="0.8.4"
# Expose the port the app runs on
EXPOSE 3000

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "snapp",
"version": "0.8.3",
"version": "0.8.4",
"private": true,
"scripts": {
"dev": "vite dev",
Expand Down
1 change: 1 addition & 0 deletions src/lib/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"cancel": "Abbrechen",
"sure-ask": "Sind Sie sicher?",
"continue": "Weiter",
"delete": "Löschen",
"total": "Gesamt",
"max-page-reached": "Keine weiteren Elemente verfügbar.",
"save": "Speichern",
Expand Down
1 change: 1 addition & 0 deletions src/lib/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"cancel": "Cancel",
"sure-ask": "Are you sure?",
"continue": "Continue",
"delete": "Delete",
"total": "Total",
"max-page-reached": "No more items available.",
"save": "Save",
Expand Down
1 change: 1 addition & 0 deletions src/lib/i18n/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"total": "Total",
"max-page-reached": "No hay más elementos disponibles.",
"save": "Guardar",
"delete": "Eliminar",
"active": "Activo",
"disabled": "Desactivado",
"back": "Volver",
Expand Down
1 change: 1 addition & 0 deletions src/lib/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"cancel": "Annuler",
"sure-ask": "Êtes-vous sûr ?",
"continue": "Continuer",
"delete":"Suprrimer",
"total": "Total",
"max-page-reached": "Plus d'articles disponibles.",
"save": "Enregistrer",
Expand Down
1 change: 1 addition & 0 deletions src/lib/i18n/locales/gl.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
"sure-ask": "¿Estás seguro?",
"continue": "Continuar",
"total": "Total",
"delete": "Eliminar",
"max-page-reached": "Non hai máis elementos dispoñibles.",
"save": "Gardar",
"active": "Activo",
Expand Down
1 change: 1 addition & 0 deletions src/lib/i18n/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"save": "Salva",
"active": "Attivo",
"disabled": "Disabilitato",
"delete": "Elimina",
"back": "Indietro",
"start": "Inizio",
"end": "Fine",
Expand Down
18 changes: 10 additions & 8 deletions src/lib/server/db/snapps/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const create_snapp = async (snapp: Partial<Snapp>, userId: string, fetch:
if (api_limited && count >= max_snapps) return [null, MAX_SNAPPS_PER_USER] as [null, string];
}

let { original_url, shortcode, notes, secret, expiration, max_usages } = snapp;
let { original_url, hit, shortcode, created, notes, secret, expiration, max_usages } = snapp;

if (!original_url || typeof original_url !== 'string' || original_url.trim() === '')
return [null, SNAPP_ORIGIN_URL_REQUESTED] as [null, string];
Expand All @@ -44,12 +44,12 @@ export const create_snapp = async (snapp: Partial<Snapp>, userId: string, fetch:
const exists = await prisma.snapp.count({ where: { shortcode: { startsWith: shortcode } } });
const password_hash = secret
? await hash(secret, {
// recommended minimum parameters
memoryCost: 19456,
timeCost: 2,
outputLen: 32,
parallelism: 1
})
// recommended minimum parameters
memoryCost: 19456,
timeCost: 2,
outputLen: 32,
parallelism: 1
})
: null;

const new_snapp = await prisma.snapp.create({
Expand All @@ -60,7 +60,9 @@ export const create_snapp = async (snapp: Partial<Snapp>, userId: string, fetch:
notes,
secret: password_hash,
expiration,
max_usages
max_usages,
created,
hit
}
});

Expand Down
1 change: 0 additions & 1 deletion src/lib/server/mark-usage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ async function markUsage(
snapp: Snapp,
request: Request,
url: URL,
eventData: any = null,
fetch: SvelteFetch
) {
const headers = Object.fromEntries(request.headers);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ui/icon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
css
}: {
ph: string;
style?: 'regular' | 'bold' | 'thin' | 'duotone';
style?: 'regular' | 'bold' | 'thin' | 'duotone'|'fill';
size?: number;
css?: { [key: string]: string };
} = $props();
Expand Down
4 changes: 2 additions & 2 deletions src/routes/[shortcode]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const load = async ({
const data = await parent();
if (secret === null) {
if (user === null || (user && user.id !== redirection.userId))
await markUsage(redirection, request, url, null, fetch);
await markUsage(redirection, request, url, fetch);
throw redirect(302, redirection.original_url);
} else return { ...data, shortcode, has_secret: true };
} else error(404, { message: 'errors.snapps.not-found' });
Expand Down Expand Up @@ -58,7 +58,7 @@ export const actions = {
});

if (validPassword) {
if (!user || user.id !== snapp.userId) await markUsage(snapp, request, url, null, fetch);
if (!user || user.id !== snapp.userId) await markUsage(snapp, request, url, fetch);
return { url: snapp.original_url };
} else
return fail(401, {
Expand Down
18 changes: 17 additions & 1 deletion src/routes/dashboard/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,28 @@ export const actions = {

const [count, err] = await database.snapps.delete(user.id, id);
let message: string | undefined = undefined;
if (err === SNAPP_NOT_FOUND) message = 'errors.snapps.max-snapps';
if (err === SNAPP_NOT_FOUND) message = 'errors.snapps.not-found';
if (err === UNAUTHORIZED) message = 'errors.unauthorized';
if (message) return fail(400, { message });

return { message: 'snapps.actions.deleted', success: true };
},
'delete-all': async ({ locals: { session, user }, request, fetch }) => {
if (!session || !user) redirect(302, '/');

const form = await request.formData();
const ids = form.get('ids')?.toString() && JSON.parse(form.get('ids')!.toString());
for (let id of ids) {
let message: string | undefined = undefined;
const [count, err] = await database.snapps.delete(user.id, id);
console.log(id)
if (err === SNAPP_NOT_FOUND) message = 'errors.snapps.not-found';
if (err === UNAUTHORIZED) message = 'errors.unauthorized';
if (message) return fail(400, { message });
}

return { message: 'snapps.actions.deleted', success: true };
},

'save-cols': async ({ locals: { session, user }, request }) => {
if (!session || !user) redirect(302, '/');
Expand Down
110 changes: 97 additions & 13 deletions src/routes/dashboard/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import { queryParam } from 'sveltekit-search-params';
import { page } from '$app/stores';
let { data, form } = $props();
let snapp_action = $state<'create' | 'edit' | 'delete'>();
let snapp_action = $state<'create' | 'edit' | 'delete' | 'delete-all'>();
let show_snapp_panel = $state(false);
let show_secret = $state(false);
Expand Down Expand Up @@ -140,6 +140,16 @@
if (idx) document.forms.namedItem(idx)?.requestSubmit();
};
const enhanceDeleteAction: SubmitFunction = ({ formData, cancel }) => {
if (!selected.length) return cancel();
formData.set('ids', JSON.stringify(selected));
return async ({ result }) => {
await applyAction(result);
await invalidateAll();
if (form?.message) toast.info($_(form.message));
if (form?.success === true) close_and_reset_panel();
};
};
const enhanceSnappAction: SubmitFunction = ({ formData, cancel }) => {
if (ttl) _snapp.expiration = new Date(new Date().getTime() + ttl * 1000);
if (_snapp) formData.set('snapp', JSON.stringify(_snapp));
Expand Down Expand Up @@ -170,6 +180,7 @@
has_expiration = false;
has_limited_usage = false;
_snapp = snapp_initial_value;
selected = [];
};
const open_edit_panel: MouseEventHandler<HTMLButtonElement> = (e) => {
Expand Down Expand Up @@ -272,6 +283,26 @@
};
let limitValue = $state<number>(data.limit);
let original_url_field = $state<HTMLInputElement>();
let selected = $state<string[]>([]);
const handle_select_this: MouseEventHandler<HTMLButtonElement> = (e) => {
const idx = e.currentTarget.dataset.idx;
if (!idx) return;
if (idx === 'all') {
if (selected.length === data.snapps.length) {
selected.splice(0, selected.length);
} else {
selected = [];
for (let snapp of data.snapps) {
selected.push(snapp.id);
}
}
} else if (selected.includes(idx)) {
const index = selected.findIndex((i) => i === idx);
selected.splice(index, 1);
} else selected.push(idx);
};
</script>

<svelte:window bind:innerWidth />
Expand All @@ -290,6 +321,13 @@
use:enhance={enhanceSaveColumn}
method="post"
></form>
<form
action="?/delete-all"
id="delete-all"
hidden
use:enhance={enhanceDeleteAction}
method="post"
></form>
<form action="?/delete" id="delete" hidden use:enhance={enhanceSnappAction} method="post"></form>
<form action="?/create" id="create" hidden use:enhance={enhanceSnappAction} method="post"></form>
<form action="?/edit" id="edit" hidden use:enhance={enhanceSnappAction} method="post"></form>
Expand Down Expand Up @@ -339,17 +377,32 @@
<div class="flex flex-col w-full items-center gap-4">
<Card css={{ card: 'md:flex-row justify-between gap-4 p-2' }}>
<h4 class="whitespace-nowrap ps-2 text-lg font-semibold">{$_('snapps.label')}</h4>
<button
onclick={(e) => {
e.stopPropagation();
show_snapp_panel = true;
snapp_action = 'create';
}}
class="flex h-12 w-full items-center gap-2 rounded border border-slate-500/50 p-0 px-4 text-sm font-semibold transition-all hover:bg-slate-500 hover:text-neutral-50 md:h-8 md:w-max md:justify-center lg:px-2"
>
<Icon ph="plus" />
<small class="text-sm ps-3 leading-none md:p-0">{$_('snapps.labels.create')}</small>
</button>
{#if !selected.length}
<button
in:fade
onclick={(e) => {
e.stopPropagation();
show_snapp_panel = true;
snapp_action = 'create';
}}
class="flex h-12 w-full items-center gap-2 rounded border border-slate-500/50 p-0 px-4 text-sm font-semibold transition-all hover:bg-slate-500 hover:text-neutral-50 md:h-8 md:w-max md:justify-center lg:px-2"
>
<Icon ph="plus" />
<small class="text-sm ps-3 leading-none md:p-0">{$_('snapps.labels.create')}</small>
</button>{:else}
<button
in:fade
onclick={(e) => {
e.stopPropagation();
show_confirm_panel = true;
snapp_action = 'delete-all';
}}
class="flex h-12 w-full items-center gap-2 rounded border border-red-500/50 p-0 px-4 text-sm font-semibold transition-all hover:bg-red-500/25 hover:text-neutral-50 md:h-8 md:w-max md:justify-center lg:px-2"
>
<Icon ph="trash" />
<small class="text-sm ps-3 leading-none md:p-0">{$_('globals.delete')}</small>
</button>
{/if}
</Card>
</div>
<Card
Expand All @@ -361,6 +414,21 @@
<table class="w-full table-auto text-sm">
<thead>
<tr class="table-row h-10">
<th class="px-2 table-cell" style:width="1.5rem">
<button
class="flex h-5 w-5 items-center justify-center rounded border border-slate-500/50 bg-neutral-50 dark:bg-neutral-950"
onclick={handle_select_this}
data-idx="all"
>
{#if selected.length === data.snapps.length}
<Icon ph="check" size={14} />
{:else if selected.length === 0}
&nbsp;
{:else}
<Icon ph="circle" size={4} style="fill" />
{/if}
</button>
</th>
{#if columns.includes('original_url')}
<th class="table-cell px-2">
<button
Expand Down Expand Up @@ -533,6 +601,19 @@
<tr
class="h-14 w-full border border-slate-500/25 bg-slate-500/5 p-4 transition-all hover:bg-slate-500/15 md:h-12"
>
<th class="px-2 table-cell" style:width="1.5rem">
<button
class="flex h-5 w-5 items-center justify-center rounded border border-slate-500/50 bg-neutral-50 dark:bg-neutral-950"
onclick={handle_select_this}
data-idx={snapp.id}
>
{#if selected.includes(snapp.id)}
<Icon ph="check" size={14} />
{:else}
&nbsp;
{/if}
</button>
</th>
{#if columns.includes('original_url')}
<td
class="table-cell w-52 max-w-52 overflow-hidden text-ellipsis whitespace-nowrap px-2 align-middle"
Expand Down Expand Up @@ -653,6 +734,9 @@
class="h-14 w-full border border-slate-500/25 bg-slate-500/5 p-4 transition-all hover:bg-slate-500/15 md:h-10"
>
{#key columns.length}
<td class="table-cell whitespace-nowrap px-2 text-center align-middle"
>&nbsp;</td
>
{#each { length: columns.length + 1 } as _, idx}
<td class="table-cell whitespace-nowrap px-2 text-center align-middle"
>&nbsp;</td
Expand Down Expand Up @@ -1069,7 +1153,7 @@
</small>
</button>
<button
data-idx="delete"
data-idx={snapp_action}
onclick={handle_save}
class="flex h-8 w-full items-center justify-center gap-2 rounded border-none bg-red-500/25 outline-none transition-all hover:bg-red-500/50 focus:bg-red-500/50"
><Icon ph="trash" size={16} /><small class="pt-0.5 font-semibold">
Expand Down
2 changes: 1 addition & 1 deletion src/routes/settings/import/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const actions = {
const snapps = JSON.parse(snapp_string) as Partial<Snapp>[];

for (let snapp of snapps) {
if (!snapp.original_url) return fail(400, { message: 'errors.snapps.orginal-url-missing' });
if (!snapp.original_url) return fail(400, { message: 'errors.snapps.original-url-missing' });
const [, err] = await database.snapps.create({ ...snapp }, user.id, fetch);
if (err) return fail(400, { message: 'migrations.failed' });
}
Expand Down
15 changes: 9 additions & 6 deletions src/routes/settings/import/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@
});
if (old_snapps.data.length)
import_list = old_snapps.data.map((snapp) => ({
userId: data.user.id,
shortcode: snapp.shortcode,
original_url: snapp.original_url,
created: snapp.created
}));
import_list = old_snapps.data
.filter((snapp) => snapp.original_url && snapp.original_url?.trim() !== '')
.map((snapp) => ({
userId: data.user.id,
shortcode: snapp.shortcode,
original_url: snapp.original_url,
created: snapp.created,
hit: snapp.used
}));
}
function getRelativeDate(date: Date) {
Expand Down

0 comments on commit 9846e7b

Please sign in to comment.