From 6ae22b7a9cd108edf54f5f62b600b041632e14cb Mon Sep 17 00:00:00 2001 From: Luca Bosin Date: Fri, 18 Aug 2023 20:47:03 +0200 Subject: [PATCH] Add attributes for demonstation purposes --- .vscode/tasks.json | 30 ++++++++++++++ README.md | 39 ++----------------- src/lib/components/Gallery.svelte | 9 +++-- src/lib/types.d.ts | 3 +- src/routes/+layout.svelte | 9 +++++ src/routes/g/[slug]/[[timestamp]]/+page.js | 10 ++--- .../g/[slug]/[[timestamp]]/+page.svelte | 6 +++ src/routes/g/[slug]/[[timestamp]]/--layout.js | 29 -------------- .../[slug]/[[timestamp]]/i/[...item]/+page.js | 8 +++- .../[[timestamp]]/i/[...item]/+page.svelte | 15 ++++++- .../i/[...item]/t/[[width]]/+server.js | 6 +-- src/routes/g/[slug]/[[timestamp]]/o/+page.js | 20 ---------- .../g/[slug]/[[timestamp]]/o/+page.svelte | 13 ------- .../[[timestamp]]/{zip => random}/+server.js | 0 14 files changed, 84 insertions(+), 113 deletions(-) create mode 100644 .vscode/tasks.json create mode 100644 src/routes/+layout.svelte delete mode 100644 src/routes/g/[slug]/[[timestamp]]/--layout.js delete mode 100644 src/routes/g/[slug]/[[timestamp]]/o/+page.js delete mode 100644 src/routes/g/[slug]/[[timestamp]]/o/+page.svelte rename src/routes/g/[slug]/[[timestamp]]/{zip => random}/+server.js (100%) diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..3702941 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,30 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Build & Deploy", + "type": "shell", + "command": "npm run build && rsync -arzP --progress --delete-after --force --update --inplace --times ./build ./package.json ./package-lock.json root@f.bosin.ch:/home/sveltekit" + }, + { + "label": "Restart Server", + "type": "shell", + "command": "ssh f.bosin.ch systemctl restart bosin-files" + }, + { + "label": "Full Deploy", + "dependsOn": [ + "Build & Deploy" + ], + "type": "shell", + "command": "ssh f.bosin.ch systemctl restart bosin-files", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 5c91169..fb90cf6 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,5 @@ -# create-svelte +# f.bosin.ch/g -Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte). +Die neue Fotogalerie von Luca Bosin. -## Creating a project - -If you're seeing this, you've probably already done this step. Congrats! - -```bash -# create a new project in the current directory -npm create svelte@latest - -# create a new project in my-app -npm create svelte@latest my-app -``` - -## Developing - -Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: - -```bash -npm run dev - -# or start the server and open the app in a new browser tab -npm run dev -- --open -``` - -## Building - -To create a production version of your app: - -```bash -npm run build -``` - -You can preview the production build with `npm run preview`. - -> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. +Jetzt testen, auf [f.bosin.ch/g/test](https://f.bosin.ch/g/test). diff --git a/src/lib/components/Gallery.svelte b/src/lib/components/Gallery.svelte index 7d4d032..66fe61c 100644 --- a/src/lib/components/Gallery.svelte +++ b/src/lib/components/Gallery.svelte @@ -1,4 +1,5 @@
+

+ Description: {#if data.album.description}{$strf(data.album.description)}{:else}no description{/if}
+ Authors: {#if data.album.authors}{Array.isArray(data.album.authors) ? data.album.authors.join(', ') : data.album.authors}{:else}unknown author{/if}
+ Sorting Date: {data.album.date}
+ License: {data.album.license}
+

diff --git a/src/routes/g/[slug]/[[timestamp]]/--layout.js b/src/routes/g/[slug]/[[timestamp]]/--layout.js deleted file mode 100644 index bbfef8f..0000000 --- a/src/routes/g/[slug]/[[timestamp]]/--layout.js +++ /dev/null @@ -1,29 +0,0 @@ -import { error } from '@sveltejs/kit'; -import StreamZip from 'node-stream-zip'; - -/** @type {import('./$types').LayoutLoad} */ -export async function load({ params }) { - const { slug, timestamp } = params; - const cslug = slug.replace(/[^\w-]/gi, ''); - const ctimestamp = timestamp?.replace(/[^\w-]/gi, ''); - - const file = `./zip/${cslug}${ctimestamp ? '-' + ctimestamp :''}.zip`; - let entries = null; - try { - const zip = new StreamZip.async({ file }); - entries = await zip.entries(); - await zip.close(); - } catch (err) { - console.error(err); - throw error(404, 'Not found'); - } - - console.log(`REQ: ${cslug}/${ctimestamp} @ ${file} with ${entries.length} entries:\n ${JSON.stringify(entries)}`); - - return { - file, - cslug, - ctimestamp, - entries - }; -} diff --git a/src/routes/g/[slug]/[[timestamp]]/i/[...item]/+page.js b/src/routes/g/[slug]/[[timestamp]]/i/[...item]/+page.js index e49ccc5..bc30add 100644 --- a/src/routes/g/[slug]/[[timestamp]]/i/[...item]/+page.js +++ b/src/routes/g/[slug]/[[timestamp]]/i/[...item]/+page.js @@ -1,8 +1,14 @@ -import { getFileName } from '$lib/util/links.js'; +import { getMetadata } from '$lib/util/album'; +import { getFileName, getFilePath, getZipName } from '$lib/util/links.js'; /** @type {import('./$types').PageLoad} */ export async function load({ params }) { + const album = await getMetadata(getZipName(params)); + const filePath = getFilePath(params.item); + const item = album.items.find(item => item.item === filePath); + return { + item, filename: getFileName(params.item) } }; diff --git a/src/routes/g/[slug]/[[timestamp]]/i/[...item]/+page.svelte b/src/routes/g/[slug]/[[timestamp]]/i/[...item]/+page.svelte index 1656d36..f67ca84 100644 --- a/src/routes/g/[slug]/[[timestamp]]/i/[...item]/+page.svelte +++ b/src/routes/g/[slug]/[[timestamp]]/i/[...item]/+page.svelte @@ -1,6 +1,19 @@ - \ No newline at end of file +{#if data.item} +{(data.item.title +{:else} +

Item not found.

+{/if} + + diff --git a/src/routes/g/[slug]/[[timestamp]]/i/[...item]/t/[[width]]/+server.js b/src/routes/g/[slug]/[[timestamp]]/i/[...item]/t/[[width]]/+server.js index 1e3b537..2f51e17 100644 --- a/src/routes/g/[slug]/[[timestamp]]/i/[...item]/t/[[width]]/+server.js +++ b/src/routes/g/[slug]/[[timestamp]]/i/[...item]/t/[[width]]/+server.js @@ -1,14 +1,14 @@ import { getFile } from '$lib/util/album'; -import { getFilePath, getZipName } from '$lib/util/links'; +import { getFileName, getFilePath, getZipName } from '$lib/util/links'; import sharp from 'sharp'; /** @type {import('./$types').RequestHandler} */ export async function GET({ params }) { let thumbnail = null; console.log(`Getting thumbnail for ${params}`); + let width = 400; try { const content = await getFile(getZipName(params), getFilePath(params.item)); - let width = 400; if (params.width) { if (params.width === 'full') { thumbnail = await sharp(content).webp({ quality: 90 }).toBuffer(); @@ -29,7 +29,7 @@ export async function GET({ params }) { return new Response(thumbnail, { headers: { 'Content-Type': 'image/webp', - 'Content-Disposition': 'inline' + 'Content-Disposition': `inline; filename="${getFileName(params.item)}-thumb-${params.width === 'full' ? 'full' : width}.webp"`, } }); } diff --git a/src/routes/g/[slug]/[[timestamp]]/o/+page.js b/src/routes/g/[slug]/[[timestamp]]/o/+page.js deleted file mode 100644 index 76c2c06..0000000 --- a/src/routes/g/[slug]/[[timestamp]]/o/+page.js +++ /dev/null @@ -1,20 +0,0 @@ -import { error } from '@sveltejs/kit'; -import StreamZip from 'node-stream-zip'; - -/** @type {import('./$types').PageLoad} */ -export async function load({ params }) { - let entries = null; - try { - const zip = new StreamZip.async({ file: `./zip/${params.slug}.zip` }); - entries = await zip.entries(); - await zip.close(); - } catch (err) { - console.error(err); - } - error(404, 'Not found'); - return { - slug: params.slug, - timestamp: params.timestamp, - entries - }; -} diff --git a/src/routes/g/[slug]/[[timestamp]]/o/+page.svelte b/src/routes/g/[slug]/[[timestamp]]/o/+page.svelte deleted file mode 100644 index 053da61..0000000 --- a/src/routes/g/[slug]/[[timestamp]]/o/+page.svelte +++ /dev/null @@ -1,13 +0,0 @@ - - -

Zip Entries

-{#each entries as entry} - {entry.name} -{:else} - No entries -{/each} diff --git a/src/routes/g/[slug]/[[timestamp]]/zip/+server.js b/src/routes/g/[slug]/[[timestamp]]/random/+server.js similarity index 100% rename from src/routes/g/[slug]/[[timestamp]]/zip/+server.js rename to src/routes/g/[slug]/[[timestamp]]/random/+server.js