refactor-login-page #7
@@ -20,7 +20,21 @@ export default ts.config(
|
||||
languageOptions: {
|
||||
globals: { ...globals.browser, ...globals.node }
|
||||
},
|
||||
rules: { 'no-undef': 'off' }
|
||||
rules: {
|
||||
'no-undef': 'off',
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
args: 'all',
|
||||
argsIgnorePattern: '^_',
|
||||
caughtErrors: 'all',
|
||||
caughtErrorsIgnorePattern: '^_',
|
||||
destructuredArrayIgnorePattern: '^_',
|
||||
varsIgnorePattern: '^_',
|
||||
ignoreRestSiblings: true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['**/*.svelte', '**/*.svelte.ts', '**/*.svelte.js'],
|
||||
|
||||
36
package-lock.json
generated
36
package-lock.json
generated
@@ -26,6 +26,7 @@
|
||||
"@testing-library/jest-dom": "^6.6.3",
|
||||
"@testing-library/svelte": "^5.2.8",
|
||||
"@tsconfig/svelte": "^5.0.4",
|
||||
"@types/jsonwebtoken": "^9.0.9",
|
||||
"eslint": "^9.28.0",
|
||||
"eslint-config-prettier": "^10.1.5",
|
||||
"eslint-plugin-svelte": "^3.9.2",
|
||||
@@ -1659,6 +1660,34 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/jsonwebtoken": {
|
||||
"version": "9.0.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.9.tgz",
|
||||
"integrity": "sha512-uoe+GxEuHbvy12OUQct2X9JenKM3qAscquYymuQN4fMWG9DBQtykrQEFcAbVACF7qaLw9BePSodUL0kquqBJpQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/ms": "*",
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/ms": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz",
|
||||
"integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "24.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.0.0.tgz",
|
||||
"integrity": "sha512-yZQa2zm87aRVcqDyH5+4Hv9KYgSdgwX1rFnGvpbzMaC7YAljmhBET93TPiTd3ObwTL+gSpIzPKg5BqVxdCvxKg==",
|
||||
"devOptional": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~7.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/resolve": {
|
||||
"version": "1.20.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz",
|
||||
@@ -6085,6 +6114,13 @@
|
||||
"typescript": ">=4.8.4 <5.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "7.8.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.8.0.tgz",
|
||||
"integrity": "sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw==",
|
||||
"devOptional": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/update-browserslist-db": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.3.tgz",
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"@testing-library/jest-dom": "^6.6.3",
|
||||
"@testing-library/svelte": "^5.2.8",
|
||||
"@tsconfig/svelte": "^5.0.4",
|
||||
"@types/jsonwebtoken": "^9.0.9",
|
||||
"eslint": "^9.28.0",
|
||||
"eslint-config-prettier": "^10.1.5",
|
||||
"eslint-plugin-svelte": "^3.9.2",
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { decryptToken } from '$lib/auth';
|
||||
import type { Handle } from '@sveltejs/kit';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Handle} */
|
||||
export async function handle({ event, resolve }) {
|
||||
export const handle: Handle = ({ event, resolve }) => {
|
||||
const jwt = event.cookies.get('session');
|
||||
try {
|
||||
if (jwt) {
|
||||
event.locals.user = decryptToken(jwt);
|
||||
return resolve(event);
|
||||
}
|
||||
} catch (err) {
|
||||
await event.cookies.delete('session');
|
||||
} catch (_) {
|
||||
event.cookies.delete('session', {path: '/'});
|
||||
event.locals.user = null;
|
||||
}
|
||||
return resolve(event);
|
||||
|
||||
@@ -11,7 +11,7 @@ export function createToken(userData) {
|
||||
return jwt.sign(userData, SECRET, { expiresIn: EXPIRES_IN });
|
||||
}
|
||||
|
||||
export function decryptToken(token) {
|
||||
export function decryptToken(token: string) {
|
||||
return jwt.verify(token, SECRET);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
export default JSON.parse(readFileSync('./config.json'));
|
||||
export default JSON.parse(readFileSync('./config.json').toString());
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import { client } from '$lib/minio';
|
||||
|
||||
/**
|
||||
* Check if caseNumber is used
|
||||
* @param {string} caseNumber
|
||||
* @returns {Promise<boolean}
|
||||
*/
|
||||
export default async function caseNumberOccupied(caseNumber) {
|
||||
export default async function caseNumberOccupied (caseNumber: string): Promise<boolean> {
|
||||
const prefix = `${caseNumber}/config.json`;
|
||||
const promise = new Promise((resolve) => {
|
||||
let stream = client.listObjectsV2('tatort', prefix, false, '');
|
||||
const promise: Promise<boolean> = new Promise((resolve) => {
|
||||
const stream = client.listObjectsV2('tatort', prefix, false, '');
|
||||
stream.on('data', () => {
|
||||
stream.destroy();
|
||||
resolve(true);
|
||||
|
||||
@@ -2,12 +2,7 @@ const KILO = 1024;
|
||||
const MEGA = KILO * KILO;
|
||||
const GIGA = MEGA * KILO;
|
||||
|
||||
/**
|
||||
* Shortens the size in bytes
|
||||
* @param {number} size
|
||||
* @returns{string}
|
||||
*/
|
||||
export default function shortenFileSize(size) {
|
||||
export default function shortenFileSize(size: number): string {
|
||||
const giga = Math.floor(size / GIGA);
|
||||
let remainder = size % GIGA;
|
||||
const mega = Math.floor(remainder / MEGA);
|
||||
|
||||
@@ -4,12 +4,7 @@ const DAY = 24 * HOUR;
|
||||
const YEAR = 365 * DAY;
|
||||
const MONTH = YEAR / 12;
|
||||
|
||||
/**
|
||||
* get readable string of time elapsed since date
|
||||
* @param {Date} date
|
||||
* @returns string
|
||||
*/
|
||||
export default function timeElapsed(date) {
|
||||
export default function timeElapsed(date: Date): string {
|
||||
const now = new Date();
|
||||
const age = Math.floor((now.getTime() - date.getTime()) / 1000);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import { redirect, type ServerLoadEvent } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './view/[vorgang]/[tatort]/$types';
|
||||
|
||||
/** @type {import('./$types').PageServerLoad} */
|
||||
export function load(event) {
|
||||
export const load: PageServerLoad = (event: ServerLoadEvent) => {
|
||||
if (!event.locals.user && event.url.pathname !== '/anmeldung') throw redirect(303, '/anmeldung');
|
||||
return {
|
||||
user: event.locals.user
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import Chevron from '$lib/icons/Chevron-right.svelte';
|
||||
import Login from '$lib/icons/Login.svelte';
|
||||
|
||||
export let data;
|
||||
</script>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
</style>
|
||||
|
||||
<script lang="ts">
|
||||
import Panel from '$lib/components/ui/Panel.svelte';
|
||||
|
||||
export let data;
|
||||
</script>
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
<style>
|
||||
ul {
|
||||
min-width: 24rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
/**
|
||||
* @type any[]
|
||||
@@ -31,31 +24,29 @@
|
||||
.filter((i) => i.length > 0)
|
||||
.map((i) => JSON.parse(i));
|
||||
|
||||
console.log(objs);
|
||||
list = list.concat(objs);
|
||||
}
|
||||
});
|
||||
|
||||
async function delete_item(ev: Event) {
|
||||
let delete_item = window.confirm("Bist du sicher?");
|
||||
let delete_item = window.confirm('Bist du sicher?');
|
||||
|
||||
if (delete_item) {
|
||||
const target = ev.currentTarget as HTMLElement | null;
|
||||
if (!target) return;
|
||||
let filename = target.id.split('del__')[1]
|
||||
let filename = target.id.split('del__')[1];
|
||||
|
||||
// delete request
|
||||
// --------------
|
||||
|
||||
let url = `/api/list/${filename}`
|
||||
let url = `/api/list/${filename}`;
|
||||
|
||||
console.log(`--- ${filename} + ${url}`)
|
||||
try {
|
||||
const response = await fetch(url,
|
||||
{method: 'DELETE'}
|
||||
)
|
||||
const response = await fetch(url, { method: 'DELETE' });
|
||||
if (response.status == 204) {
|
||||
setTimeout(() => {window.location.reload()}, 500)
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
@@ -64,9 +55,7 @@
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -103,8 +92,13 @@
|
||||
on:click|preventDefault={delete_item}
|
||||
aria-label="Vorgang {item.name} löschen"
|
||||
>
|
||||
<svg
|
||||
height="20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="m8 3v1 1h1v-1h4v1h1v-1-1zm-4 3v1h14v-1zm2 2v11h1 9v-1-10h-1v10h-8v-10z" fill="#373737" transform="translate(1 1)"/></svg>
|
||||
<svg height="20" width="20" xmlns="http://www.w3.org/2000/svg"
|
||||
><path
|
||||
d="m8 3v1 1h1v-1h4v1h1v-1-1zm-4 3v1h14v-1zm2 2v11h1 9v-1-10h-1v10h-8v-10z"
|
||||
fill="#373737"
|
||||
transform="translate(1 1)"
|
||||
/></svg
|
||||
>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -117,3 +111,9 @@
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
ul {
|
||||
min-width: 24rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<style>
|
||||
ul {
|
||||
min-width: 24rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script lang="ts">
|
||||
import { onMount, tick } from 'svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import shortenFileSize from '$lib/helper/shortenFileSize';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
@@ -18,7 +12,6 @@
|
||||
import ModalContent from '$lib/components/ui/Modal/ModalContent.svelte';
|
||||
import ModalFooter from '$lib/components/ui/Modal/ModalFooter.svelte';
|
||||
|
||||
/** @type {import('./$types').PageData} */
|
||||
/** export let data; */
|
||||
|
||||
interface ListItem {
|
||||
@@ -59,28 +52,26 @@
|
||||
.filter((i) => i.length > 0)
|
||||
.map((i) => JSON.parse(i));
|
||||
|
||||
console.log(objs);
|
||||
list = list.concat(objs);
|
||||
|
||||
list = list.map((item) => {
|
||||
item.show_button = true;
|
||||
return item;
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function uploadSuccessful() {
|
||||
console.log('reset');
|
||||
open = false;
|
||||
}
|
||||
|
||||
function defocus_element(i: number) {
|
||||
let item = list[i]
|
||||
let text_field_id = `label__${item.name}`
|
||||
let item = list[i];
|
||||
let text_field_id = `label__${item.name}`;
|
||||
|
||||
let text_field = document.getElementById(text_field_id)
|
||||
let text_field = document.getElementById(text_field_id);
|
||||
if (text_field) {
|
||||
text_field.setAttribute("contenteditable", "false")
|
||||
text_field.setAttribute('contenteditable', 'false');
|
||||
text_field.textContent = item.name;
|
||||
}
|
||||
|
||||
@@ -90,25 +81,25 @@
|
||||
}
|
||||
|
||||
async function handle_input(ev: KeyboardEvent, i: number) {
|
||||
let item = list[i]
|
||||
if (ev.key == "Escape") {
|
||||
let text_field_id = `label__${item.name}`
|
||||
let item = list[i];
|
||||
if (ev.key == 'Escape') {
|
||||
let text_field_id = `label__${item.name}`;
|
||||
|
||||
let text_field = document.getElementById(text_field_id)
|
||||
let text_field = document.getElementById(text_field_id);
|
||||
if (text_field) {
|
||||
text_field.setAttribute("contenteditable", "false");
|
||||
text_field.setAttribute('contenteditable', 'false');
|
||||
text_field.textContent = item.name;
|
||||
}
|
||||
|
||||
// reshow button
|
||||
item.show_button = true
|
||||
item.show_button = true;
|
||||
return;
|
||||
}
|
||||
if (ev.key == "Enter") {
|
||||
console.log('--- hitted')
|
||||
if (ev.key == 'Enter') {
|
||||
let name_field = ev.currentTarget as HTMLElement | null;
|
||||
let new_name = name_field ? (name_field.textContent || (name_field as any).innerText || '') : '';
|
||||
|
||||
let new_name = name_field
|
||||
? name_field.textContent || (name_field as any).innerText || ''
|
||||
: '';
|
||||
|
||||
if (new_name == '') {
|
||||
alert('Bitte einen gültigen Namen eingeben.');
|
||||
@@ -123,34 +114,35 @@
|
||||
ev.preventDefault();
|
||||
|
||||
// construct PUT URL
|
||||
const url = $page.url
|
||||
console.log(url);
|
||||
const url = $page.url;
|
||||
|
||||
let data_obj: { new_name: string; old_name: string } = { new_name: '', old_name: '' };
|
||||
data_obj["new_name"] = new_name
|
||||
data_obj["old_name"] = ev.currentTarget && (ev.currentTarget as HTMLElement).id ? (ev.currentTarget as HTMLElement).id.split('__')[1] : ''
|
||||
|
||||
data_obj['new_name'] = new_name;
|
||||
data_obj['old_name'] =
|
||||
ev.currentTarget && (ev.currentTarget as HTMLElement).id
|
||||
? (ev.currentTarget as HTMLElement).id.split('__')[1]
|
||||
: '';
|
||||
|
||||
open = true;
|
||||
inProgress = true;
|
||||
|
||||
const response = await fetch(url,
|
||||
{method: 'PUT', body: JSON.stringify( data_obj )
|
||||
})
|
||||
const response = await fetch(url, { method: 'PUT', body: JSON.stringify(data_obj) });
|
||||
|
||||
inProgress = false;
|
||||
|
||||
if (!response.ok) {
|
||||
err = true;
|
||||
if (response.status == 400) {
|
||||
let json_res = await response.json()
|
||||
let json_res = await response.json();
|
||||
// alert(json_res['msg'])
|
||||
return;
|
||||
}
|
||||
throw new Error(`Fehlgeschlagen: ${response.status}`)
|
||||
throw new Error(`Fehlgeschlagen: ${response.status}`);
|
||||
} else {
|
||||
uploadSuccessful();
|
||||
setTimeout(() => {window.location.reload()}, 500)
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
// --- upload finished ---
|
||||
@@ -158,7 +150,6 @@
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<div class="-z-10 bg-white">
|
||||
@@ -200,13 +191,12 @@
|
||||
on:focusout={() => {
|
||||
defocus_element(i);
|
||||
}}
|
||||
on:keydown|stopPropagation={
|
||||
// event needed to identify ID
|
||||
on:keydown|stopPropagation={// event needed to identify ID
|
||||
// TO-DO: check if event is needed or if index is sufficient
|
||||
async (ev) => {handle_input(ev, i)}
|
||||
}
|
||||
|
||||
>{item.name}</span>
|
||||
async (ev) => {
|
||||
handle_input(ev, i);
|
||||
}}>{item.name}</span
|
||||
>
|
||||
<!-- https://iconduck.com/icons/192863/edit-rename -->
|
||||
|
||||
{#if item.show_button}
|
||||
@@ -215,67 +205,73 @@
|
||||
id="edit__{item.name}"
|
||||
aria-label="Datei umbenennen"
|
||||
on:click|preventDefault={(ev) => {
|
||||
let text_field_id = `label__${item.name}`
|
||||
let text_field_id = `label__${item.name}`;
|
||||
|
||||
let text_field = document.getElementById(text_field_id)
|
||||
let text_field = document.getElementById(text_field_id);
|
||||
if (text_field) {
|
||||
text_field.setAttribute("contenteditable", "true");
|
||||
text_field.setAttribute('contenteditable', 'true');
|
||||
text_field.focus();
|
||||
text_field.textContent = '';
|
||||
}
|
||||
|
||||
// hide button
|
||||
item.show_button = false
|
||||
item.show_button = false;
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
height="20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="m14.996094 3-11.9921878 11.992188h-.0039062v4.007812h1 2 1.0078125v-.0039l11.9921875-11.9921938-.001953-.0019531.001953-.0019531-4-4-.002.00195zm-1.998047 3.4121094 2.589844 2.5898437-7.587891 7.5878909v-1.589844h-1-1v-1-.589844zm-7.998047 7.9980466v1.589844h1 1v1 .589844l-.4101562.410156h-1.5898438l-1-1v-1.589844z" fill="#373737" transform="translate(1 1)"/></svg>
|
||||
<svg height="20" width="20" xmlns="http://www.w3.org/2000/svg"
|
||||
><path
|
||||
d="m14.996094 3-11.9921878 11.992188h-.0039062v4.007812h1 2 1.0078125v-.0039l11.9921875-11.9921938-.001953-.0019531.001953-.0019531-4-4-.002.00195zm-1.998047 3.4121094 2.589844 2.5898437-7.587891 7.5878909v-1.589844h-1-1v-1-.589844zm-7.998047 7.9980466v1.589844h1 1v1 .589844l-.4101562.410156h-1.5898438l-1-1v-1.589844z"
|
||||
fill="#373737"
|
||||
transform="translate(1 1)"
|
||||
/></svg
|
||||
>
|
||||
</button>
|
||||
{/if}
|
||||
<button
|
||||
style="padding: 2px"
|
||||
id="del__{item.name}"
|
||||
on:click|preventDefault={async (ev) => {
|
||||
let delete_item = window.confirm("Bist du sicher?");
|
||||
let delete_item = window.confirm('Bist du sicher?');
|
||||
|
||||
if (delete_item) {
|
||||
// bucket: tatort, name: <vorgang>/item-name
|
||||
let vorgang = $page.params.vorgang
|
||||
let vorgang = $page.params.vorgang;
|
||||
let filename = '';
|
||||
if (ev && ev.currentTarget && (ev.currentTarget as HTMLElement).id) {
|
||||
filename = (ev.currentTarget as HTMLElement).id.split('del__')[1];
|
||||
}
|
||||
|
||||
|
||||
|
||||
// delete request
|
||||
// --------------
|
||||
|
||||
let url = new URL($page.url);
|
||||
url.pathname += `/${filename}`;
|
||||
|
||||
console.log(`--- ${vorgang} + ${filename} + ${url}`)
|
||||
try {
|
||||
const response = await fetch(url,
|
||||
{method: 'DELETE'}
|
||||
)
|
||||
const response = await fetch(url, { method: 'DELETE' });
|
||||
if (response.status == 204) {
|
||||
setTimeout(() => {window.location.reload()}, 500)
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.log(error.message)
|
||||
console.log(error.message);
|
||||
} else {
|
||||
console.log(error)
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}}
|
||||
aria-label="Datei löschen"
|
||||
>
|
||||
<svg
|
||||
height="20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="m8 3v1 1h1v-1h4v1h1v-1-1zm-4 3v1h14v-1zm2 2v11h1 9v-1-10h-1v10h-8v-10z" fill="#373737" transform="translate(1 1)"/></svg>
|
||||
<svg height="20" width="20" xmlns="http://www.w3.org/2000/svg"
|
||||
><path
|
||||
d="m8 3v1 1h1v-1h4v1h1v-1-1zm-4 3v1h14v-1zm2 2v11h1 9v-1-10h-1v10h-8v-10z"
|
||||
fill="#373737"
|
||||
transform="translate(1 1)"
|
||||
/></svg
|
||||
>
|
||||
</button>
|
||||
<p class="mt-1 truncate text-xs leading-5 text-gray-500">
|
||||
{shortenFileSize(item.size)}
|
||||
@@ -307,5 +303,10 @@
|
||||
</ModalContent>
|
||||
<ModalFooter><Button disabled={inProgress} on:click={uploadSuccessful}>Ok</Button></ModalFooter>
|
||||
</Modal>
|
||||
|
||||
</div>
|
||||
|
||||
<style>
|
||||
ul {
|
||||
min-width: 24rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -3,25 +3,24 @@ import { json } from '@sveltejs/kit';
|
||||
|
||||
|
||||
// rename operation
|
||||
export async function PUT({ request }) {
|
||||
export async function PUT({ request }: {request: Request}) {
|
||||
const data = await request.json();
|
||||
|
||||
console.log(`--- ${request.url.split('/').at(-1)} +++ ${JSON.stringify(data)}`);
|
||||
|
||||
// Vorgang
|
||||
let vorgang = request.url.split('/').at(-1)
|
||||
const vorgang = request.url.split('/').at(-1);
|
||||
|
||||
// prepare copy, incl. check if new name exists already
|
||||
let old_name = data["old_name"]
|
||||
let src_full_path = `/tatort/${vorgang}/${old_name}`
|
||||
let new_name = `${vorgang}/${data["new_name"]}`
|
||||
const old_name = data["old_name"];
|
||||
const src_full_path = `/tatort/${vorgang}/${old_name}`;
|
||||
const new_name = `${vorgang}/${data["new_name"]}`;
|
||||
|
||||
try {
|
||||
let file_stats = await client.statObject('tatort', new_name)
|
||||
return json({ msg: 'Die Datei existiert bereits.' }, { status: 400 })
|
||||
await client.statObject('tatort', new_name);
|
||||
return json({ msg: 'Die Datei existiert bereits.' }, { status: 400 });
|
||||
} catch (error) {
|
||||
// continue operation
|
||||
console.log('continue operation')
|
||||
console.log(error, 'continue operation');
|
||||
}
|
||||
|
||||
// actual copy operation
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import { client } from '$lib/minio';
|
||||
import { json } from '@sveltejs/kit';
|
||||
|
||||
export async function DELETE({ request }) {
|
||||
export async function DELETE({ request }: { request: Request }) {
|
||||
const url_fragments = request.url.split('/');
|
||||
const item = url_fragments.at(-1);
|
||||
const vorgang = url_fragments.at(-2);
|
||||
|
||||
let url_fragments = request.url.split('/')
|
||||
let item = url_fragments.at(-1);
|
||||
let vorgang = url_fragments.at(-2);
|
||||
|
||||
await client.removeObject('tatort', `${vorgang}/${item}`)
|
||||
await client.removeObject('tatort', `${vorgang}/${item}`);
|
||||
|
||||
return new Response(null, { status: 204 });
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import caseNumberOccupied from '$lib/helper/caseNumberOccupied';
|
||||
|
||||
/** @type {import('./$types').Actions} */
|
||||
export const actions = {
|
||||
default: async ({ request }) => {
|
||||
default: async ({ request }: {request: Request}) => {
|
||||
const data = await request.formData();
|
||||
const caseNumber = data.get('caseNumber');
|
||||
const description = data.get('description');
|
||||
@@ -28,7 +28,7 @@ export const actions = {
|
||||
|
||||
const config = `${JSON.stringify({ caseNumber, description, version: 1 })}\n`;
|
||||
|
||||
await client.putObject('tatort', `${caseNumber}/config.json`, config, {
|
||||
await client.putObject('tatort', `${caseNumber}/config.json`, config, undefined, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
|
||||
@@ -55,22 +55,22 @@
|
||||
<div>
|
||||
<label for="description" class="block text-sm font-medium leading-6 text-gray-900"
|
||||
><span class="flex"
|
||||
>{#if form?.error?.description}
|
||||
>{#if form?.description}
|
||||
<span class="inline-block mr-1"><Exclamation /></span>
|
||||
{/if} Beschreibung</span
|
||||
></label
|
||||
>
|
||||
<div class="mt-2">
|
||||
<textarea
|
||||
value={form?.description ?? ''}
|
||||
value={form?.description?.toString() ?? ''}
|
||||
id="description"
|
||||
name="description"
|
||||
rows="3"
|
||||
class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
|
||||
></textarea>
|
||||
</div>
|
||||
{#if form?.error?.description}
|
||||
<p class="block text-sm leading-6 text-red-900 mt-2">{form.error.description}</p>
|
||||
{#if form?.error}
|
||||
<p class="block text-sm leading-6 text-red-900 mt-2">{form.description}</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import path from 'path';
|
||||
import { writeFile } from 'fs/promises';
|
||||
import { createReadStream } from 'fs';
|
||||
/** import Minio from 'minio'; */
|
||||
import { Readable } from 'stream';
|
||||
/** const MINIO_ACCESS_KEY = 'tMhLrfog47lMm0HZ'; */
|
||||
import { client } from '$lib/minio';
|
||||
import { fail } from '@sveltejs/kit';
|
||||
|
||||
function isRequiredFieldValid(value) {
|
||||
const isRequiredFieldValid = (value: unknown) => {
|
||||
if (value == null) return false;
|
||||
|
||||
if (typeof value === 'string' || value instanceof String) return value.trim() !== '';
|
||||
@@ -15,9 +10,8 @@ function isRequiredFieldValid(value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @type {import('./$types').Actions} */
|
||||
export const actions = {
|
||||
url: async ({ request }) => {
|
||||
url: async ({ request }: {request: Request}) => {
|
||||
const data = await request.formData();
|
||||
const vorgang = data.get('vorgang');
|
||||
const name = data.get('name');
|
||||
@@ -30,20 +24,20 @@ export const actions = {
|
||||
if (!objectName.endsWith('.png')) objectName += '.png';
|
||||
break;
|
||||
case '':
|
||||
if (fileName.endsWith('.glb') && !objectName.endsWith('.glb')) objectName += '.glb';
|
||||
if (fileName?.toString().endsWith('.glb') && !objectName.endsWith('.glb')) objectName += '.glb';
|
||||
}
|
||||
|
||||
const url = await client.presignedPutObject('tatort', objectName);
|
||||
|
||||
return { url };
|
||||
},
|
||||
validate: async ({ request }) => {
|
||||
validate: async ({ request }: {request: Request}) => {
|
||||
const requestData = await request.formData();
|
||||
const data = Object.fromEntries(requestData);
|
||||
const vorgang = data.vorgang;
|
||||
const name = data.name;
|
||||
let success = true;
|
||||
let err = {};
|
||||
const err = {};
|
||||
|
||||
if (isRequiredFieldValid(vorgang)) err.vorgang = null;
|
||||
else {
|
||||
@@ -62,24 +56,21 @@ export const actions = {
|
||||
return fail(400, err);
|
||||
},
|
||||
|
||||
upload: async ({ request }) => {
|
||||
upload: async ({ request }: {request: Request}) => {
|
||||
const requestData = await request.formData();
|
||||
const data = Object.fromEntries(requestData);
|
||||
const vorgang = data.vorgang;
|
||||
const name = data.name;
|
||||
console.log('I:', vorgang, name);
|
||||
|
||||
const url = await client.presignedPutObject('tatort', `${vorgang}/${name}`, 60);
|
||||
|
||||
console.log('O:', url);
|
||||
return { url };
|
||||
},
|
||||
upload3: async ({ request }) => {
|
||||
upload3: async ({ request }: {request: Request}) => {
|
||||
const requestData = await request.formData();
|
||||
const data = Object.fromEntries(requestData);
|
||||
const name = data.name;
|
||||
const stream = data.file.stream();
|
||||
console.log('Data:', stream);
|
||||
const metaData = { 'Content-Type': 'model-gtlf-binary', 'X-VorgangsNr': '4711' };
|
||||
const result = new Promise((resolve, reject) => {
|
||||
client.putObject('tatort', name, Readable.from(stream), metaData, function (err, etag) {
|
||||
@@ -91,7 +82,6 @@ export const actions = {
|
||||
let error = null;
|
||||
try {
|
||||
etag = await result;
|
||||
console.log(etag);
|
||||
} catch (err) {
|
||||
error = err;
|
||||
console.log('Error:', err);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { deserialize, enhance } from '$app/forms';
|
||||
import { deserialize } from '$app/forms';
|
||||
import Alert from '$lib/components/ui/Alert.svelte';
|
||||
import Button from '$lib/components/ui/Button.svelte';
|
||||
import Modal from '$lib/components/ui/Modal/Modal.svelte';
|
||||
@@ -15,15 +15,12 @@
|
||||
let inProgress = false;
|
||||
let vorgang = '';
|
||||
let name = '';
|
||||
/** @type {?string}*/
|
||||
let etag = null;
|
||||
/** @type {?FileList} */
|
||||
let files = null;
|
||||
let etag: string | null = null;
|
||||
let files: FileList | null = null;
|
||||
|
||||
$: inProgress = form === null;
|
||||
|
||||
/** @type {?Record<string,any>}*/
|
||||
let formErrors;
|
||||
let formErrors: Record<string,any> | null;
|
||||
|
||||
async function validateForm() {
|
||||
let data = new FormData();
|
||||
@@ -41,7 +38,6 @@
|
||||
success = false;
|
||||
}
|
||||
|
||||
console.log('File', files);
|
||||
if (!files?.length) {
|
||||
formErrors = { file: 'Sie haben keine Datei ausgewählt.', ...formErrors };
|
||||
success = false;
|
||||
@@ -71,14 +67,12 @@
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @param {MouseEvent} event*/
|
||||
async function buttonClick(event) {
|
||||
async function buttonClick(event: MouseEvent) {
|
||||
if (!(await validateForm())) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
const url = await getUrl();
|
||||
console.log('URL', url);
|
||||
open = true;
|
||||
inProgress = true;
|
||||
|
||||
@@ -86,7 +80,6 @@
|
||||
.then((response) => {
|
||||
inProgress = false;
|
||||
etag = '123';
|
||||
console.log('SUCCESS', response);
|
||||
})
|
||||
.catch((err) => {
|
||||
inProgress = false;
|
||||
@@ -96,7 +89,6 @@
|
||||
}
|
||||
|
||||
function uploadSuccessful() {
|
||||
console.log('reset');
|
||||
open = false;
|
||||
vorgang = '';
|
||||
name = '';
|
||||
|
||||
@@ -3,7 +3,7 @@ import { fail, redirect } from '@sveltejs/kit';
|
||||
|
||||
/** @type {import('./$types').Actions} */
|
||||
export const actions = {
|
||||
default: async ({ request }) => {
|
||||
default: async ({ request }: {request: Request}) => {
|
||||
const data = await request.formData();
|
||||
const caseNumber = data.get('caseNumber');
|
||||
|
||||
@@ -15,7 +15,7 @@ export const actions = {
|
||||
});
|
||||
}
|
||||
|
||||
if (!(await caseNumberOccupied(caseNumber))) {
|
||||
if (typeof caseNumber === 'string' && !(await caseNumberOccupied(caseNumber))) {
|
||||
return fail(400, {
|
||||
success: false,
|
||||
caseNumber,
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
<script lang="ts">
|
||||
import Alert from '$lib/components/ui/Alert.svelte';
|
||||
import Button from '$lib/components/ui/Button.svelte';
|
||||
import Modal from '$lib/components/ui/Modal/Modal.svelte';
|
||||
import ModalTitle from '$lib/components/ui/Modal/ModalTitle.svelte';
|
||||
import ModalContent from '$lib/components/ui/Modal/ModalContent.svelte';
|
||||
import ModalFooter from '$lib/components/ui/Modal/ModalFooter.svelte';
|
||||
import Exclamation from '$lib/icons/Exclamation.svelte';
|
||||
|
||||
export let form;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { client } from '$lib/minio';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
/** @type {import('./$types').PageServerLoad} */
|
||||
export async function load({ params }) {
|
||||
export const load: PageServerLoad = async ({ params }) => {
|
||||
const { vorgang, tatort } = params;
|
||||
const url = await client.presignedUrl('GET', 'tatort', `${vorgang}/${tatort}`);
|
||||
return { url };
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<script lang="ts">
|
||||
import { preloadCode } from '$app/navigation';
|
||||
import Panel from '$lib/components/ui/Panel.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import Button from '$lib/components/ui/Button.svelte';
|
||||
@@ -20,26 +19,16 @@
|
||||
let cameraAzimuth = 0;
|
||||
let cameraPolar = 0;
|
||||
|
||||
let frontView = cameraAzimuth === 0 && cameraPolar === 0 ? true : false;
|
||||
|
||||
let topView = cameraAzimuth === 0 && cameraPolar === 90 ? true : false;
|
||||
|
||||
let cameraZoom = 100;
|
||||
let xRotation = 0;
|
||||
let yRotation = 0;
|
||||
let zRotation = 0;
|
||||
|
||||
/**
|
||||
* @type {any}
|
||||
*/
|
||||
let modelViewer;
|
||||
|
||||
$: style = `width: ${progress}%`;
|
||||
|
||||
/**
|
||||
* @param {any} detail
|
||||
*/
|
||||
function onProgress({ detail }) {
|
||||
const onProgress = ({ detail }) => {
|
||||
progress = Math.ceil(detail.totalProgress * 100.0);
|
||||
if (progress == 100) {
|
||||
setTimeout(() => {
|
||||
@@ -49,21 +38,6 @@
|
||||
}
|
||||
|
||||
function onResetView() {
|
||||
console.log(
|
||||
'show cameraOrbit:',
|
||||
modelViewer.getCameraOrbit(),
|
||||
modelViewer.cameraOrbit,
|
||||
modelViewer.getDimensions()
|
||||
);
|
||||
console.log(
|
||||
'Camera-orbit: ',
|
||||
modelViewer.getAttribute('camera-orbit'),
|
||||
'camera-target: ',
|
||||
modelViewer.getAttribute('camera-target'),
|
||||
'object-rotation: ',
|
||||
modelViewer.getAttribute('rotation')
|
||||
);
|
||||
|
||||
cameraAzimuth = 0;
|
||||
cameraPolar = 0;
|
||||
cameraZoom = 100;
|
||||
@@ -77,12 +51,7 @@
|
||||
fieldOfView = '10deg';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} azimuth
|
||||
* @param {number} polar
|
||||
* @param {number} zoom
|
||||
*/
|
||||
function updateCameraOrbit(azimuth, polar, zoom) {
|
||||
function updateCameraOrbit(azimuth: number, polar: number, zoom: number) {
|
||||
cameraAzimuth = azimuth;
|
||||
cameraPolar = polar;
|
||||
cameraZoom = zoom;
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { dev } from '$app/environment';
|
||||
import { fail, redirect } from '@sveltejs/kit';
|
||||
import { fail, redirect, type Cookies } from '@sveltejs/kit';
|
||||
import { authenticate } from '$lib/auth';
|
||||
import type { RequestEvent } from '../(angemeldet)/$types';
|
||||
|
||||
const COOKIE_NAME = 'session';
|
||||
|
||||
/** @type {import('./$types').Actions} */
|
||||
export const actions = {
|
||||
login: async ({ request, cookies }) => {
|
||||
login: async ({ request, cookies }: {request: Request, cookies: Cookies}) => {
|
||||
const data = await request.formData();
|
||||
const user = data.get('user');
|
||||
const password = data.get('password');
|
||||
@@ -23,7 +24,7 @@ export const actions = {
|
||||
});
|
||||
throw redirect(303, '/');
|
||||
},
|
||||
logout: async (event) => {
|
||||
logout: async (event: RequestEvent) => {
|
||||
event.cookies.delete(COOKIE_NAME, {path: '/'});
|
||||
event.locals.user = null;
|
||||
return { success: true };
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
<script lang="ts">
|
||||
import Panel from '$lib/components/ui/Panel.svelte';
|
||||
import Button from '$lib/components/ui/Button.svelte';
|
||||
import Alert from '$lib/components/ui/Alert.svelte';
|
||||
import Login from '$lib/icons/Login.svelte';
|
||||
import type { ActionData } from "./$types";
|
||||
|
||||
/** @type {import('./$types').ActionData} */
|
||||
export let form;
|
||||
export let form: ActionData;
|
||||
|
||||
let user = form?.user ?? '';
|
||||
|
||||
function buttonClick() {}
|
||||
</script>
|
||||
|
||||
<!--
|
||||
|
||||
@@ -3,7 +3,7 @@ import { client } from '$lib/minio';
|
||||
/** @type {import('./$types').RequestHandler} */
|
||||
export async function GET({ params }) {
|
||||
const prefix = params.vorgang ? `${params.vorgang}/` : '';
|
||||
let stream = client.listObjectsV2('tatort', prefix, false, '');
|
||||
const stream = client.listObjectsV2('tatort', prefix, false, '');
|
||||
const result = new ReadableStream({
|
||||
start(controller) {
|
||||
stream.on('data', (data) => {
|
||||
@@ -52,9 +52,6 @@ export async function DELETE({ params }) {
|
||||
items_str.on('end', async () => {
|
||||
resolve(res)
|
||||
})
|
||||
|
||||
console.log(`+++ ${vorgang}`)
|
||||
|
||||
})
|
||||
|
||||
await client.removeObjects('tatort', object_list)
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { client } from '$lib/minio';
|
||||
|
||||
/** @type {import('./$types').RequestHandler} */
|
||||
export async function GET() {
|
||||
var stream = client.listObjectsV2('tatort', '', true);
|
||||
const stream = client.listObjectsV2('tatort', '', true);
|
||||
const result = new ReadableStream({
|
||||
start(controller) {
|
||||
stream.on('data', (data) => {
|
||||
//console.log(data);
|
||||
controller.enqueue(`${JSON.stringify(data)}\n`);
|
||||
});
|
||||
stream.on('end', () => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { client } from '$lib/minio';
|
||||
import type { RequestHandler } from "@sveltejs/kit";
|
||||
|
||||
/** @type {import('./$types').RequestHandler} */
|
||||
export async function GET(params) {
|
||||
export async function GET(params: RequestHandler) {
|
||||
console.log('GET', params);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user