Compare commits
228 Commits
archive/f0
...
c53400d7b7
| Author | SHA1 | Date | |
|---|---|---|---|
| c53400d7b7 | |||
| ef1ddb58a0 | |||
| 8c4f95d52e | |||
| 5b408b096e | |||
| aae8237aae | |||
| 5927f1dacd | |||
| f39debd0b8 | |||
| 7d265341cc | |||
| d6f2956bcb | |||
| 5a06c99fb7 | |||
| b3e2b297a3 | |||
| b655df1087 | |||
| 77c57cb58b | |||
| 0f2cf87a78 | |||
| 1fd6cb3ab3 | |||
| d402282efe | |||
|
|
952c3901c1 | ||
| dfa5c9ade1 | |||
| 4406a86f44 | |||
| 08d83c9ed4 | |||
|
|
cf567451bb | ||
| 52e9eba7ed | |||
| 962dc35324 | |||
| 12217cb7a6 | |||
| e9b4289727 | |||
| 9b57a988f3 | |||
| 4f9e919bfe | |||
| 9e6318d516 | |||
| c715295c72 | |||
| e3eac5b441 | |||
| f6ed438908 | |||
| 542c12cc5f | |||
| ee9d9fa8fc | |||
| addcc26a07 | |||
| db1cc78f2c | |||
| e8170de947 | |||
| 26c05b4999 | |||
| 809c355849 | |||
| bd9275c378 | |||
| 143bb128a5 | |||
| b2f624a7d1 | |||
| a7527ccf22 | |||
| 34d5034a71 | |||
| 6786f768f0 | |||
| 552350354b | |||
| d9bcad9f77 | |||
| 4633769366 | |||
| 2444349694 | |||
| c5202bb757 | |||
| 73c551c9de | |||
| 51af112610 | |||
| b8e5031669 | |||
| 51d3f19f3e | |||
| 5070ac9f7a | |||
| 873a382f69 | |||
| fa59db7a88 | |||
| 484acd3bcf | |||
| cd5389666e | |||
| a7eb81151f | |||
| 8408d63f40 | |||
| f2bde76969 | |||
| 83bcaca918 | |||
| 9ddec90214 | |||
| f7245fac90 | |||
| 564716e853 | |||
| ffa34b3b61 | |||
| 307894c980 | |||
| 40599f4ffa | |||
| 8b1b3532fc | |||
| f6513c9ed8 | |||
| c034064d41 | |||
| dc2d038b1b | |||
| 0c6dbe30ab | |||
| 64aa1d404e | |||
| fa69fa9dcd | |||
| 8d92e94bd6 | |||
| 7c1b8669c0 | |||
| 5f996e7007 | |||
| f0df67fb86 | |||
| b63834eb51 | |||
| e9eb2c1163 | |||
| 3e926844b8 | |||
| ba4d810164 | |||
| b6a52822f1 | |||
| b843e3abc0 | |||
| 7a25dbf68c | |||
| 32d6245b5a | |||
| 45644c9695 | |||
| 0622fce790 | |||
| 0de66fe533 | |||
| 0aa03aea19 | |||
| 2ad9e5d86d | |||
| b57a30338e | |||
| eee820b39e | |||
| c25c8498f3 | |||
| 95a9364391 | |||
| 49907da1b1 | |||
| 93be24a8de | |||
| 22fc1f490c | |||
| 0235b56637 | |||
| 7ca8b295db | |||
| abd756462b | |||
| 2939869816 | |||
| 3bd369c9e2 | |||
| 517654bfbf | |||
| 739f67169e | |||
| 2d003a619f | |||
| bb5ade22c6 | |||
| be4e351217 | |||
| 30b49029b2 | |||
| 890380609f | |||
| 2667db5755 | |||
| 021ec3d383 | |||
| 7018c74884 | |||
| 2b2fa7a82b | |||
| fe9f8add88 | |||
| de7b27bd71 | |||
| f995b58d0f | |||
| efcbc4d60f | |||
| 02d4957315 | |||
| de35986633 | |||
| 843c4ecaf4 | |||
| 173f36fb50 | |||
| 35c5323a19 | |||
| 5a1cd22dc6 | |||
| 1fabe234e0 | |||
| 036798d330 | |||
| fee152553b | |||
| 2ed49394d7 | |||
| c74322228f | |||
| 95936b09b5 | |||
| 1d84b67a94 | |||
| 083efb3aec | |||
| fd17d10119 | |||
| 9ad96abb77 | |||
| 4dcd2e1a63 | |||
| 331b9c22e1 | |||
| 997ef6e30d | |||
| 1c394dff72 | |||
| 8c29d39bf6 | |||
| 0181fb288b | |||
| 1de66b11b3 | |||
| f2dd50c16e | |||
| be61814b58 | |||
| 62bca02625 | |||
| 15529541ed | |||
| b432554cca | |||
| b991904921 | |||
| 66794ef0f6 | |||
| b46852e385 | |||
| d0c6feee33 | |||
| 38f9f61e8a | |||
| 2effdb12c1 | |||
| b273b8046a | |||
| 0b4df7b714 | |||
| ea9b61fe79 | |||
| 017d5ce458 | |||
| 72169c4e64 | |||
| 8b276f9828 | |||
| 56cfd79687 | |||
| b2e00eb030 | |||
| d5a7058f2d | |||
| 355e4f3287 | |||
| 7d15e0369d | |||
| d6baaef992 | |||
| 533d94c6a5 | |||
| 41a98d3d1d | |||
| b4c669226f | |||
| ee6b9fcec1 | |||
| ded024bc67 | |||
| ff891bc164 | |||
| 0aec68eb8a | |||
| bb98c3656e | |||
| 5be47343c4 | |||
| e471a450d1 | |||
| 09d93e3a52 | |||
| b82d9a7708 | |||
| c5dd8b9424 | |||
| a2ac88af50 | |||
| 28e93fe943 | |||
| 98ccf6a0b0 | |||
| e01d4b1d76 | |||
| 3dbaf7a01b | |||
| 34f8fd5490 | |||
| 6d3e6ad047 | |||
| ca74e873be | |||
| c373b49f1c | |||
| 03a304f6fe | |||
| ecc2564c70 | |||
| fd0572939e | |||
| fd8298906a | |||
| 5ce5c78698 | |||
| aeabbd6d1f | |||
| af50e0fab9 | |||
| 31ca124511 | |||
| 07247486ab | |||
| e4d74e4331 | |||
| d58be34fe5 | |||
| 841446082e | |||
| bcb83ca6a7 | |||
| 89ca2bfd7c | |||
| fb72296e57 | |||
| 9524441fc1 | |||
| 97dc5aa6c4 | |||
| 8ef0845909 | |||
| acef68dc26 | |||
| c1958e848a | |||
| 20c273407f | |||
| d5b39575c7 | |||
| d05776ad3a | |||
| 10f090a64e | |||
| c991e3d778 | |||
| 5ef5476d92 | |||
| db90bae19f | |||
| efdb4e29e2 | |||
| 180a9d7ce4 | |||
| 15f2c6e549 | |||
| 4b8099481c | |||
| 7413733eb0 | |||
| d5601b8fae | |||
| c3202333d9 | |||
| 52222f0236 | |||
| 63638cfba5 | |||
| b966d19792 | |||
| def4e22226 | |||
| 527c2b438d | |||
| 5a5ae9901a | |||
| b44187b010 |
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
build
|
||||
config.json
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
test-results
|
||||
node_modules
|
||||
config.json
|
||||
|
||||
# Output
|
||||
.output
|
||||
|
||||
18
Dockerfile.dev
Normal file
18
Dockerfile.dev
Normal file
@@ -0,0 +1,18 @@
|
||||
# --- Build stage ---
|
||||
FROM node:24-alpine AS build
|
||||
ENV NODE_ENV=development
|
||||
ENV ORIGIN=https://tatort-dev.innovation-hub-niedersachsen.de
|
||||
WORKDIR /app
|
||||
COPY package.json ./
|
||||
RUN npm i --unsafe-perm
|
||||
COPY . ./
|
||||
COPY config_dev.json ./config.json
|
||||
RUN npm run build
|
||||
RUN npm run init-db
|
||||
|
||||
# --- Production stage ---
|
||||
FROM node:24-alpine
|
||||
COPY --from=build /app .
|
||||
ENV HOST=0.0.0.0
|
||||
EXPOSE 3000
|
||||
CMD ["sh", "-c", "ORIGIN=https://tatort-dev.innovation-hub-niedersachsen.de node build/index.js"]
|
||||
@@ -6,6 +6,7 @@ WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm ci
|
||||
COPY . ./
|
||||
COPY config_prod.json ./config.json
|
||||
RUN npm run build
|
||||
|
||||
# --- Production stage ---
|
||||
@@ -14,4 +15,3 @@ COPY --from=build /app .
|
||||
ENV HOST=0.0.0.0
|
||||
EXPOSE 3000
|
||||
CMD ["sh", "-c", "ORIGIN=https://tatort.innovation-hub-niedersachsen.de node build/index.js"]
|
||||
|
||||
137
Jenkinsfile
vendored
Normal file
137
Jenkinsfile
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
/* groovylint-disable-next-line UnusedVariable */
|
||||
@Library('InnoHub-Library') _
|
||||
|
||||
def didRun = false
|
||||
def versionTag = 'null'
|
||||
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
tools {
|
||||
nodejs 'NodeJS-24.2.0'
|
||||
}
|
||||
|
||||
environment {
|
||||
REGISTRY = 'https://gitea.innovation-hub-niedersachsen.de/'
|
||||
USER = 'jenkins'
|
||||
TOKEN = credentials('JenkinsGitea')
|
||||
}
|
||||
|
||||
parameters {
|
||||
string(name: 'REPO_NAME', defaultValue: '', description: 'Repo Name')
|
||||
string(name: 'GIT_REF', defaultValue: '', description: 'Git Ref')
|
||||
}
|
||||
|
||||
options {
|
||||
buildDiscarder(
|
||||
BuildHistoryManager([
|
||||
[ continueAfterMatch: false, matchAtMost: 5 ],
|
||||
[ actions: [ DeleteBuild() ] ]
|
||||
])
|
||||
)
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Set Version Tag') {
|
||||
steps {
|
||||
script {
|
||||
versionTag = generateVersionTag(params.GIT_REF)
|
||||
echo "[INFO] Using VERSION_TAG: ${versionTag}"
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Validate Repository') {
|
||||
steps {
|
||||
script {
|
||||
checkRepoName(params.REPO_NAME, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Install Dependencies') {
|
||||
steps {
|
||||
script {
|
||||
didRun = true
|
||||
}
|
||||
sh 'npm ci'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Test & Security Audit') {
|
||||
steps {
|
||||
script {
|
||||
didRun = true
|
||||
}
|
||||
echo 'Start checking security vulnerabilities in npm packages'
|
||||
sh 'npm audit --audit-level=moderate'
|
||||
}
|
||||
}
|
||||
|
||||
stage('SonarQube Analysis') {
|
||||
steps {
|
||||
withSonarQubeEnv('sonarqube') {
|
||||
sh 'sonar-scanner -Dsonar.projectKey=tatort -Dsonar.sources=src'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Push image to gitea registry') {
|
||||
when {
|
||||
branch 'development'
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
def imageName = "gitea.innovation-hub-niedersachsen.de/innohub/tatort-dev"
|
||||
|
||||
docker.withRegistry(REGISTRY, 'JenkinsGitea') {
|
||||
def img = docker.build("${imageName}:${versionTag}", '-f Dockerfile.dev .')
|
||||
img.push()
|
||||
img.push('latest')
|
||||
}
|
||||
|
||||
didRun = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Update Helm Chart Repository') {
|
||||
when {
|
||||
branch 'development'
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
updateHelmChart([
|
||||
tag: versionTag,
|
||||
repoUrl: 'gitea.innovation-hub-niedersachsen.de/innohub/charts.git',
|
||||
chartPath: 'tatort-dev/tatort',
|
||||
chartName: 'tatort',
|
||||
imageRepo: 'gitea.innovation-hub-niedersachsen.de/innohub/tatort-dev',
|
||||
credentialsId: 'JenkinsGitea',
|
||||
branch: 'main'
|
||||
])
|
||||
|
||||
didRun = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
success {
|
||||
script {
|
||||
if (didRun) {
|
||||
echo 'Pipeline erfolgreich!'
|
||||
discordSend description: "Running ${env.BUILD_ID} on ${env.JENKINS_URL}, ${params.GIT_REF}", footer: 'Pipeline succeeded', link: env.BUILD_URL, result: currentBuild.currentResult, title: env.JOB_NAME, webhookURL: 'https://discordapp.com/api/webhooks/1389470542691831819/NdMO17sLBG2dplp_-oh6Ff0cbPOoADl0QwXKM9UzduxU44av_ZQkQjKTmpdK7YuwcZDc'
|
||||
}
|
||||
}
|
||||
}
|
||||
failure {
|
||||
script {
|
||||
if (didRun) {
|
||||
echo 'Pipeline fehlgeschlagen!'
|
||||
discordSend description: "Running ${env.BUILD_ID} on ${env.JENKINS_URL}, ${params.GIT_REF}", footer: 'Pipeline failed', link: env.BUILD_URL, result: currentBuild.currentResult, title: env.JOB_NAME, webhookURL: 'https://discordapp.com/api/webhooks/1389470542691831819/NdMO17sLBG2dplp_-oh6Ff0cbPOoADl0QwXKM9UzduxU44av_ZQkQjKTmpdK7YuwcZDc'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
README.md
21
README.md
@@ -36,3 +36,24 @@ 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://svelte.dev/docs/kit/adapters) for your target environment.
|
||||
|
||||
## Initializing the SQLite DB
|
||||
|
||||
A database initialization script `init_db.ts` in included in the `src/init` folder. It will create a users database (if not existing) and populate it with a default admin user. Additionally, an empty cases table will be created.
|
||||
|
||||
It can be run with `node init_db.ts`
|
||||
|
||||
Database schema:
|
||||
|
||||
Users
|
||||
|
||||
- id
|
||||
- name
|
||||
- pw
|
||||
|
||||
Cases
|
||||
|
||||
- id
|
||||
- token
|
||||
- name
|
||||
- pin
|
||||
|
||||
10
config.json
10
config.json
@@ -1,17 +1,17 @@
|
||||
{
|
||||
"minio": {
|
||||
"endPoint": "api-s3.innovation-hub-niedersachsen.de",
|
||||
"endPoint": "sws3.innovation-hub-niedersachsen.de",
|
||||
"port": 443,
|
||||
"useSSL": true,
|
||||
"accessKey": "GxKhfnfkNvlDU7qzsz0D",
|
||||
"secretKey": "cqSM5rIRr4MPtqzu2sNKgmB9k2OghPbyxwAWogeM"
|
||||
"accessKey": "wjpKrmaqXra99rX3D61H",
|
||||
"secretKey": "fTPi0u0FR6Lv9Y9IKydWv6WM0EA5XrsK008HCt9u"
|
||||
},
|
||||
"jwt": {
|
||||
"secret": "@S2!q@@wXz$dCQ8JoVsHLpzaJ6JCfB",
|
||||
"expiresIn": 36000
|
||||
"expiresIn": 3600
|
||||
},
|
||||
"auth": {
|
||||
"admin": { "password": "A-InnoHUB_2025!", "admin": true },
|
||||
"user": { "password": "U-InnoHUB_2025!", "admin": false }
|
||||
}
|
||||
}
|
||||
}
|
||||
17
config_dev.json
Normal file
17
config_dev.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"minio": {
|
||||
"endPoint": "sws3.innovation-hub-niedersachsen.de",
|
||||
"port": 443,
|
||||
"useSSL": true,
|
||||
"accessKey": "wjpKrmaqXra99rX3D61H",
|
||||
"secretKey": "fTPi0u0FR6Lv9Y9IKydWv6WM0EA5XrsK008HCt9u"
|
||||
},
|
||||
"jwt": {
|
||||
"secret": "@S2!q@@wXz$dCQ8JoVsHLpzaJ6JCfB",
|
||||
"expiresIn": 3600
|
||||
},
|
||||
"auth": {
|
||||
"admin": { "password": "A-InnoHUB_2025!", "admin": true },
|
||||
"user": { "password": "U-InnoHUB_2025!", "admin": false }
|
||||
}
|
||||
}
|
||||
17
config_prod.json
Normal file
17
config_prod.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"minio": {
|
||||
"endPoint": "api-s3.innovation-hub-niedersachsen.de",
|
||||
"port": 443,
|
||||
"useSSL": true,
|
||||
"accessKey": "GxKhfnfkNvlDU7qzsz0D",
|
||||
"secretKey": "cqSM5rIRr4MPtqzu2sNKgmB9k2OghPbyxwAWogeM"
|
||||
},
|
||||
"jwt": {
|
||||
"secret": "@S2!q@@wXz$dCQ8JoVsHLpzaJ6JCfB",
|
||||
"expiresIn": 3600
|
||||
},
|
||||
"auth": {
|
||||
"admin": { "password": "A-InnoHUB_2025!", "admin": true },
|
||||
"user": { "password": "U-InnoHUB_2025!", "admin": false }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
test('home page has expected h1', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
await expect(page.locator('h1')).toBeVisible();
|
||||
});
|
||||
@@ -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'],
|
||||
|
||||
3239
package-lock.json
generated
3239
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
50
package.json
50
package.json
@@ -14,40 +14,46 @@
|
||||
"lint": "prettier --check . && eslint .",
|
||||
"test:unit": "vitest",
|
||||
"test": "npm run test:unit -- --run && npm run test:e2e",
|
||||
"test:e2e": "playwright test"
|
||||
"init-db": "tsx ./src/init/init_db.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^1.2.5",
|
||||
"@eslint/compat": "^1.2.9",
|
||||
"@eslint/js": "^9.18.0",
|
||||
"@playwright/test": "^1.49.1",
|
||||
"@sveltejs/adapter-auto": "^4.0.0",
|
||||
"@sveltejs/kit": "^2.16.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|
||||
"@sveltejs/kit": "^2.21.3",
|
||||
"@sveltejs/vite-plugin-svelte": "^5.1.0",
|
||||
"@testing-library/jest-dom": "^6.6.3",
|
||||
"@testing-library/svelte": "^5.2.4",
|
||||
"eslint": "^9.18.0",
|
||||
"eslint-config-prettier": "^10.0.1",
|
||||
"eslint-plugin-svelte": "^3.0.0",
|
||||
"globals": "^16.0.0",
|
||||
"jsdom": "^26.0.0",
|
||||
"prettier": "^3.4.2",
|
||||
"prettier-plugin-svelte": "^3.3.3",
|
||||
"svelte": "^5.0.0",
|
||||
"svelte-check": "^4.0.0",
|
||||
"typescript": "^5.0.0",
|
||||
"typescript-eslint": "^8.20.0",
|
||||
"vite": "^6.2.5",
|
||||
"vitest": "^3.0.0"
|
||||
"@testing-library/svelte": "^5.2.8",
|
||||
"@tsconfig/svelte": "^5.0.4",
|
||||
"@types/better-sqlite3": "^7.6.13",
|
||||
"@types/jsonwebtoken": "^9.0.9",
|
||||
"eslint": "^9.28.0",
|
||||
"eslint-config-prettier": "^10.1.5",
|
||||
"eslint-plugin-svelte": "^3.9.2",
|
||||
"globals": "^16.2.0",
|
||||
"jsdom": "^26.1.0",
|
||||
"prettier": "^3.5.3",
|
||||
"prettier-plugin-svelte": "^3.4.0",
|
||||
"svelte": "^5.33.18",
|
||||
"svelte-check": "^4.2.1",
|
||||
"tsx": "^4.20.3",
|
||||
"typescript": "^5.8.3",
|
||||
"typescript-eslint": "^8.34.0",
|
||||
"vite": "^6.3.5",
|
||||
"vitest": "^3.2.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@google/model-viewer": "^4.1.0",
|
||||
"@sveltejs/adapter-node": "^5.2.12",
|
||||
"@tailwindcss/forms": "^0.5.10",
|
||||
"autoprefixer": "^10.4.21",
|
||||
"better-sqlite3": "^12.2.0",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"jssha": "^3.3.1",
|
||||
"minio": "^8.0.5",
|
||||
"postcss": "^8.5.3",
|
||||
"svelte-cubed": "^0.2.1",
|
||||
"tailwindcss": "^3.4.17"
|
||||
"postcss": "^8.5.4",
|
||||
"sqlite3": "^5.1.7",
|
||||
"tailwindcss": "^3.4.17",
|
||||
"uuid": "^11.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
/** @type {import('@playwright/test').PlaywrightTestConfig} */
|
||||
const config = {
|
||||
webServer: {
|
||||
command: 'npm run build && npm run preview',
|
||||
port: 4173
|
||||
},
|
||||
testDir: 'tests',
|
||||
testMatch: /(.+\.)?(test|spec)\.[jt]s/
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -1,9 +0,0 @@
|
||||
import { defineConfig } from '@playwright/test';
|
||||
|
||||
export default defineConfig({
|
||||
webServer: {
|
||||
command: 'npm run build && npm run preview',
|
||||
port: 4173
|
||||
},
|
||||
testDir: 'e2e'
|
||||
});
|
||||
@@ -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 = async ({ 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 await resolve(event);
|
||||
36
src/init/init_db.ts
Normal file
36
src/init/init_db.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import Database from 'better-sqlite3';
|
||||
import jsSHA from 'jssha';
|
||||
|
||||
const db = new Database('./src/lib/data/tatort.db');
|
||||
|
||||
let createSQLStmt = `CREATE TABLE IF NOT EXISTS users
|
||||
(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
pw TEXT NOT NULL)`;
|
||||
db.exec(createSQLStmt);
|
||||
|
||||
// check if there are any users; if not add one default admin one
|
||||
const userPassword = 'A-InnoHUB_2025!';
|
||||
const hashedUserPassword = new jsSHA('SHA-512', 'TEXT').update(userPassword).getHash('HEX');
|
||||
const checkInsertSQLStmt = `INSERT INTO users (name, pw) SELECT 'admin', '${hashedUserPassword}'
|
||||
WHERE NOT EXISTS (SELECT * FROM users);`;
|
||||
|
||||
db.exec(checkInsertSQLStmt);
|
||||
|
||||
const usersSQLStmt = `SELECT * FROM USERS`;
|
||||
let SQLStatement = db.prepare(usersSQLStmt);
|
||||
|
||||
// cases table
|
||||
|
||||
createSQLStmt = `CREATE TABLE IF NOT EXISTS cases
|
||||
(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
token TEXT NOT NULL UNIQUE,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
pin TEXT NOT NULL)`;
|
||||
|
||||
db.exec(createSQLStmt);
|
||||
|
||||
const vorgangSQLStmt = `SELECT * FROM cases`;
|
||||
SQLStatement = db.prepare(vorgangSQLStmt);
|
||||
|
||||
db.close();
|
||||
@@ -1,29 +0,0 @@
|
||||
import jwt from 'jsonwebtoken';
|
||||
|
||||
import config from '$lib/config';
|
||||
|
||||
const SECRET = config.jwt.secret;
|
||||
const EXPIRES_IN = config.jwt.expiresIn;
|
||||
|
||||
const AUTH = config.auth;
|
||||
|
||||
export function createToken(userData) {
|
||||
return jwt.sign(userData, SECRET, { expiresIn: EXPIRES_IN });
|
||||
}
|
||||
|
||||
export function decryptToken(token) {
|
||||
return jwt.verify(token, SECRET);
|
||||
}
|
||||
|
||||
export function authenticate(user, pass) {
|
||||
let userData = null;
|
||||
|
||||
if (AUTH[user]) {
|
||||
const { password, ...data } = AUTH[user];
|
||||
if (password && password === pass) userData = data;
|
||||
}
|
||||
|
||||
if (userData == null) return null;
|
||||
|
||||
return createToken({ id: user, ...userData });
|
||||
}
|
||||
34
src/lib/auth.ts
Normal file
34
src/lib/auth.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import jwt from 'jsonwebtoken';
|
||||
import jsSHA from 'jssha';
|
||||
import { db } from '$lib/server/dbService';
|
||||
|
||||
import config from '$lib/config';
|
||||
|
||||
const SECRET = config.jwt.secret;
|
||||
const EXPIRES_IN = config.jwt.expiresIn;
|
||||
|
||||
|
||||
export function createToken(userData) {
|
||||
return jwt.sign(userData, SECRET, { expiresIn: EXPIRES_IN });
|
||||
}
|
||||
|
||||
export function decryptToken(token: string) {
|
||||
return jwt.verify(token, SECRET);
|
||||
}
|
||||
|
||||
export function authenticate(user, password) {
|
||||
let JWTToken;
|
||||
|
||||
// hash user password
|
||||
const hashedPW = new jsSHA('SHA-512', 'TEXT').update(password).getHash('HEX');
|
||||
|
||||
const getUserSQLStmt = 'SELECT name, pw FROM users WHERE name = ?';
|
||||
const row = db.prepare(getUserSQLStmt).get(user);
|
||||
const storedPW = row.pw;
|
||||
|
||||
if (hashedPW && hashedPW === storedPW) {
|
||||
JWTToken = createToken({ id: user, admin: true });
|
||||
}
|
||||
|
||||
return JWTToken;
|
||||
}
|
||||
@@ -46,7 +46,7 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
<script lang="ts">
|
||||
export let type = 'info';
|
||||
let classNames = '';
|
||||
export { classNames as class };
|
||||
32
src/lib/components/BaseInputField.svelte
Normal file
32
src/lib/components/BaseInputField.svelte
Normal file
@@ -0,0 +1,32 @@
|
||||
<script lang="ts">
|
||||
import Exclamation from '$lib/icons/Exclamation.svelte';
|
||||
|
||||
let { label = '', error = null, value, name, id, type = 'text'} = $props();
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<label for={name} class="block text-sm font-medium leading-6 text-gray-900"
|
||||
><span class="flex"
|
||||
>{#if error}
|
||||
<span class="inline-block mr-1"><Exclamation /></span>
|
||||
{/if}
|
||||
{label}</span
|
||||
></label
|
||||
>
|
||||
<div class="mt-2">
|
||||
<div
|
||||
class="flex rounded-md shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-600"
|
||||
>
|
||||
<input
|
||||
class="block flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 text-sm leading-6"
|
||||
bind:value
|
||||
{type}
|
||||
{name}
|
||||
{id}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{#if error}
|
||||
<p class="block text-sm leading-6 text-red-900 mt-2">{error}</p>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -173,7 +173,7 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
<script lang="ts">
|
||||
export let href = null;
|
||||
export let type = 'button';
|
||||
export let size = 'md';
|
||||
@@ -11,11 +11,11 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores';
|
||||
import Trash from '$lib/icons/Trash.svelte';
|
||||
import Panel from '$lib/components/ui/Panel.svelte';
|
||||
import Button from '$lib/components/ui/Button.svelte';
|
||||
import Panel from '$lib/components/Panel.svelte';
|
||||
import Button from '$lib/components/Button.svelte';
|
||||
import { clickOutside } from '$lib/helpers/clickOutside.js';
|
||||
const { adminMode, prediction, predictionRemove } = $page.data;
|
||||
|
||||
37
src/lib/components/Footer.svelte
Normal file
37
src/lib/components/Footer.svelte
Normal file
@@ -0,0 +1,37 @@
|
||||
<script>
|
||||
import Profile from "$lib/icons/Profile.svelte";
|
||||
|
||||
export let data;
|
||||
</script>
|
||||
|
||||
<div class="flex-none">
|
||||
<footer class="justify-end">
|
||||
<div class="bg-gray-100">
|
||||
<div class="mx-auto max-w-7xl px-6 lg:px-8">
|
||||
<div class="flex justify-between divide-x divide-gray-900/5 border-x border-gray-900/5">
|
||||
<a
|
||||
href="/list"
|
||||
class="px-4 py-1 -ml-4 flex items-center justify-center gap-x-2.5 text-sm font-semibold leading-6 text-gray-500 hover:bg-gray-200 hover:text-gray-700"
|
||||
>
|
||||
© 2023 Innovation Hub Niedersachen
|
||||
</a>
|
||||
<a
|
||||
href="/"
|
||||
class="px-4 py-1 flex items-center justify-center gap-x-2.5 text-sm font-semibold leading-6 text-gray-500 hover:bg-gray-200 hover:text-gray-700"
|
||||
>
|
||||
back
|
||||
</a>
|
||||
<a
|
||||
href="/"
|
||||
class="px-4 py-1 -mr-4 flex items-center justify-center gap-x-2.5 text-sm font-semibold leading-6 text-gray-500 hover:bg-gray-200 hover:text-gray-700"
|
||||
>
|
||||
<!--icon-->
|
||||
<Profile />
|
||||
|
||||
{data?.user?.id}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
36
src/lib/components/Header.svelte
Normal file
36
src/lib/components/Header.svelte
Normal file
@@ -0,0 +1,36 @@
|
||||
<script lang="ts">
|
||||
import Chevron from '$lib/icons/Chevron-right.svelte';
|
||||
|
||||
export let data;
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col">
|
||||
<header class="flex-none relative isolate z-10 bg-white px-8">
|
||||
<nav
|
||||
class="mx-auto flex max-w-7xl items-center justify-between p-6 lg:px-8"
|
||||
aria-label="Global"
|
||||
>
|
||||
<div class="flex w-48">
|
||||
<a href="/" class="-m-1.5 p-1.5 w-10">
|
||||
<span class="sr-only">Tatort Niedersachen</span>
|
||||
<img class="h-8 w-auto" src="/Landeswappen_NI.svg" alt="Landeswappen Niedersachsen" />
|
||||
</a>
|
||||
</div>
|
||||
<h1 class="text-3xl text-slate-400 font-bold">Tatort</h1>
|
||||
<div class="lg:flex lg:justify-end w-48">
|
||||
{#if data.user}
|
||||
<form method="POST" action="/anmeldung?/logout">
|
||||
<input type="hidden" />
|
||||
<button type="submit" class="text-sm font-semibold leading-6 text-gray-900"
|
||||
><span
|
||||
><span class="align-middle inline-block">Abmelden</span><span
|
||||
class="align-middle inline-block"><Chevron /></span
|
||||
></span
|
||||
></button
|
||||
>
|
||||
</form>
|
||||
{/if}
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
</div>
|
||||
@@ -41,7 +41,7 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
<script lang="ts">
|
||||
import { fade } from 'svelte/transition';
|
||||
export let size = 'xl'; // https://tailwindcss.com/docs/max-width#class-reference
|
||||
export let open = false;
|
||||
@@ -15,7 +15,7 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
<script lang="ts">
|
||||
export let scroll = true;
|
||||
export let padding = true;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script>
|
||||
<script lang="ts">
|
||||
export let title = 'Erfolgreich';
|
||||
export let show = false;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
<script lang="ts">
|
||||
export let padding = 'p-6';
|
||||
export let shadow = true;
|
||||
let classNames = '';
|
||||
@@ -6,7 +6,7 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
<script lang="ts">
|
||||
import { clickOutside } from '$lib/helpers/clickOutside.js';
|
||||
import Check from '$lib/icons/Check.svelte';
|
||||
import Selector from '$lib/icons/Selector.svelte';
|
||||
@@ -1,3 +0,0 @@
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
export default JSON.parse(readFileSync('./config.json'));
|
||||
3
src/lib/config.ts
Normal file
3
src/lib/config.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
export default JSON.parse(readFileSync('./config.json').toString());
|
||||
BIN
src/lib/data/tatort.db
Normal file
BIN
src/lib/data/tatort.db
Normal file
Binary file not shown.
@@ -1,22 +0,0 @@
|
||||
import { client } from '$lib/minio';
|
||||
|
||||
/**
|
||||
* Check if caseNumber is used
|
||||
* @param {string} caseNumber
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
export default async function caseNumberOccupied(caseNumber) {
|
||||
const prefix = `${caseNumber}/config.json`;
|
||||
const promise = new Promise((resolve) => {
|
||||
let stream = client.listObjectsV2('tatort', prefix, false, '');
|
||||
stream.on('data', () => {
|
||||
stream.destroy();
|
||||
resolve(true);
|
||||
});
|
||||
stream.on('end', () => {
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
17
src/lib/helper/vorgangNumberOccupied.ts
Normal file
17
src/lib/helper/vorgangNumberOccupied.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { client } from '$lib/minio';
|
||||
|
||||
export default async function vorgangNumberOccupied (vorgangNumber: string): Promise<boolean> {
|
||||
const prefix = `${vorgangNumber}`;
|
||||
const promise: Promise<boolean> = new Promise((resolve) => {
|
||||
const stream = client.listObjectsV2('tatort', prefix, false, '');
|
||||
stream.on('data', () => {
|
||||
stream.destroy();
|
||||
resolve(true);
|
||||
});
|
||||
stream.on('end', () => {
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
@@ -6,3 +6,7 @@ import config from '$lib/config';
|
||||
|
||||
/** export const client = new Minio.Client(config.minio); */
|
||||
export const client = new Client(config.minio);
|
||||
|
||||
export const BUCKET = 'tatort';
|
||||
export const TOKENFILENAME = '__perm__';
|
||||
export const CONFIGFILENAME = 'config.json';
|
||||
29
src/lib/server/authService.ts
Normal file
29
src/lib/server/authService.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { dev } from '$app/environment';
|
||||
import { fail, redirect, type Cookies, type RequestEvent } from '@sveltejs/kit';
|
||||
import { authenticate } from '$lib/auth';
|
||||
|
||||
const COOKIE_NAME = 'session';
|
||||
|
||||
export const loginUser = async ({ request, cookies }: { request: Request; cookies: Cookies }) => {
|
||||
const data = await request.formData();
|
||||
const user = data.get('user');
|
||||
const password = data.get('password');
|
||||
|
||||
const token = authenticate(user, password);
|
||||
|
||||
if (!token) return fail(400, { user, incorrect: true });
|
||||
|
||||
cookies.set(COOKIE_NAME, token, {
|
||||
path: '/',
|
||||
httpOnly: true,
|
||||
sameSite: 'strict',
|
||||
secure: !dev
|
||||
});
|
||||
return redirect(303, '/');
|
||||
};
|
||||
|
||||
export const logoutUser = async (event: RequestEvent) => {
|
||||
event.cookies.delete(COOKIE_NAME, { path: '/' });
|
||||
event.locals.user = null;
|
||||
return { success: true };
|
||||
};
|
||||
3
src/lib/server/dbService.ts
Normal file
3
src/lib/server/dbService.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import Database from 'better-sqlite3';
|
||||
|
||||
export const db = new Database('./src/lib/data/tatort.db');
|
||||
27
src/lib/server/s3ClientService.ts
Normal file
27
src/lib/server/s3ClientService.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { BUCKET, client } from '$lib/minio';
|
||||
|
||||
export const checkIfExactDirectoryExists = (dir: string): Promise<boolean> => {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
const prefix = dir.endsWith('/') ? dir : `${dir}/`;
|
||||
|
||||
const stream = client.listObjectsV2(BUCKET, prefix, false, '');
|
||||
|
||||
stream.on('data', (obj) => {
|
||||
if (obj.prefix === undefined && obj.name.startsWith(prefix)) {
|
||||
stream.destroy();
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
|
||||
stream.on('error', (err) => reject(err));
|
||||
|
||||
stream.on('end', () => resolve(false));
|
||||
});
|
||||
};
|
||||
|
||||
export const getContentOfTextObject = async (bucket: string, objPath: string) => {
|
||||
const res = await client.getObject(bucket, objPath);
|
||||
|
||||
const text = await new Response(res).text();
|
||||
return text;
|
||||
};
|
||||
189
src/lib/server/vorgangService.ts
Normal file
189
src/lib/server/vorgangService.ts
Normal file
@@ -0,0 +1,189 @@
|
||||
import { fail } from '@sveltejs/kit';
|
||||
import { BUCKET, client, CONFIGFILENAME, TOKENFILENAME } from '$lib/minio';
|
||||
import { checkIfExactDirectoryExists, getContentOfTextObject } from './s3ClientService';
|
||||
|
||||
import { db } from './dbService';
|
||||
|
||||
/**
|
||||
* Get Vorgang and corresponend list of tatorte
|
||||
* @param vorgangToken
|
||||
* @returns
|
||||
*/
|
||||
export const getCrimesListByToken = async (vorgangToken: string) => {
|
||||
const prefix = `${vorgangToken}/`;
|
||||
|
||||
const stream = client.listObjectsV2(BUCKET, prefix, false, '');
|
||||
|
||||
const list = [];
|
||||
for await (const chunk of stream) {
|
||||
const splittedNameParts = chunk.name.split('/');
|
||||
const prefix = splittedNameParts[0];
|
||||
const name = splittedNameParts[1];
|
||||
|
||||
if (name === CONFIGFILENAME || name === TOKENFILENAME) continue;
|
||||
list.push({ ...chunk, name: name, prefix: prefix, show_button: true });
|
||||
}
|
||||
return list;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Vorgang
|
||||
* @param vorgangToken
|
||||
* @returns vorgangObj with keys `token`, `name`, `pin` || undefined
|
||||
*/
|
||||
export const getVorgangByToken = (vorgangToken: string): {token: string, name:string, pin: string} | undefined => {
|
||||
const getVorgangSQLStmt = `SELECT token, name, pin FROM cases WHERE token = ?`;
|
||||
const statement = db.prepare(getVorgangSQLStmt);
|
||||
const result = statement.get(vorgangToken) as {token: string, name:string, pin: string} | undefined;
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Vorgang
|
||||
* @param vorgangName
|
||||
* @returns vorgangObj with keys `token`, `name`, `pin` || undefined
|
||||
*/
|
||||
export const getVorgangByName = (vorgangName: string): {token: string, name: string, pin: string} | undefined => {
|
||||
const getVorgangByNameSQLStmt = `SELECT token, name, pin FROM cases WHERE name = ?`;
|
||||
const statement = db.prepare(getVorgangByNameSQLStmt);
|
||||
const result = statement.get(vorgangName) as {token: string, name: string, pin: string} | undefined;
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete Vorgang
|
||||
* @param vorgangToken
|
||||
* @returns int: number of changes
|
||||
*/
|
||||
export const deleteVorgangByToken = function (vorgangToken: string) {
|
||||
const deleteSQLStmt = 'DELETE FROM cases WHERE token = ?';
|
||||
const statement = db.prepare(deleteSQLStmt);
|
||||
const info = statement.run(vorgangToken);
|
||||
|
||||
return info.changes;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetches list of vorgänge from s3 bucket
|
||||
* @returns list of available vorgaenge
|
||||
*/
|
||||
export const getListOfVorgänge = async () => {
|
||||
const stream = client.listObjectsV2(BUCKET, '', false, '');
|
||||
|
||||
const list = [];
|
||||
for await (const chunk of stream) {
|
||||
const objPath = `${chunk.prefix}${TOKENFILENAME}`;
|
||||
|
||||
const token = await getContentOfTextObject(BUCKET, objPath);
|
||||
|
||||
const cleanedChunkPrefix = chunk.prefix.replace(/\/$/, '');
|
||||
list.push({ name: cleanedChunkPrefix, token: token });
|
||||
}
|
||||
return list;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetches list of vorgänge from database
|
||||
* @returns list with of available vorgaenge
|
||||
*/
|
||||
export const getVorgaenge = (): {vorgangToken: string, vorgangName: string, vorgangPIN: string}[] => {
|
||||
const getVorgaengeSQLStmt = `SELECT token, name, pin from cases`;
|
||||
const statement = db.prepare(getVorgaengeSQLStmt);
|
||||
const result = statement.all() as { token: string; name: string; pin: string }[];
|
||||
const vorgaenge_list: {vorgangToken: string, vorgangName: string, vorgangPIN: string}[] = [];
|
||||
for (const resultItem of result) {
|
||||
const vorg = { vorgangToken: resultItem.token, vorgangName: resultItem.name, vorgangPIN: resultItem.pin };
|
||||
vorgaenge_list.push(vorg);
|
||||
}
|
||||
|
||||
return vorgaenge_list;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if Vorgang exists
|
||||
* @param request
|
||||
* @returns fail or true
|
||||
*/
|
||||
export const checkIfVorgangExists = async (vorgangId: string | null) => {
|
||||
if (!vorgangId) {
|
||||
return fail(400, {
|
||||
success: false,
|
||||
vorgangId,
|
||||
error: { message: 'Die Vorgangsnummer darf nicht leer sein.' }
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof vorgangId === 'string' && !(await checkIfExactDirectoryExists(vorgangId))) {
|
||||
return fail(400, {
|
||||
success: false,
|
||||
vorgangId,
|
||||
error: { message: 'Die Vorgangsnummer existiert in dieser Anwendung nicht.' }
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export const vorgangExists = function (vorgangToken: string | null) {
|
||||
if (!vorgangToken) {
|
||||
return fail(400, {
|
||||
success: false,
|
||||
vorgangId: vorgangToken,
|
||||
error: { message: 'Die Vorgangsnummer darf nicht leer sein.' }
|
||||
});
|
||||
}
|
||||
|
||||
const vorgaenge = getVorgaenge();
|
||||
const vorgaengeTokens = vorgaenge.map((vorgang) => vorgang.vorgangToken);
|
||||
|
||||
const found = vorgaengeTokens.indexOf(vorgangToken) != -1;
|
||||
|
||||
return found;
|
||||
};
|
||||
|
||||
export const vorgangNameExists = (vorgangName: string) => {
|
||||
const vorgaenge = getVorgaenge();
|
||||
const vorgaengeNames = vorgaenge.map((vorgang) => vorgang.vorgangName);
|
||||
|
||||
const found = vorgaengeNames.indexOf(vorgangName) != -1;
|
||||
|
||||
return found;
|
||||
};
|
||||
|
||||
export const hasValidToken = async (vorgangId: string, vorgangToken: string) => {
|
||||
const objPath = `${vorgangId}/${TOKENFILENAME}`;
|
||||
|
||||
try {
|
||||
if (!vorgangToken) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const token = await getContentOfTextObject(BUCKET, objPath);
|
||||
if (!token || token !== vorgangToken) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (error.name == 'S3Error') {
|
||||
console.log(error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const vorgangPINValidation = function (vorgangToken: string, vorgangPIN: string) {
|
||||
if (!vorgangPIN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const vorgang = getVorgangByToken(vorgangToken);
|
||||
|
||||
if (!vorgang || vorgang.pin !== vorgangPIN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
/** @type {import('./$types').PageServerLoad} */
|
||||
export function load(event) {
|
||||
if (!event.locals.user && event.url.pathname !== '/anmeldung') throw redirect(303, '/anmeldung');
|
||||
return {
|
||||
user: event.locals.user
|
||||
};
|
||||
}
|
||||
10
src/routes/(angemeldet)/+layout.server.ts
Normal file
10
src/routes/(angemeldet)/+layout.server.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { redirect, type ServerLoadEvent } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from '../anmeldung/$types';
|
||||
|
||||
export const load: PageServerLoad = (event: ServerLoadEvent) => {
|
||||
if (!event.locals.user && event.url.pathname !== '/anmeldung') throw redirect(303, '/anmeldung');
|
||||
return {
|
||||
user: event.locals.user
|
||||
|
||||
};
|
||||
}
|
||||
@@ -1,74 +1,18 @@
|
||||
<script>
|
||||
import Chevron from '$lib/icons/Chevron-right.svelte';
|
||||
import Login from '$lib/icons/Login.svelte';
|
||||
import Profile from '$lib/icons/Profile.svelte';
|
||||
<script lang="ts">
|
||||
import Footer from '$lib/components/Footer.svelte';
|
||||
import Header from '$lib/components/Header.svelte';
|
||||
|
||||
export let data;
|
||||
</script>
|
||||
|
||||
<div class="h-screen v-screen flex flex-col">
|
||||
<div class="flex flex-col h-full">
|
||||
<header class="flex-none relative isolate z-10 bg-white px-8">
|
||||
<nav
|
||||
class="mx-auto flex max-w-7xl items-center justify-between p-6 lg:px-8"
|
||||
aria-label="Global"
|
||||
>
|
||||
<div class="flex w-48">
|
||||
<a href="/" class="-m-1.5 p-1.5 w-10">
|
||||
<span class="sr-only">Tatort Niedersachen</span>
|
||||
<img class="h-8 w-auto" src="/Landeswappen_NI.svg" alt="Landeswappen Niedersachsen" />
|
||||
</a>
|
||||
</div>
|
||||
<h1 class="text-3xl text-slate-400 font-bold">Tatort</h1>
|
||||
<div class="lg:flex lg:justify-end w-48">
|
||||
{#if data.user}
|
||||
<form method="POST" action="/anmeldung?/logout">
|
||||
<input type="hidden" />
|
||||
<button type="submit" class="text-sm font-semibold leading-6 text-gray-900"
|
||||
><span
|
||||
><span class="align-middle inline-block">Abmelden</span><span
|
||||
class="align-middle inline-block"><Chevron /></span
|
||||
></span
|
||||
></button
|
||||
>
|
||||
</form>
|
||||
{/if}
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<Header {data}/>
|
||||
|
||||
<div class="h-full grow overflow-scroll">
|
||||
<slot />
|
||||
</div>
|
||||
<div class="flex-none">
|
||||
<footer class="justify-end">
|
||||
<div class="bg-gray-100">
|
||||
<div class="mx-auto max-w-7xl px-6 lg:px-8">
|
||||
<div class="flex justify-between divide-x divide-gray-900/5 border-x border-gray-900/5">
|
||||
<a
|
||||
href="/list"
|
||||
class="px-4 py-1 -ml-4 flex items-center justify-center gap-x-2.5 text-sm font-semibold leading-6 text-gray-500 hover:bg-gray-200 hover:text-gray-700"
|
||||
>
|
||||
© 2023 Innovation Hub Niedersachen
|
||||
</a>
|
||||
<a
|
||||
href="/"
|
||||
class="px-4 py-1 flex items-center justify-center gap-x-2.5 text-sm font-semibold leading-6 text-gray-500 hover:bg-gray-200 hover:text-gray-700"
|
||||
>
|
||||
back
|
||||
</a>
|
||||
<a
|
||||
href="/"
|
||||
class="px-4 py-1 -mr-4 flex items-center justify-center gap-x-2.5 text-sm font-semibold leading-6 text-gray-500 hover:bg-gray-200 hover:text-gray-700"
|
||||
>
|
||||
<!--icon-->
|
||||
<Profile />
|
||||
<Footer {data}/>
|
||||
|
||||
{data.user.id}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<script>
|
||||
import Panel from '$lib/components/ui/Panel.svelte';
|
||||
<script lang="ts">
|
||||
import AddProcess from '$lib/icons/Add-Process.svelte';
|
||||
import FileRect from '$lib/icons/File-rect.svelte';
|
||||
import ListIcon from '$lib/icons/List-icon.svelte';
|
||||
|
||||
|
||||
export let data;
|
||||
export let outline = true;
|
||||
</script>
|
||||
@@ -28,33 +28,6 @@
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
<!--{#if data.user.admin}
|
||||
<div class="group relative rounded-lg p-6 text-sm leading-6 hover:bg-gray-50 w-1/4">
|
||||
<div
|
||||
class="flex h-11 w-11 items-center justify-center rounded-lg bg-gray-50 group-hover:bg-white"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
class="w-6 h-6"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m3.75 9v6m3-3H9m1.5-12H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<a href="/tatorte" class="mt-6 block font-semibold text-gray-900">
|
||||
Neueer Vorgang
|
||||
<span class="absolute inset-0"></span>
|
||||
</a>
|
||||
<p class="mt-1 text-gray-600">Stelle einen weiteren Tatort für die Anwendung bereit.</p>
|
||||
</div>
|
||||
{/if}-->
|
||||
{#if data.user.admin}
|
||||
<div class="group relative rounded-lg p-6 text-sm leading-6 hover:bg-gray-50 w-1/4">
|
||||
<div
|
||||
@@ -85,4 +58,4 @@
|
||||
</div>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
</style>
|
||||
10
src/routes/(angemeldet)/list/+page.server.ts
Normal file
10
src/routes/(angemeldet)/list/+page.server.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { getVorgaenge } from '$lib/server/vorgangService';
|
||||
import type { PageServerLoad } from '../../(token-based)/view/$types';
|
||||
|
||||
export const load: PageServerLoad = async () => {
|
||||
const vorgangList = getVorgaenge();
|
||||
|
||||
return {
|
||||
vorgangList
|
||||
};
|
||||
};
|
||||
@@ -1,36 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import Trash from '$lib/icons/Trash.svelte';
|
||||
import Folder from '$lib/icons/Folder.svelte';
|
||||
import type { PageData } from '../$types';
|
||||
|
||||
/**
|
||||
* @type any[]
|
||||
*/
|
||||
let list: any[] = [];
|
||||
//$: list;
|
||||
export let data: PageData;
|
||||
|
||||
onMount(async () => {
|
||||
const response = await fetch('/api/list');
|
||||
const stream = await response.body;
|
||||
if (!stream) return;
|
||||
|
||||
const reader = stream.getReader();
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) return;
|
||||
|
||||
const objs = new TextDecoder()
|
||||
.decode(value)
|
||||
.split('\n')
|
||||
.filter((i) => i.length > 0)
|
||||
.map((i) => JSON.parse(i));
|
||||
|
||||
console.log(objs);
|
||||
list = list.concat(objs);
|
||||
}
|
||||
});
|
||||
const vorgangList = data.vorgangList;
|
||||
|
||||
async function delete_item(ev: Event) {
|
||||
let delete_item = window.confirm('Bist du sicher?');
|
||||
@@ -39,13 +14,12 @@
|
||||
const target = ev.currentTarget as HTMLElement | null;
|
||||
if (!target) return;
|
||||
let filename = target.id.split('del__')[1];
|
||||
|
||||
|
||||
// delete request
|
||||
// --------------
|
||||
|
||||
let url = `/api/list/${filename}`;
|
||||
|
||||
console.log(`--- ${filename} + ${url}`);
|
||||
try {
|
||||
const response = await fetch(url, { method: 'DELETE' });
|
||||
if (response.status == 204) {
|
||||
@@ -70,20 +44,20 @@
|
||||
</div>
|
||||
<div class="mx-auto flex justify-center max-w-7xl h-full">
|
||||
<ul role="list" class="divide-y divide-gray-100">
|
||||
{#each list as item}
|
||||
{#each vorgangList as vorgangItem}
|
||||
<li>
|
||||
<a href="/list/{item.name}" class="flex justify-between gap-x-6 py-5">
|
||||
<a href="/list/{vorgangItem.vorgangToken}?pin={vorgangItem.vorgangPIN}" class="flex justify-between gap-x-6 py-5">
|
||||
<div class="flex gap-x-4">
|
||||
<!-- Ordner -->
|
||||
<Folder />
|
||||
<div class="min-w-0 flex-auto">
|
||||
<span class="text-sm font-semibold leading-6 text-gray-900">{item.name}</span>
|
||||
<span class="text-sm font-semibold leading-6 text-gray-900">{vorgangItem.vorgangName}</span>
|
||||
<!-- Delete button -->
|
||||
<button
|
||||
style="padding: 2px"
|
||||
id="del__{item.name}"
|
||||
id="del__{vorgangItem.vorgangToken}"
|
||||
on:click|preventDefault={delete_item}
|
||||
aria-label="Vorgang {item.name} löschen"
|
||||
aria-label="Vorgang {vorgangItem.name} löschen"
|
||||
>
|
||||
<Trash />
|
||||
</button>
|
||||
|
||||
@@ -1,318 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { onMount, tick } from 'svelte';
|
||||
import shortenFileSize from '$lib/helper/shortenFileSize';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
import timeElapsed from '$lib/helper/timeElapsed';
|
||||
|
||||
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 Cube from '$lib/icons/Cube.svelte';
|
||||
import Edit from '$lib/icons/Edit.svelte';
|
||||
import Trash from '$lib/icons/Trash.svelte';
|
||||
|
||||
/** @type {import('./$types').PageData} */
|
||||
export let data;
|
||||
|
||||
console.log(`--- ${data.user.admin}`);
|
||||
|
||||
interface ListItem {
|
||||
name: string;
|
||||
size: number;
|
||||
lastModified: string | number | Date;
|
||||
show_button?: boolean;
|
||||
// add other properties as needed
|
||||
}
|
||||
|
||||
let list: ListItem[] = [];
|
||||
$: list;
|
||||
|
||||
let open = false;
|
||||
$: open;
|
||||
let inProgress = false;
|
||||
$: inProgress;
|
||||
let err = false;
|
||||
$: err;
|
||||
|
||||
let rename_input;
|
||||
$: rename_input;
|
||||
|
||||
onMount(async () => {
|
||||
const response = await fetch('/api/list/' + $page.params.vorgang);
|
||||
const stream = response.body;
|
||||
if (!stream) return;
|
||||
|
||||
const reader = stream.getReader();
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) return;
|
||||
|
||||
const objs = new TextDecoder()
|
||||
.decode(value)
|
||||
.split('\n')
|
||||
.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 text_field = document.getElementById(text_field_id);
|
||||
if (text_field) {
|
||||
text_field.setAttribute('contenteditable', 'false');
|
||||
text_field.textContent = item.name;
|
||||
}
|
||||
|
||||
// reshow button
|
||||
list[i].show_button = true;
|
||||
return;
|
||||
}
|
||||
|
||||
async function handle_input(ev: KeyboardEvent, i: number) {
|
||||
let item = list[i];
|
||||
if (ev.key == 'Escape') {
|
||||
let text_field_id = `label__${item.name}`;
|
||||
|
||||
let text_field = document.getElementById(text_field_id);
|
||||
if (text_field) {
|
||||
text_field.setAttribute('contenteditable', 'false');
|
||||
text_field.textContent = item.name;
|
||||
}
|
||||
|
||||
// reshow button
|
||||
item.show_button = true;
|
||||
return;
|
||||
}
|
||||
if (ev.key == 'Enter') {
|
||||
console.log('--- hitted');
|
||||
let name_field = ev.currentTarget as HTMLElement | null;
|
||||
let new_name = name_field
|
||||
? name_field.textContent || (name_field as any).innerText || ''
|
||||
: '';
|
||||
|
||||
if (new_name == '') {
|
||||
alert('Bitte einen gültigen Namen eingeben.');
|
||||
ev.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
// actual upload
|
||||
// -------------
|
||||
|
||||
// to prevent from item being selected
|
||||
ev.preventDefault();
|
||||
|
||||
// construct PUT URL
|
||||
const url = $page.url;
|
||||
console.log(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]
|
||||
: '';
|
||||
|
||||
open = true;
|
||||
inProgress = true;
|
||||
|
||||
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();
|
||||
// alert(json_res['msg'])
|
||||
return;
|
||||
}
|
||||
throw new Error(`Fehlgeschlagen: ${response.status}`);
|
||||
} else {
|
||||
uploadSuccessful();
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
// --- upload finished ---
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="-z-10 bg-white">
|
||||
<div class="flex flex-col items-center justify-center w-full">
|
||||
<h1 class="text-xl">Vorgang {$page.params.vorgang}</h1>
|
||||
</div>
|
||||
<div class="mx-auto flex justify-center max-w-7xl h-full">
|
||||
<ul class="divide-y divide-gray-100">
|
||||
{#each list as item, i}
|
||||
<li>
|
||||
<div class=" flex gap-x-4">
|
||||
<a
|
||||
href="/view/{$page.params.vorgang}/{item.name}"
|
||||
class=" flex justify-between gap-x-6 py-5"
|
||||
aria-label="zum 3D-modell"
|
||||
>
|
||||
<Cube />
|
||||
</a>
|
||||
<div class="min-w-0 flex-auto">
|
||||
{#if data.user.admin}
|
||||
<span
|
||||
id="label__{item.name}"
|
||||
class="text-sm font-semibold leading-6 text-gray-900 inline-block min-w-1"
|
||||
contenteditable={!item.show_button}
|
||||
role="textbox"
|
||||
tabindex="0"
|
||||
aria-label="Dateiname bearbeiten"
|
||||
on:focusout={() => {
|
||||
defocus_element(i);
|
||||
}}
|
||||
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
|
||||
>
|
||||
|
||||
<input
|
||||
class="text-sm font-semibold leading-6 text-gray-900 inline-block min-w-1"
|
||||
type="text"
|
||||
name=""
|
||||
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);
|
||||
}}
|
||||
bind:value={item.name}
|
||||
id="label__{item.name}"
|
||||
/>
|
||||
<!-- disabled={item.show_button} -->
|
||||
<!-- https://iconduck.com/icons/192863/edit-rename -->
|
||||
|
||||
{#if item.show_button}
|
||||
<button
|
||||
style="padding: 2px"
|
||||
id="edit__{item.name}"
|
||||
aria-label="Datei umbenennen"
|
||||
on:click|preventDefault={(ev) => {
|
||||
let text_field_id = `label__${item.name}`;
|
||||
|
||||
let text_field = document.getElementById(text_field_id);
|
||||
if (text_field) {
|
||||
text_field.setAttribute('contenteditable', 'true');
|
||||
text_field.focus();
|
||||
text_field.textContent = '';
|
||||
}
|
||||
|
||||
// hide button
|
||||
item.show_button = false;
|
||||
}}
|
||||
>
|
||||
<Edit />
|
||||
</button>
|
||||
{/if}
|
||||
<button
|
||||
style="padding: 2px"
|
||||
id="del__{item.name}"
|
||||
on:click|preventDefault={async (ev) => {
|
||||
let delete_item = window.confirm('Bist du sicher?');
|
||||
|
||||
if (delete_item) {
|
||||
// bucket: tatort, name: <vorgang>/item-name
|
||||
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' });
|
||||
if (response.status == 204) {
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.log(error.message);
|
||||
} else {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
aria-label="Datei löschen"
|
||||
>
|
||||
<Trash />
|
||||
</button>
|
||||
{:else}
|
||||
<span class="text-sm font-semibold leading-6 text-gray-900 inline-block min-w-1"
|
||||
>{item.name}</span
|
||||
>
|
||||
{/if}
|
||||
<p class="mt-1 truncate text-xs leading-5 text-gray-500">
|
||||
{shortenFileSize(item.size)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden sm:flex sm:flex-col sm:items-end">
|
||||
<p class="text-sm leading-6 text-gray-900">3D Tatort</p>
|
||||
<p class="mt-1 text-xs leading-5 text-gray-500">
|
||||
Zuletzt geändert <time datetime="2023-01-23T13:23Z"
|
||||
>{timeElapsed(new Date(item.lastModified))}</time
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<Modal {open}
|
||||
><ModalTitle>Umbenennen</ModalTitle><ModalContent>
|
||||
{#if inProgress}
|
||||
<p class="py-2 mb-1">Vorgang läuft...</p>
|
||||
{/if}
|
||||
{#if err}
|
||||
<Alert class="w-full" type="error">Fehler beim Umbenennen</Alert>
|
||||
{/if}
|
||||
</ModalContent>
|
||||
<ModalFooter><Button disabled={inProgress} on:click={uploadSuccessful}>Ok</Button></ModalFooter>
|
||||
</Modal>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
ul {
|
||||
min-width: 24rem;
|
||||
}
|
||||
</style>
|
||||
@@ -1,36 +0,0 @@
|
||||
import { client } from '$lib/minio';
|
||||
import { json } from '@sveltejs/kit';
|
||||
|
||||
|
||||
// rename operation
|
||||
export async function PUT({ request }) {
|
||||
const data = await request.json();
|
||||
|
||||
console.log(`--- ${request.url.split('/').at(-1)} +++ ${JSON.stringify(data)}`);
|
||||
|
||||
// Vorgang
|
||||
let 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"]}`
|
||||
|
||||
try {
|
||||
let file_stats = await client.statObject('tatort', new_name)
|
||||
return json({ msg: 'Die Datei existiert bereits.' }, { status: 400 })
|
||||
} catch (error) {
|
||||
// continue operation
|
||||
console.log('continue operation')
|
||||
}
|
||||
|
||||
// actual copy operation
|
||||
await client.copyObject('tatort', new_name, src_full_path)
|
||||
|
||||
// delete
|
||||
await client.removeObject('tatort', `${vorgang}/${old_name}`)
|
||||
|
||||
// return success or failure
|
||||
|
||||
return json({ success: 'success' }, { status: 200 });
|
||||
};
|
||||
@@ -1,13 +0,0 @@
|
||||
import { client } from '$lib/minio';
|
||||
import { json } from '@sveltejs/kit';
|
||||
|
||||
export async function DELETE({ request }) {
|
||||
|
||||
let url_fragments = request.url.split('/')
|
||||
let item = url_fragments.at(-1);
|
||||
let vorgang = url_fragments.at(-2);
|
||||
|
||||
await client.removeObject('tatort', `${vorgang}/${item}`)
|
||||
|
||||
return new Response(null, { status: 204 });
|
||||
};
|
||||
@@ -1,37 +0,0 @@
|
||||
import { client } from '$lib/minio';
|
||||
import { fail } from '@sveltejs/kit';
|
||||
|
||||
import caseNumberOccupied from '$lib/helper/caseNumberOccupied';
|
||||
|
||||
/** @type {import('./$types').Actions} */
|
||||
export const actions = {
|
||||
default: async ({ request }) => {
|
||||
const data = await request.formData();
|
||||
const caseNumber = data.get('caseNumber');
|
||||
const description = data.get('description');
|
||||
|
||||
if (!caseNumber) {
|
||||
return fail(400, {
|
||||
caseNumber,
|
||||
description,
|
||||
error: { caseNumber: 'Es muss eine Vorgangsnummer vorhanden sein.' }
|
||||
});
|
||||
}
|
||||
|
||||
if (await caseNumberOccupied(`${caseNumber}`)) {
|
||||
return fail(400, {
|
||||
caseNumber,
|
||||
description,
|
||||
error: { caseNumber: 'Die Vorgangsnummer wurde im System bereits angelegt.' }
|
||||
});
|
||||
}
|
||||
|
||||
const config = `${JSON.stringify({ caseNumber, description, version: 1 })}\n`;
|
||||
|
||||
await client.putObject('tatort', `${caseNumber}/config.json`, config, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
};
|
||||
37
src/routes/(angemeldet)/tatorte/+page.server.ts
Normal file
37
src/routes/(angemeldet)/tatorte/+page.server.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { client } from '$lib/minio';
|
||||
import { fail } from '@sveltejs/kit';
|
||||
|
||||
import vorgangNumberOccupied from '$lib/helper/vorgangNumberOccupied.js';
|
||||
|
||||
/** @type {import('./$types').Actions} */
|
||||
export const actions = {
|
||||
default: async ({ request }: {request: Request}) => {
|
||||
const data = await request.formData();
|
||||
const vorgangNumber: string | null = data.get('vorgangNumber') as string;
|
||||
const description: string | null = data.get('description') as string;
|
||||
|
||||
if (!vorgangNumber) {
|
||||
return fail(400, {
|
||||
vorgangNumber,
|
||||
description,
|
||||
error: { vorgangNumber: 'Es muss eine Vorgangsnummer vorhanden sein.' }
|
||||
});
|
||||
}
|
||||
|
||||
if (await vorgangNumberOccupied(`${vorgangNumber}`)) {
|
||||
return fail(400, {
|
||||
vorgangNumber,
|
||||
description,
|
||||
error: { vorgangNumber: 'Die Vorgangsnummer wurde im System bereits angelegt.' }
|
||||
});
|
||||
}
|
||||
|
||||
const config = `${JSON.stringify({ vorgangNumber, description, version: 1 })}\n`;
|
||||
|
||||
await client.putObject('tatort', `${vorgangNumber}/config.json`, config, undefined, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
};
|
||||
@@ -1,10 +1,10 @@
|
||||
<script>
|
||||
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';
|
||||
<script lang="ts">
|
||||
import Alert from '$lib/components/Alert.svelte';
|
||||
import Button from '$lib/components/Button.svelte';
|
||||
import Modal from '$lib/components/Modal/Modal.svelte';
|
||||
import ModalTitle from '$lib/components/Modal/ModalTitle.svelte';
|
||||
import ModalContent from '$lib/components/Modal/ModalContent.svelte';
|
||||
import ModalFooter from '$lib/components/Modal/ModalFooter.svelte';
|
||||
import Exclamation from '$lib/icons/Exclamation.svelte';
|
||||
|
||||
export let form;
|
||||
@@ -27,9 +27,9 @@
|
||||
|
||||
<div class="mt-10 grid grid-cols-1 gap-x-6 gap-y-8">
|
||||
<div>
|
||||
<label for="caseNumber" class="block text-sm font-medium leading-6 text-gray-900"
|
||||
<label for="vorgangNumber" class="block text-sm font-medium leading-6 text-gray-900"
|
||||
><span class="flex"
|
||||
>{#if form?.error?.caseNumber}
|
||||
>{#if form?.error?.vorgangNumber}
|
||||
<span class="inline-block mr-1"><Exclamation /></span>
|
||||
{/if} Vorgangs-Nr.</span
|
||||
></label
|
||||
@@ -39,43 +39,43 @@
|
||||
class="flex rounded-md shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-600"
|
||||
>
|
||||
<input
|
||||
value={form?.caseNumber ?? ''}
|
||||
value={form?.vorgangNumber ?? ''}
|
||||
type="text"
|
||||
name="caseNumber"
|
||||
id="caseNumber"
|
||||
name="vorgangNumber"
|
||||
id="vorgangNumber"
|
||||
class="block flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 text-sm leading-6"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{#if form?.error?.caseNumber}
|
||||
<p class="block text-sm leading-6 text-red-900 mt-2">{form.error.caseNumber}</p>
|
||||
{#if form?.error?.vorgangNumber}
|
||||
<p class="block text-sm leading-6 text-red-900 mt-2">{form.error.vorgangNumber}</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<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>
|
||||
|
||||
<label for="code">
|
||||
<span >Zugangscode (optional) </span>
|
||||
<label for="vorgang-token">
|
||||
<span >Zugangstoken (optional) </span>
|
||||
</label>
|
||||
|
||||
<div class="mt-2">
|
||||
@@ -83,7 +83,7 @@
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
id="code"
|
||||
id="vorgang-token"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
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) {
|
||||
if (value == null) return false;
|
||||
|
||||
if (typeof value === 'string' || value instanceof String) return value.trim() !== '';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @type {import('./$types').Actions} */
|
||||
export const actions = {
|
||||
url: async ({ request }) => {
|
||||
const data = await request.formData();
|
||||
const vorgang = data.get('vorgang');
|
||||
const name = data.get('name');
|
||||
const type = data.get('type');
|
||||
const fileName = data.get('fileName');
|
||||
|
||||
let objectName = `${vorgang}/${name}`;
|
||||
switch (type) {
|
||||
case 'image/png':
|
||||
if (!objectName.endsWith('.png')) objectName += '.png';
|
||||
break;
|
||||
case '':
|
||||
if (fileName.endsWith('.glb') && !objectName.endsWith('.glb')) objectName += '.glb';
|
||||
}
|
||||
|
||||
const url = await client.presignedPutObject('tatort', objectName);
|
||||
|
||||
return { url };
|
||||
},
|
||||
validate: async ({ request }) => {
|
||||
const requestData = await request.formData();
|
||||
const data = Object.fromEntries(requestData);
|
||||
const vorgang = data.vorgang;
|
||||
const name = data.name;
|
||||
const zugangscode = data.zugangscode;
|
||||
let success = true;
|
||||
let err = {};
|
||||
|
||||
if (isRequiredFieldValid(vorgang)) err.vorgang = null;
|
||||
else {
|
||||
err.vorgang = 'Das Feld Vorgang darf nicht leer bleiben.';
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (isRequiredFieldValid(name)) err.name = null;
|
||||
else {
|
||||
err.name = 'Das Feld Name darf nicht leer bleiben.';
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (isRequiredFieldValid(zugangscode)) err.zugangscode = null;
|
||||
else {
|
||||
err.zugangscode = 'Das Feld Zugangscode darf nicht leer bleiben.';
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (success) return { success };
|
||||
|
||||
return fail(400, err);
|
||||
},
|
||||
|
||||
upload: async ({ 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 }) => {
|
||||
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) {
|
||||
if (err) return reject(err);
|
||||
resolve(etag);
|
||||
});
|
||||
});
|
||||
let etag = null;
|
||||
let error = null;
|
||||
try {
|
||||
etag = await result;
|
||||
console.log(etag);
|
||||
} catch (err) {
|
||||
error = err;
|
||||
console.log('Error:', err);
|
||||
}
|
||||
|
||||
return { etag, error };
|
||||
//await writeFile(filePath, Buffer.from(await data.file.arrayBuffer()));
|
||||
}
|
||||
};
|
||||
125
src/routes/(angemeldet)/upload/+page.server.ts
Normal file
125
src/routes/(angemeldet)/upload/+page.server.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
import { Readable } from 'stream';
|
||||
import { client } from '$lib/minio';
|
||||
import { fail } from '@sveltejs/kit';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { db } from '$lib/server/dbService';
|
||||
import { getVorgangByName, vorgangNameExists } from '$lib/server/vorgangService';
|
||||
|
||||
const isRequiredFieldValid = (value: unknown) => {
|
||||
if (value == null) return false;
|
||||
|
||||
if (typeof value === 'string' || value instanceof String) return value.trim() !== '';
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
url: async ({ request }: { request: Request }) => {
|
||||
const data = await request.formData();
|
||||
const vorgangName: string | null = data.get('vorgang') as string;
|
||||
const crimeName: string | null = data.get('name') as string;
|
||||
const type: string | null = data.get('type') as string;
|
||||
const vorgangPIN: string | null = data.get('vorgangPIN') as string;
|
||||
const fileName: string | null = data.get('fileName') as string;
|
||||
|
||||
const vorgangExists = vorgangNameExists(vorgangName);
|
||||
let vorgangToken;
|
||||
|
||||
if (!vorgangExists) {
|
||||
vorgangToken = uuidv4();
|
||||
const insertSQLStatement = `INSERT INTO cases (token, name, pin) VALUES (?, ?, ?)`;
|
||||
const statement = db.prepare(insertSQLStatement);
|
||||
statement.run(vorgangToken, vorgangName, vorgangPIN);
|
||||
} else {
|
||||
const vorgang = getVorgangByName(vorgangName);
|
||||
vorgangToken = vorgang.token;
|
||||
if (vorgang && vorgang.pin != vorgangPIN) {
|
||||
const updateSQLStmt = `UPDATE cases SET pin = ? WHERE token = ?`;
|
||||
const statement = db.prepare(updateSQLStmt);
|
||||
statement.run(vorgangPIN, vorgangToken);
|
||||
}
|
||||
}
|
||||
|
||||
let objectName = `${vorgangToken}/${crimeName}`;
|
||||
switch (type) {
|
||||
case 'image/png':
|
||||
if (!objectName.endsWith('.png')) objectName += '.png';
|
||||
break;
|
||||
case '':
|
||||
if (fileName?.toString().endsWith('.glb') && !objectName.endsWith('.glb'))
|
||||
objectName += '.glb';
|
||||
}
|
||||
|
||||
const url = await client.presignedPutObject('tatort', objectName);
|
||||
|
||||
return { url };
|
||||
},
|
||||
validate: async ({ request }: { request: Request }) => {
|
||||
const requestData = await request.formData();
|
||||
const data = Object.fromEntries(requestData);
|
||||
const vorgang = data.vorgang;
|
||||
const name = data.name;
|
||||
const vorgangPIN = data.vorgangPIN;
|
||||
let success = true;
|
||||
const err = {};
|
||||
if (isRequiredFieldValid(vorgang)) {
|
||||
err.vorgang = null;
|
||||
} else {
|
||||
err.vorgang = 'Das Feld Vorgang darf nicht leer bleiben.';
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (isRequiredFieldValid(name)) {
|
||||
err.name = null;
|
||||
} else {
|
||||
err.name = 'Das Feld Name darf nicht leer bleiben.';
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (isRequiredFieldValid(vorgangPIN)) {
|
||||
err.vorgangPIN = null;
|
||||
} else {
|
||||
err.vorgangPIN = 'Das Feld Zugangspasswort darf nicht leer bleiben.';
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (success) return { success };
|
||||
|
||||
return fail(400, err);
|
||||
},
|
||||
|
||||
upload: async ({ request }: { request: Request }) => {
|
||||
const requestData = await request.formData();
|
||||
const data = Object.fromEntries(requestData);
|
||||
const vorgang = data.vorgang;
|
||||
const name = data.name;
|
||||
|
||||
const url = await client.presignedPutObject('tatort', `${vorgang}/${name}`, 60);
|
||||
|
||||
return { url };
|
||||
},
|
||||
upload3: async ({ request }: { request: Request }) => {
|
||||
const requestData = await request.formData();
|
||||
const data = Object.fromEntries(requestData);
|
||||
const name = data.name;
|
||||
const stream = data.file.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) {
|
||||
if (err) return reject(err);
|
||||
resolve(etag);
|
||||
});
|
||||
});
|
||||
let etag = null;
|
||||
let error = null;
|
||||
try {
|
||||
etag = await result;
|
||||
} catch (err) {
|
||||
error = err;
|
||||
console.log('Error:', err);
|
||||
}
|
||||
|
||||
return { etag, error };
|
||||
}
|
||||
};
|
||||
@@ -1,11 +1,11 @@
|
||||
<script>
|
||||
import { deserialize, enhance } 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';
|
||||
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';
|
||||
<script lang="ts">
|
||||
import { deserialize } from '$app/forms';
|
||||
import Alert from '$lib/components/Alert.svelte';
|
||||
import Button from '$lib/components/Button.svelte';
|
||||
import Modal from '$lib/components/Modal/Modal.svelte';
|
||||
import ModalTitle from '$lib/components/Modal/ModalTitle.svelte';
|
||||
import ModalContent from '$lib/components/Modal/ModalContent.svelte';
|
||||
import ModalFooter from '$lib/components/Modal/ModalFooter.svelte';
|
||||
import shortenFileSize from '$lib/helper/shortenFileSize.js';
|
||||
import Exclamation from '$lib/icons/Exclamation.svelte';
|
||||
import FileRect from '$lib/icons/File-rect.svelte';
|
||||
@@ -15,27 +15,34 @@
|
||||
let open = false;
|
||||
let inProgress = false;
|
||||
let vorgang = '';
|
||||
const code_len = 8;
|
||||
let zugangscode = Math.random()
|
||||
.toString(36)
|
||||
.slice(2, 2 + code_len);
|
||||
let case_existing = undefined;
|
||||
const PINLength = 8;
|
||||
|
||||
function generatePIN() {
|
||||
return Math.random()
|
||||
.toString(36)
|
||||
.slice(2, 2 + PINLength);
|
||||
}
|
||||
let vorgangPIN = '';
|
||||
let vorgangPINOld = '';
|
||||
$: vorgangPINOld = generatePIN();
|
||||
$: vorgangPIN = vorgangPINOld;
|
||||
|
||||
let vorgangExists = undefined;
|
||||
$: vorgangExists = false;
|
||||
|
||||
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();
|
||||
data.append('vorgang', vorgang);
|
||||
data.append('name', name);
|
||||
data.append('zugangscode', zugangscode);
|
||||
data.append('vorgangPIN', vorgangPIN);
|
||||
const response = await fetch('?/validate', { method: 'POST', body: data });
|
||||
/** @type {import('@sveltejs/kit').ActionResult} */
|
||||
const result = deserialize(await response.text());
|
||||
@@ -48,7 +55,6 @@
|
||||
success = false;
|
||||
}
|
||||
|
||||
console.log('File', files);
|
||||
if (!files?.length) {
|
||||
formErrors = { file: 'Sie haben keine Datei ausgewählt.', ...formErrors };
|
||||
success = false;
|
||||
@@ -58,7 +64,6 @@
|
||||
formErrors = { file: 'Keine gültige .GLD-Datei', ...formErrors };
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -66,6 +71,7 @@
|
||||
let data = new FormData();
|
||||
data.append('vorgang', vorgang);
|
||||
data.append('name', name);
|
||||
data.append('vorgangPIN', vorgangPIN);
|
||||
if (files?.length === 1) {
|
||||
data.append('type', files[0].type);
|
||||
data.append('fileName', files[0].name);
|
||||
@@ -78,14 +84,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;
|
||||
|
||||
@@ -93,7 +97,6 @@
|
||||
.then((response) => {
|
||||
inProgress = false;
|
||||
etag = '123';
|
||||
console.log('SUCCESS', response);
|
||||
})
|
||||
.catch((err) => {
|
||||
inProgress = false;
|
||||
@@ -103,7 +106,6 @@
|
||||
}
|
||||
|
||||
function uploadSuccessful() {
|
||||
console.log('reset');
|
||||
open = false;
|
||||
vorgang = '';
|
||||
name = '';
|
||||
@@ -137,6 +139,7 @@
|
||||
// big endian!
|
||||
let file = files[0];
|
||||
let file_header = file.slice(0, 4);
|
||||
console.log(file_header);
|
||||
let header_bytes = await file_header.bytes();
|
||||
let file_header_hex = '0x' + header_bytes.toHex().toString();
|
||||
|
||||
@@ -145,26 +148,51 @@
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// return true or false
|
||||
async function case_exists(case_no) {
|
||||
console.log('--- fired');
|
||||
// ping `/(angemeldet)/view` with caseNumber in POST body
|
||||
let url = '/view';
|
||||
let data = new FormData();
|
||||
data.append('caseNumber', case_no);
|
||||
const response = await fetch(url, { method: 'POST', body: data });
|
||||
|
||||
const code = response.status;
|
||||
|
||||
console.log(`+++ ${response.redirected}`);
|
||||
|
||||
if (code == 303) {
|
||||
return true;
|
||||
// `/(angemeldet)/view` return true or false
|
||||
async function checkVorgangExists(vorgangName: string) {
|
||||
if (vorgangName == '') {
|
||||
vorgangPIN = vorgangPINOld;
|
||||
return;
|
||||
}
|
||||
|
||||
return false;
|
||||
try {
|
||||
const url = `/api/list/${vorgangName}`;
|
||||
const response = await fetch(url, { method: 'HEAD' });
|
||||
|
||||
if (response.status === 200) {
|
||||
console.log('Vorgang existiert:', vorgangName);
|
||||
vorgangExists = true;
|
||||
const token = await getVorgangPIN(vorgangName);
|
||||
vorgangPIN = token;
|
||||
return true;
|
||||
} else {
|
||||
console.log('Vorgang existiert nicht!');
|
||||
vorgangExists = false;
|
||||
vorgangPIN = vorgangPINOld;
|
||||
return false;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Fehler bei checkVorgangExists:', err);
|
||||
vorgangExists = false;
|
||||
vorgangPIN = vorgangPINOld;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function getVorgangPIN(vorgangName: string) {
|
||||
if (vorgangName == '') return;
|
||||
|
||||
let url = `/api/list/${vorgangName}/vorgangPIN`;
|
||||
const response = await fetch(url);
|
||||
|
||||
if (response.status == 200) {
|
||||
return response.text();
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -186,7 +214,7 @@
|
||||
><span class="flex"
|
||||
>{#if formErrors?.vorgang}
|
||||
<span class="inline-block mr-1"><Exclamation /></span>
|
||||
{/if} Vorgang</span
|
||||
{/if} Vorgangsname</span
|
||||
></label
|
||||
>
|
||||
<div class="mt-2">
|
||||
@@ -200,13 +228,18 @@
|
||||
id="vorgang"
|
||||
autocomplete={vorgang}
|
||||
class="block flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6"
|
||||
on:input={() => case_exists(vorgang)}
|
||||
on:input={() => checkVorgangExists(vorgang)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{#if formErrors?.vorgang}
|
||||
<p class="block text-sm leading-6 text-red-900 mt-2">{formErrors.vorgang}</p>
|
||||
{/if}
|
||||
{#if vorgangExists && vorgang.length > 0}
|
||||
<span>Datei wird zum existierenden Vorgang hinzugefügt.</span>
|
||||
{:else if vorgang.length > 0}
|
||||
<span>Neuer Vorgang wird angelegt.</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@@ -214,7 +247,7 @@
|
||||
><span class="flex"
|
||||
>{#if formErrors?.name}
|
||||
<span class="inline-block mr-1"><Exclamation /></span>
|
||||
{/if} Name</span
|
||||
{/if} Modellname</span
|
||||
></label
|
||||
>
|
||||
<div class="mt-2">
|
||||
@@ -237,11 +270,11 @@
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="zugangscode" class="block text-sm font-medium leading-6 text-gray-900"
|
||||
<label for="vorgang-pin" class="block text-sm font-medium leading-6 text-gray-900"
|
||||
><span class="flex"
|
||||
>{#if formErrors?.zugangscode}
|
||||
>{#if formErrors?.vorgangPIN}
|
||||
<span class="inline-block mr-1"><Exclamation /></span>
|
||||
{/if} Zugangscode</span
|
||||
{/if} Zugangs-PIN</span
|
||||
></label
|
||||
>
|
||||
<div class="mt-2">
|
||||
@@ -249,16 +282,28 @@
|
||||
class="flex rounded-md shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-600"
|
||||
>
|
||||
<input
|
||||
bind:value={zugangscode}
|
||||
bind:value={vorgangPIN}
|
||||
type="text"
|
||||
name="zugangscode"
|
||||
id="zugangscode"
|
||||
name="vorgang-pin"
|
||||
id="vorgang-pin"
|
||||
on:input={(ev) => {
|
||||
vorgangPINOld = ev.target.value;
|
||||
}}
|
||||
class="block flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
class="rounded-md bg-blue-500 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
||||
on:click={() => {
|
||||
vorgangPIN = vorgangPINOld = generatePIN();
|
||||
}}
|
||||
type="button"
|
||||
>
|
||||
Generiere Zugangs-PIN
|
||||
</button>
|
||||
</div>
|
||||
{#if formErrors?.code}
|
||||
<p class="block text-sm leading-6 text-red-900 mt-2">{formErrors.code}</p>
|
||||
{#if formErrors?.vorgangPIN}
|
||||
<p class="block text-sm leading-6 text-red-900 mt-2">{formErrors.vorgangPIN}</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import caseNumberOccupied from '$lib/helper/caseNumberOccupied';
|
||||
import { fail, redirect } from '@sveltejs/kit';
|
||||
|
||||
/** @type {import('./$types').Actions} */
|
||||
export const actions = {
|
||||
default: async ({ request }) => {
|
||||
const data = await request.formData();
|
||||
console.log(`--- ${Object.keys(data)}`)
|
||||
const caseNumber = data.get('caseNumber');
|
||||
|
||||
if (!caseNumber) {
|
||||
console.log('^^^ here')
|
||||
return fail(400, {
|
||||
success: false,
|
||||
caseNumber,
|
||||
error: { caseNumber: 'Die Vorgangsnummer darf nicht leer sein.' }
|
||||
});
|
||||
}
|
||||
|
||||
let res = (await caseNumberOccupied(caseNumber))
|
||||
console.log(`gibt es? ${res} + ${caseNumber}`)
|
||||
if (!(await caseNumberOccupied(caseNumber))) {
|
||||
console.log('^^^ there')
|
||||
return fail(400, {
|
||||
success: false,
|
||||
caseNumber,
|
||||
error: { caseNumber: 'Die Vorgangsnummer existiert in dieser Anwendung nicht.' }
|
||||
});
|
||||
}
|
||||
else {
|
||||
throw redirect(303, `/list/${caseNumber}`);
|
||||
console.log(`---blabla ${caseNumber}`)
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
@@ -1,64 +0,0 @@
|
||||
<script>
|
||||
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;
|
||||
</script>
|
||||
|
||||
<div class="mx-auto max-w-2xl">
|
||||
<div class="flex flex-col items-center justify-center w-full">
|
||||
<h1 class="text-xl">Vorgang ansehen</h1>
|
||||
</div>
|
||||
|
||||
<form method="POST">
|
||||
<div class="space-y-12">
|
||||
<div class="border-b border-gray-900/10 pb-12">
|
||||
<!-- <h2 class="text-base font-semibold leading-7 text-gray-900">Profile</h2> -->
|
||||
<p class="mt-8 text-sm leading-6 text-gray-600">
|
||||
Anhand der Vorgangsnummer werden Sie zu den Dateien des Vorgangs weitergeleitet und können
|
||||
sich den Vorgang dann ansehen.
|
||||
</p>
|
||||
|
||||
<div class="mt-10 grid grid-cols-1 gap-x-6 gap-y-8">
|
||||
<div>
|
||||
<label for="caseNumber" class="block text-sm font-medium leading-6 text-gray-900"
|
||||
><span class="flex"
|
||||
>{#if form?.error?.caseNumber}
|
||||
<span class="inline-block mr-1"><Exclamation /></span>
|
||||
{/if} Vorgangs-Nr.</span
|
||||
></label
|
||||
>
|
||||
<div class="mt-2 w-full">
|
||||
<div
|
||||
class="flex w-full rounded-md shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-600"
|
||||
>
|
||||
<input
|
||||
value={form?.caseNumber ?? ''}
|
||||
type="text"
|
||||
name="caseNumber"
|
||||
id="caseNumber"
|
||||
class="block w-full flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{#if form?.error?.caseNumber}
|
||||
<p class="block text-sm leading-6 text-red-900 mt-2">{form.error.caseNumber}</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-6 flex items-center justify-end gap-x-6">
|
||||
<Button
|
||||
type="submit"
|
||||
class="rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
||||
>Weiter</Button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
22
src/routes/(token-based)/+layout.server.ts
Normal file
22
src/routes/(token-based)/+layout.server.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import {
|
||||
vorgangPINValidation,
|
||||
vorgangExists
|
||||
} from '$lib/server/vorgangService';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './list/[vorgang]/$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, url, locals }) => {
|
||||
if (locals.user) {
|
||||
return {
|
||||
user: locals.user
|
||||
};
|
||||
}
|
||||
|
||||
const vorgangToken = params.vorgang;
|
||||
const vorgangPIN = url.searchParams.get('pin');
|
||||
|
||||
const isVorgangValid = vorgangExists(vorgangToken);
|
||||
const isVorgangPINValid = vorgangPINValidation(vorgangToken, vorgangPIN);
|
||||
|
||||
if (!isVorgangValid || !isVorgangPINValid) throw redirect(303, `/anmeldung?vorgang=${vorgangToken}`);
|
||||
};
|
||||
16
src/routes/(token-based)/+layout.svelte
Normal file
16
src/routes/(token-based)/+layout.svelte
Normal file
@@ -0,0 +1,16 @@
|
||||
<script lang="ts">
|
||||
import Footer from '$lib/components/Footer.svelte';
|
||||
import Header from '$lib/components/Header.svelte';
|
||||
|
||||
export let data;
|
||||
</script>
|
||||
|
||||
<div class="h-screen v-screen flex flex-col">
|
||||
<Header {data} />
|
||||
|
||||
<div class="mt-10 flex-grow items-center justify-center">
|
||||
<slot />
|
||||
</div>
|
||||
|
||||
<Footer {data} />
|
||||
</div>
|
||||
16
src/routes/(token-based)/list/[vorgang]/+page.server.ts
Normal file
16
src/routes/(token-based)/list/[vorgang]/+page.server.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { getVorgangByToken, getCrimesListByToken } from '$lib/server/vorgangService';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, url }) => {
|
||||
const vorgangToken = params.vorgang;
|
||||
const vorgangPIN = url.searchParams.get('pin');
|
||||
|
||||
const crimesList = await getCrimesListByToken(vorgangToken);
|
||||
const vorgang = getVorgangByToken(vorgangToken);
|
||||
|
||||
return {
|
||||
crimesList,
|
||||
vorgangPIN,
|
||||
vorgang
|
||||
};
|
||||
};
|
||||
293
src/routes/(token-based)/list/[vorgang]/+page.svelte
Normal file
293
src/routes/(token-based)/list/[vorgang]/+page.svelte
Normal file
@@ -0,0 +1,293 @@
|
||||
<script lang="ts">
|
||||
import shortenFileSize from '$lib/helper/shortenFileSize';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
import timeElapsed from '$lib/helper/timeElapsed';
|
||||
|
||||
import Alert from '$lib/components/Alert.svelte';
|
||||
import Button from '$lib/components/Button.svelte';
|
||||
import Modal from '$lib/components/Modal/Modal.svelte';
|
||||
import ModalTitle from '$lib/components/Modal/ModalTitle.svelte';
|
||||
import ModalContent from '$lib/components/Modal/ModalContent.svelte';
|
||||
import ModalFooter from '$lib/components/Modal/ModalFooter.svelte';
|
||||
import Cube from '$lib/icons/Cube.svelte';
|
||||
import Edit from '$lib/icons/Edit.svelte';
|
||||
import Trash from '$lib/icons/Trash.svelte';
|
||||
|
||||
/** export let data; */
|
||||
/** @type {import('./$types').PageData} */
|
||||
export let data;
|
||||
|
||||
interface ListItem {
|
||||
name: string;
|
||||
size: number;
|
||||
lastModified: string | number | Date;
|
||||
show_button?: boolean;
|
||||
// add other properties as needed
|
||||
}
|
||||
|
||||
const vorgang = data.vorgang;
|
||||
const crimesList: ListItem[] = data.crimesList;
|
||||
const vorgangPIN: string = data.vorgangPIN;
|
||||
|
||||
let open = false;
|
||||
$: open;
|
||||
let inProgress = false;
|
||||
$: inProgress;
|
||||
let err = false;
|
||||
$: err;
|
||||
|
||||
let rename_input;
|
||||
$: rename_input;
|
||||
|
||||
function uploadSuccessful() {
|
||||
open = false;
|
||||
}
|
||||
|
||||
function defocus_element(i: number) {
|
||||
let item = crimesList[i];
|
||||
let text_field_id = `label__${item.name}`;
|
||||
|
||||
let text_field = document.getElementById(text_field_id);
|
||||
if (text_field) {
|
||||
text_field.setAttribute('contenteditable', 'false');
|
||||
text_field.textContent = item.name;
|
||||
}
|
||||
|
||||
// reshow button
|
||||
crimesList[i].show_button = true;
|
||||
return;
|
||||
}
|
||||
|
||||
async function handleEditFieldInput(ev: KeyboardEvent, listItemIndex: number) {
|
||||
let item = crimesList[listItemIndex];
|
||||
if (ev.key == 'Escape') {
|
||||
let text_field_id = `label__${item.name}`;
|
||||
|
||||
let text_field = document.getElementById(text_field_id);
|
||||
if (text_field) {
|
||||
text_field.setAttribute('contenteditable', 'false');
|
||||
text_field.textContent = item.name;
|
||||
}
|
||||
|
||||
// reshow button
|
||||
item.show_button = true;
|
||||
return;
|
||||
}
|
||||
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 || ''
|
||||
: '';
|
||||
|
||||
if (new_name == '') {
|
||||
alert('Bitte einen gültigen Namen eingeben.');
|
||||
ev.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
// actual upload
|
||||
// -------------
|
||||
|
||||
// to prevent from item being selected
|
||||
ev.preventDefault();
|
||||
|
||||
// construct PUT URL
|
||||
const url = $page.url.pathname.split('?')[0];
|
||||
|
||||
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]
|
||||
: '';
|
||||
|
||||
open = true;
|
||||
inProgress = true;
|
||||
|
||||
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();
|
||||
return;
|
||||
}
|
||||
throw new Error(`Fehlgeschlagen: ${response.status}`);
|
||||
} else {
|
||||
uploadSuccessful();
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
// --- upload finished ---
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function constructMailToLink() {
|
||||
const subject = "Link zum Tatvorgang";
|
||||
const link = $page.url.toString().split('?')[0];
|
||||
const body = `Hallo,
|
||||
|
||||
hier ist der Link zum Tatvorgang:
|
||||
${link}
|
||||
|
||||
Der Zugangs-PIN wird zur Sicherheit über einen zweiten Kommunikationskanal übermittelt.
|
||||
|
||||
Mit freundlichen Grüßen,
|
||||
`;
|
||||
|
||||
const mailtoLink = `mailto:?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`;
|
||||
|
||||
return mailtoLink;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="-z-10 bg-white">
|
||||
<div class="flex flex-col items-center justify-center w-full">
|
||||
<h1 class="text-xl">Vorgang {vorgang.name}</h1>
|
||||
{#if data?.user?.admin}
|
||||
Zugangs-PIN: {vorgang.pin}
|
||||
<a href="{constructMailToLink()}"><Button>Share Link</Button></a>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="mx-auto flex justify-center max-w-7xl h-full">
|
||||
<ul class="divide-y divide-gray-100">
|
||||
{#each crimesList as item, crimeListItemIndex}
|
||||
<li>
|
||||
<a
|
||||
href="/view/{$page.params.vorgang}/{item.name}?pin={vorgangPIN}"
|
||||
class=" flex justify-between gap-x-6 py-5"
|
||||
aria-label="zum 3D-modell"
|
||||
>
|
||||
<div class=" flex gap-x-4">
|
||||
<Cube />
|
||||
<div class="min-w-0 flex-auto">
|
||||
{#if data?.user?.admin}
|
||||
<span
|
||||
id="label__{item.name}"
|
||||
class="text-sm font-semibold leading-6 text-gray-900 inline-block min-w-1"
|
||||
contenteditable={!item.show_button}
|
||||
role="textbox"
|
||||
tabindex="0"
|
||||
aria-label="Dateiname bearbeiten"
|
||||
on:focusout={() => {
|
||||
defocus_element(crimeListItemIndex);
|
||||
}}
|
||||
on:keydown|stopPropagation={// event needed to identify ID
|
||||
// TO-DO: check if event is needed or if index is sufficient
|
||||
async (ev) => {
|
||||
handleEditFieldInput(ev, crimeListItemIndex);
|
||||
}}>{item.name}</span
|
||||
>
|
||||
|
||||
|
||||
{#if item.show_button}
|
||||
<button
|
||||
style="padding: 2px"
|
||||
id="edit__{item.name}"
|
||||
aria-label="Datei umbenennen"
|
||||
on:click|preventDefault={(ev) => {
|
||||
let text_field_id = `label__${item.name}`;
|
||||
|
||||
let text_field = document.getElementById(text_field_id);
|
||||
if (text_field) {
|
||||
text_field.setAttribute('contenteditable', 'true');
|
||||
text_field.focus();
|
||||
text_field.textContent = '';
|
||||
}
|
||||
|
||||
// hide button
|
||||
item.show_button = false;
|
||||
}}
|
||||
>
|
||||
<Edit />
|
||||
</button>
|
||||
{/if}
|
||||
<button
|
||||
style="padding: 2px"
|
||||
id="del__{item.name}"
|
||||
on:click|preventDefault={async (ev) => {
|
||||
let delete_item = window.confirm('Bist du sicher?');
|
||||
|
||||
if (delete_item) {
|
||||
// bucket: tatort, name: <vorgang>/item-name
|
||||
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}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api${url.pathname}`, { method: 'DELETE' });
|
||||
if (response.status == 204) {
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.log(error.message);
|
||||
} else {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
aria-label="Datei löschen"
|
||||
>
|
||||
<Trash />
|
||||
</button>
|
||||
{:else}
|
||||
<span class="text-sm font-semibold leading-6 text-gray-900 inline-block min-w-1"
|
||||
>{item.name}</span
|
||||
>
|
||||
{/if}
|
||||
<p class="mt-1 truncate text-xs leading-5 text-gray-500">
|
||||
{shortenFileSize(item.size)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden sm:flex sm:flex-col sm:items-end">
|
||||
<p class="text-sm leading-6 text-gray-900">3D Tatort</p>
|
||||
<p class="mt-1 text-xs leading-5 text-gray-500">
|
||||
Zuletzt geändert <time datetime="2023-01-23T13:23Z"
|
||||
>{timeElapsed(new Date(item.lastModified))}</time
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<Modal {open}
|
||||
><ModalTitle>Umbenennen</ModalTitle><ModalContent>
|
||||
{#if inProgress}
|
||||
<p class="py-2 mb-1">Vorgang läuft...</p>
|
||||
{/if}
|
||||
{#if err}
|
||||
<Alert class="w-full" type="error">Fehler beim Umbenennen</Alert>
|
||||
{/if}
|
||||
</ModalContent>
|
||||
<ModalFooter><Button disabled={inProgress} on:click={uploadSuccessful}>Ok</Button></ModalFooter>
|
||||
</Modal>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
ul {
|
||||
min-width: 24rem;
|
||||
}
|
||||
</style>
|
||||
34
src/routes/(token-based)/list/[vorgang]/+server.ts
Normal file
34
src/routes/(token-based)/list/[vorgang]/+server.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { client } from '$lib/minio';
|
||||
import { json } from '@sveltejs/kit';
|
||||
|
||||
|
||||
// rename operation for crimes
|
||||
export async function PUT({ request }: {request: Request}) {
|
||||
const data = await request.json();
|
||||
|
||||
// Vorgang
|
||||
const vorgangToken = request.url.split('/').at(-1);
|
||||
|
||||
// prepare copy, incl. check if new name exists already
|
||||
const crimeOldName = data["old_name"];
|
||||
const crimeS3FullBucketPathOld = `/tatort/${vorgangToken}/${crimeOldName}`;
|
||||
const crimeNewName = `${vorgangToken}/${data["new_name"]}`;
|
||||
|
||||
try {
|
||||
await client.statObject('tatort', crimeNewName);
|
||||
return json({ msg: 'Die Datei existiert bereits.' }, { status: 400 });
|
||||
} catch (error) {
|
||||
// continue operation
|
||||
console.log(error, 'continue operation');
|
||||
}
|
||||
|
||||
// actual copy operation
|
||||
await client.copyObject('tatort', crimeNewName, crimeS3FullBucketPathOld)
|
||||
|
||||
// delete
|
||||
await client.removeObject('tatort', `${vorgangToken}/${crimeOldName}`)
|
||||
|
||||
// return success or failure
|
||||
|
||||
return json({ success: 'success' }, { status: 200 });
|
||||
};
|
||||
11
src/routes/(token-based)/view/+page.server.ts
Normal file
11
src/routes/(token-based)/view/+page.server.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
export const actions = {
|
||||
default: async ({request}: {request: Request}) => {
|
||||
const data = await request.formData();
|
||||
const vorgangId: string | null = data.get('vorgang-id') as string;
|
||||
const vorgangToken: string | null = data.get('vorgang-token') as string;
|
||||
|
||||
if( vorgangId && vorgangToken) throw redirect(303, `/list/${vorgangId}?token=${vorgangToken}`);
|
||||
}
|
||||
}
|
||||
39
src/routes/(token-based)/view/+page.svelte
Normal file
39
src/routes/(token-based)/view/+page.svelte
Normal file
@@ -0,0 +1,39 @@
|
||||
<script lang="ts">
|
||||
import BaseInputField from '$lib/components/BaseInputField.svelte';
|
||||
import Button from '$lib/components/Button.svelte';
|
||||
import ArrowRight from '$lib/icons/Arrow-right.svelte';
|
||||
|
||||
export let form;
|
||||
</script>
|
||||
|
||||
<div class="mx-auto max-w-2xl">
|
||||
<div class="flex flex-col items-center justify-center w-full">
|
||||
<h1 class="text-xl">Vorgang ansehen</h1>
|
||||
</div>
|
||||
<p class="mt-8 mb-8 text-sm leading-6 text-gray-600">
|
||||
Anhand der Vorgangsnummer werden Sie zu den Dateien des Vorgangs weitergeleitet und können sich
|
||||
den Vorgang dann ansehen.
|
||||
</p>
|
||||
<form method="POST">
|
||||
<BaseInputField
|
||||
id="vorgang-id"
|
||||
name="vorgang-id"
|
||||
label="Vorgangskennung"
|
||||
type="text"
|
||||
value={form?.vorgangId}
|
||||
/>
|
||||
<div class="mt-5">
|
||||
<BaseInputField
|
||||
id="vorgang-token"
|
||||
name="vorgang-token"
|
||||
label="Zugangstoken"
|
||||
type="text"
|
||||
value={form?.vorgangToken}
|
||||
error={form?.error?.message}
|
||||
/>
|
||||
</div>
|
||||
<div class="flex justify-end pt-4">
|
||||
<Button type="submit"><ArrowRight /></Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -1,7 +1,7 @@
|
||||
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,7 +1,8 @@
|
||||
<script>
|
||||
import Panel from '$lib/components/ui/Panel.svelte';
|
||||
<script lang="ts">
|
||||
import Panel from '$lib/components/Panel.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import Button from '$lib/components/ui/Button.svelte';
|
||||
import Button from '$lib/components/Button.svelte';
|
||||
import type { ModelViewerElement } from '@google/model-viewer';
|
||||
|
||||
export let data;
|
||||
|
||||
@@ -19,79 +20,50 @@
|
||||
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;
|
||||
let modelViewer: ModelViewerElement | null = null;
|
||||
|
||||
$: style = `width: ${progress}%`;
|
||||
|
||||
/**
|
||||
* @param {any} detail
|
||||
*/
|
||||
function onProgress({ detail }) {
|
||||
const updateModelProgress = ({ detail }: { detail: { totalProgress: number } }) => {
|
||||
progress = Math.ceil(detail.totalProgress * 100.0);
|
||||
if (progress == 100) {
|
||||
setTimeout(() => {
|
||||
hideProgressScreen = true;
|
||||
}, 250);
|
||||
} else hideProgressScreen = false;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
modelViewer.cameraOrbit = cameraOrbit;
|
||||
modelViewer.cameraTarget = cameraTarget;
|
||||
modelViewer.fieldOfView = fieldOfView;
|
||||
cameraAzimuth = 0;
|
||||
cameraPolar = 0;
|
||||
cameraZoom = 100;
|
||||
fieldOfView = '10deg';
|
||||
if (modelViewer) {
|
||||
cameraAzimuth = 0;
|
||||
cameraPolar = 0;
|
||||
cameraZoom = 100;
|
||||
modelViewer.cameraOrbit = cameraOrbit;
|
||||
modelViewer.cameraTarget = cameraTarget;
|
||||
modelViewer.fieldOfView = fieldOfView;
|
||||
cameraAzimuth = 0;
|
||||
cameraPolar = 0;
|
||||
cameraZoom = 100;
|
||||
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;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="h-full model w-full bg-neutral-200 p-4 transition-all delay-250">
|
||||
<div class="h-full w-full bg-neutral-200 p-4 transition-all delay-250">
|
||||
<!-- xr-environment -->
|
||||
<model-viewer
|
||||
ar
|
||||
class="h-full w-full"
|
||||
shadow-intensity="1"
|
||||
src={data.url}
|
||||
bind:this={modelViewer}
|
||||
@@ -103,7 +75,7 @@
|
||||
orientation={`${xRotation}deg ${yRotation}deg ${zRotation}deg`}
|
||||
camera-target="0m 0m 0m"
|
||||
camera-orbit={`${cameraAzimuth}deg ${cameraPolar}deg ${cameraZoom}%`}
|
||||
on:progress={onProgress}
|
||||
on:progress={updateModelProgress}
|
||||
>
|
||||
<!--Buttons zum Steuern-->
|
||||
<div
|
||||
@@ -111,18 +83,7 @@
|
||||
class:opacity-0={!hideProgressScreen}
|
||||
class:hidden={!hideProgressScreen}
|
||||
>
|
||||
<button slot="ar-button" id="ar-button"> 👋 Activate AR </button>
|
||||
|
||||
<div id="ar-prompt">AR-Prompt</div>
|
||||
|
||||
<button id="ar-failure"> AR is not tracking! </button>
|
||||
<div class="flex flex-col bg-white/50">
|
||||
<button
|
||||
on:click={() => {
|
||||
console.log(modelViewer.ar, modelViewer.getAttribute('ar-status'));
|
||||
}}>Test</button
|
||||
>
|
||||
|
||||
<!--3 Buttons-->
|
||||
<div class="p-2">
|
||||
<Button
|
||||
@@ -214,22 +175,4 @@
|
||||
</div>
|
||||
|
||||
<style>
|
||||
model-viewer {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* .vertical-slider {
|
||||
writing-mode: bt-lr; /* Schreibt von unten nach oben (Vertikale Darstellung)
|
||||
transform: rotate(270deg); /* Slider um 270° drehen
|
||||
height: 200px;
|
||||
} */
|
||||
|
||||
.model {
|
||||
height: calc(100%-84px);
|
||||
}
|
||||
|
||||
/* .active-border {
|
||||
border: 2px blue solid;
|
||||
} */
|
||||
</style>
|
||||
@@ -1,4 +1,4 @@
|
||||
<script>
|
||||
<script lang="ts">
|
||||
import '../app.css';
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
import { dev } from '$app/environment';
|
||||
import { fail, redirect } from '@sveltejs/kit';
|
||||
import { authenticate } from '$lib/auth';
|
||||
|
||||
const COOKIE_NAME = 'session';
|
||||
|
||||
/** @type {import('./$types').Actions} */
|
||||
export const actions = {
|
||||
login: async ({ request, cookies }) => {
|
||||
const data = await request.formData();
|
||||
const user = data.get('user');
|
||||
const password = data.get('password');
|
||||
|
||||
const token = authenticate(user, password);
|
||||
|
||||
if (!token) return fail(400, { user, incorrect: true });
|
||||
|
||||
cookies.set(COOKIE_NAME, token, {
|
||||
path: '/',
|
||||
httpOnly: true,
|
||||
sameSite: 'strict',
|
||||
secure: !dev
|
||||
});
|
||||
throw redirect(303, '/');
|
||||
},
|
||||
logout: async (event) => {
|
||||
event.cookies.delete(COOKIE_NAME, {path: '/'});
|
||||
event.locals.user = null;
|
||||
return { success: true };
|
||||
}
|
||||
};
|
||||
16
src/routes/anmeldung/+page.server.ts
Normal file
16
src/routes/anmeldung/+page.server.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { loginUser, logoutUser } from '$lib/server/authService';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
export const actions = {
|
||||
login: ({ request, cookies }) => loginUser({ request, cookies }),
|
||||
logout: (event) => logoutUser(event),
|
||||
getVorgangByToken: async ({ request }) => {
|
||||
const data = await request.formData();
|
||||
const vorgangToken = data.get('vorgang-token');
|
||||
const vorgangPIN = data.get('vorgang-pin');
|
||||
|
||||
if (!vorgangToken || !vorgangPIN) return;
|
||||
|
||||
throw redirect(303, `/list/${vorgangToken}?pin=${vorgangPIN}`);
|
||||
}
|
||||
} as const;
|
||||
@@ -1,38 +1,67 @@
|
||||
<script>
|
||||
import Panel from '$lib/components/ui/Panel.svelte';
|
||||
import Button from '$lib/components/ui/Button.svelte';
|
||||
import Alert from '$lib/components/ui/Alert.svelte';
|
||||
<script lang="ts">
|
||||
import BaseInputField from '$lib/components/BaseInputField.svelte';
|
||||
import Button from '$lib/components/Button.svelte';
|
||||
import Modal from '$lib/components/Modal/Modal.svelte';
|
||||
import ModalContent from '$lib/components/Modal/ModalContent.svelte';
|
||||
import ModalFooter from '$lib/components/Modal/ModalFooter.svelte';
|
||||
import ModalTitle from '$lib/components/Modal/ModalTitle.svelte';
|
||||
import ArrowRight from '$lib/icons/Arrow-right.svelte';
|
||||
import Login from '$lib/icons/Login.svelte';
|
||||
|
||||
/** @type {import('./$types').ActionData} */
|
||||
export let form;
|
||||
|
||||
let user = form?.user ?? '';
|
||||
export let open = false;
|
||||
|
||||
function buttonClick() {}
|
||||
import { page } from '$app/state';
|
||||
const vorgangToken = page.url.searchParams.get('vorgang');
|
||||
</script>
|
||||
|
||||
<!--
|
||||
This example requires updating your template:
|
||||
|
||||
```
|
||||
<html class="h-full bg-white">
|
||||
<body class="h-full">
|
||||
```
|
||||
-->
|
||||
<div class="flex min-h-full flex-col justify-center px-6 py-12 lg:px-8">
|
||||
<div class="sm:mx-auto sm:w-full sm:max-w-sm">
|
||||
<img class="mx-auto h-10 w-auto" src="/Landeswappen_NI.svg" alt="Landeswappen Niedersachsen" />
|
||||
|
||||
<h2 class="mt-10 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900">
|
||||
Anmeldung zum 3D Tatort
|
||||
Willkommen beim 3D Tatort
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<div class="mt-10 sm:mx-auto sm:w-full sm:max-w-sm">
|
||||
<form class="space-y-6" action="?/login" method="POST">
|
||||
<div class="w-full max-w-sm mx-auto">
|
||||
<div class="relative mt-5 bg-gray-50 rounded-xl shadow-xl p-3 pt-1">
|
||||
<div class="mt-10">
|
||||
<form action="?/getVorgangByToken" method="POST">
|
||||
<BaseInputField
|
||||
id="vorgang-token"
|
||||
name="vorgang-token"
|
||||
label="Vorgangskennung"
|
||||
type="text"
|
||||
value={vorgangToken}
|
||||
/>
|
||||
<div class="mt-5">
|
||||
<BaseInputField
|
||||
id="vorgang-pin"
|
||||
name="vorgang-pin"
|
||||
label="Zugangs-PIN"
|
||||
type="text"
|
||||
value={form?.vorgangPIN}
|
||||
error={form?.error?.message}
|
||||
/>
|
||||
</div>
|
||||
<div class="flex justify-end pt-4">
|
||||
<Button type="submit"><ArrowRight /></Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-end mt-10 px-3">
|
||||
<Button on:click={() => (open = true)}><Login /></Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Modal {open}>
|
||||
<ModalTitle>Anmelden</ModalTitle>
|
||||
<ModalContent class="flex justify-center">
|
||||
<form action="?/login" method="POST">
|
||||
<div>
|
||||
<label for="user" class="block text-sm font-medium leading-6 text-gray-900">Kennung</label>
|
||||
<label for="user" class="text-sm font-medium leading-6 text-gray-900">Kennung</label>
|
||||
<div class="mt-2">
|
||||
<input
|
||||
id="user"
|
||||
@@ -40,17 +69,15 @@
|
||||
type="text"
|
||||
autocomplete="email"
|
||||
required
|
||||
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"
|
||||
class="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"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="flex items-center justify-between">
|
||||
<label for="password" class="block text-sm font-medium leading-6 text-gray-900"
|
||||
>Passwort</label
|
||||
>
|
||||
</div>
|
||||
<label for="password" class="block text-sm font-medium leading-6 text-gray-900"
|
||||
>Passwort</label
|
||||
>
|
||||
<div class="mt-2">
|
||||
<input
|
||||
id="password"
|
||||
@@ -63,13 +90,10 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button
|
||||
type="submit"
|
||||
class="mt-10 flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
||||
>Anmelden</button
|
||||
>
|
||||
<div class="flex justify-end">
|
||||
<Button type="submit" class="mt-5">Anmelden</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</ModalContent>
|
||||
<ModalFooter><Button on:click={() => (open = false)}>Ok</Button></ModalFooter>
|
||||
</Modal>
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
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 result = new ReadableStream({
|
||||
start(controller) {
|
||||
stream.on('data', (data) => {
|
||||
if (prefix === '') {
|
||||
if (data.prefix)
|
||||
controller.enqueue(`${JSON.stringify({ ...data, name: data.prefix.slice(0, -1) })}\n`);
|
||||
return;
|
||||
}
|
||||
|
||||
const name = data.name.slice(prefix.length);
|
||||
if (name === 'config.json') return;
|
||||
|
||||
controller.enqueue(`${JSON.stringify({ ...data, name, prefix })}\n`);
|
||||
});
|
||||
stream.on('end', () => {
|
||||
controller.close();
|
||||
});
|
||||
},
|
||||
cancel() {
|
||||
stream.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
return new Response(result, {
|
||||
headers: {
|
||||
'content-type': 'text/event-stream'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export async function DELETE({ params }) {
|
||||
const vorgang = params.vorgang
|
||||
|
||||
const object_list = await new Promise((resolve, reject) => {
|
||||
|
||||
const res = []
|
||||
const items_str = client.listObjects('tatort', vorgang, true)
|
||||
|
||||
items_str.on('data', (obj) => {
|
||||
res.push(obj.name)
|
||||
})
|
||||
|
||||
items_str.on('error', reject)
|
||||
|
||||
items_str.on('end', async () => {
|
||||
resolve(res)
|
||||
})
|
||||
|
||||
console.log(`+++ ${vorgang}`)
|
||||
|
||||
})
|
||||
|
||||
await client.removeObjects('tatort', object_list)
|
||||
|
||||
return new Response(null, { status: 204 });
|
||||
};
|
||||
40
src/routes/api/list/[vorgang]/+server.ts
Normal file
40
src/routes/api/list/[vorgang]/+server.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { client } from '$lib/minio';
|
||||
import { deleteVorgangByToken, vorgangNameExists } from '$lib/server/vorgangService';
|
||||
|
||||
export async function DELETE({ params }) {
|
||||
const vorgangToken = params.vorgang;
|
||||
|
||||
const object_list = await new Promise((resolve, reject) => {
|
||||
const res = [];
|
||||
const items_str = client.listObjects('tatort', vorgangToken, true);
|
||||
|
||||
items_str.on('data', (obj) => {
|
||||
res.push(obj.name);
|
||||
});
|
||||
|
||||
items_str.on('error', reject);
|
||||
|
||||
items_str.on('end', async () => {
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
|
||||
await client.removeObjects('tatort', object_list);
|
||||
deleteVorgangByToken(vorgangToken);
|
||||
|
||||
return new Response(null, { status: 204 });
|
||||
}
|
||||
|
||||
export async function HEAD({ params }) {
|
||||
try {
|
||||
const vorgangName = params.vorgang;
|
||||
const existing = vorgangNameExists(vorgangName);
|
||||
|
||||
return new Response(null, {
|
||||
status: existing ? 200 : 404
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Fehler im HEAD-Handler:', err);
|
||||
return new Response(null, { status: 500 });
|
||||
}
|
||||
}
|
||||
35
src/routes/api/list/[vorgang]/[tatort]/+server.ts
Normal file
35
src/routes/api/list/[vorgang]/[tatort]/+server.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { BUCKET, client } from '$lib/minio';
|
||||
|
||||
export async function GET() {
|
||||
const stream = client.listObjectsV2(BUCKET, '', true);
|
||||
const result = new ReadableStream({
|
||||
start(controller) {
|
||||
stream.on('data', (data) => {
|
||||
controller.enqueue(`${JSON.stringify(data)}\n`);
|
||||
});
|
||||
stream.on('end', () => {
|
||||
controller.close();
|
||||
});
|
||||
},
|
||||
cancel() {
|
||||
stream.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
return new Response(result, {
|
||||
headers: {
|
||||
'content-type': 'text/event-stream'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
await client.removeObject(BUCKET, `${vorgang}/${item}`);
|
||||
|
||||
return new Response(null, { status: 204 });
|
||||
}
|
||||
16
src/routes/api/list/[vorgang]/vorgangPIN/+server.ts
Normal file
16
src/routes/api/list/[vorgang]/vorgangPIN/+server.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { db } from '$lib/server/dbService';
|
||||
|
||||
/** @type {import('./$types').RequestHandler} */
|
||||
export async function GET({ params }) {
|
||||
const vorgangName = params.vorgang;
|
||||
|
||||
const getPINSQLStatement = `SELECT pin FROM cases WHERE name = ?;`;
|
||||
const row = db.prepare(getPINSQLStatement).get(vorgangName);
|
||||
const vorgangPIN = row?.pin;
|
||||
|
||||
if (vorgangPIN) {
|
||||
return new Response(vorgangPIN, { status: 200 });
|
||||
} else {
|
||||
return new Response(null, { status: 404 });
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import { client } from '$lib/minio';
|
||||
|
||||
/** @type {import('./$types').RequestHandler} */
|
||||
export async function GET() {
|
||||
var 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', () => {
|
||||
controller.close();
|
||||
});
|
||||
},
|
||||
cancel() {
|
||||
stream.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
return new Response(result, {
|
||||
headers: {
|
||||
'content-type': 'text/event-stream'
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import { client } from '$lib/minio';
|
||||
|
||||
/** @type {import('./$types').RequestHandler} */
|
||||
export async function GET(params) {
|
||||
console.log('GET', params);
|
||||
}
|
||||
5
src/routes/api/upload/+server.ts
Normal file
5
src/routes/api/upload/+server.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { RequestHandler } from "@sveltejs/kit";
|
||||
|
||||
export async function GET(params: RequestHandler) {
|
||||
console.log('GET', params);
|
||||
}
|
||||
@@ -10,7 +10,9 @@
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"moduleResolution": "bundler"
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*", "src/node_modules"],
|
||||
"exclude": ["node_modules/*", "__sapper__/*", "public/*"]
|
||||
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
|
||||
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user