diff --git a/src/assets/views/url-shrinker.njk b/src/assets/views/url-shrinker.njk
deleted file mode 100644
index 83e520b..0000000
--- a/src/assets/views/url-shrinker.njk
+++ /dev/null
@@ -1,75 +0,0 @@
-{% extends 'layouts' %}
-
-{% set title = app.name + ' - Shrink URL' %}
-
-{% block scripts %}
-
-{% endblock %}
-
-{% block body %}
-
Shrink URLs
- For security reasons, shrinked URLs cannot be deleted.
-
-
-
- Shrink a URL
-
-
-
- {% set url = flash('url') %}
- {% if url | length %}
-
- {% endif %}
-
-
-
-
- URL list
-
- {{ macros.paginate(urls.pagination, 'url-shrinker', 3) }}
-
-
-
-
- # |
- Target |
- Actions |
-
-
-
-
- {% for url in urls %}
-
- {{ url.id }} |
- {{ url.target_url }} |
-
-
-
-
- |
-
- {% else %}
-
- You haven't shrunk any url yet. |
-
- {% endfor %}
-
-
-
- {{ macros.paginate(urls.pagination, 'url-shrinker', 3) }}
-
-
-{% endblock %}
diff --git a/src/assets/views/url-shrinker.svelte b/src/assets/views/url-shrinker.svelte
new file mode 100644
index 0000000..908f005
--- /dev/null
+++ b/src/assets/views/url-shrinker.svelte
@@ -0,0 +1,83 @@
+
+
+
+ Shrink URLs
+
+
+
+
+ Shrink a URL
+
+ For security reasons, shrinked URLs cannot be deleted.
+
+
+
+ {#if $locals.flash.url}
+
+ {/if}
+
+
+
+
+
+
+ URL list
+
+
+
+
+
+
+
+ # |
+ Target |
+ Actions |
+
+
+
+
+ {#each $locals.urls as url}
+
+ {url.id} |
+
+
+ {url.target_url}
+
+ |
+
+
+ |
+
+ {:else}
+
+ You haven't shrunk any url yet. |
+
+ {/each}
+
+
+
+
+
+
diff --git a/src/controllers/URLRedirectController.ts b/src/controllers/URLRedirectController.ts
index 5552adb..766360d 100644
--- a/src/controllers/URLRedirectController.ts
+++ b/src/controllers/URLRedirectController.ts
@@ -18,10 +18,15 @@ export default class URLRedirectController extends Controller {
protected async getUrlShrinker(req: Request, res: Response): Promise {
const user = req.as(RequireAuthMiddleware).getUser();
const allowedDomains = config.get('allowed_url_domains');
+ const urls = await URLRedirect.paginateForUser(req, 25, user.getOrFail('id'));
res.render('url-shrinker', {
allowed_domains: allowedDomains,
default_domain: allowedDomains[config.get('default_url_domain_for_urls')],
- urls: await URLRedirect.paginateForUser(req, 25, user.getOrFail('id')),
+ urls: urls.map(url => ({
+ ...url,
+ url: url.getURL(),
+ })),
+ pagination: urls.pagination?.serialize(),
});
}
diff --git a/src/models/URLRedirect.ts b/src/models/URLRedirect.ts
index acf06a8..e6e343e 100644
--- a/src/models/URLRedirect.ts
+++ b/src/models/URLRedirect.ts
@@ -3,6 +3,7 @@ import {Request} from "express";
import User from "swaf/auth/models/User";
import {route} from "swaf/common/Routing";
import Model from "swaf/db/Model";
+import {ModelQueryResult} from "swaf/db/ModelQuery";
import FileModel from "./FileModel.js";
@@ -15,7 +16,11 @@ export default class URLRedirect extends Model {
return await this.select().where('slug', slug).first();
}
- public static async paginateForUser(req: Request, perPage: number, user_id: number): Promise {
+ public static async paginateForUser(
+ req: Request,
+ perPage: number,
+ user_id: number,
+ ): Promise> {
req.params.sortBy = 'created_at';
req.params.sortDirection = 'DESC';
return await this.paginate(req, perPage, this.select().where('user_id', user_id));