Merge pull request 'f076_api_endpoints_for_renaming_crimes' (#25) from f076_api_endpoints_for_renaming_crimes into development
All checks were successful
InnoHub Processor/tatort/pipeline/head This commit looks good
All checks were successful
InnoHub Processor/tatort/pipeline/head This commit looks good
Reviewed-on: #25
This commit was merged in pull request #25.
This commit is contained in:
@@ -59,8 +59,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handle_input(ev: KeyboardEvent, i: number) {
|
async function handleEditFieldInput(ev: KeyboardEvent, listItemIndex: number) {
|
||||||
let item = crimesList[i];
|
let item = crimesList[listItemIndex];
|
||||||
if (ev.key == 'Escape') {
|
if (ev.key == 'Escape') {
|
||||||
let text_field_id = `label__${item.name}`;
|
let text_field_id = `label__${item.name}`;
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@
|
|||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
|
||||||
// construct PUT URL
|
// construct PUT URL
|
||||||
const url = $page.url;
|
const url = $page.url.pathname.split('?')[0];
|
||||||
|
|
||||||
let data_obj: { new_name: string; old_name: string } = { new_name: '', old_name: '' };
|
let data_obj: { new_name: string; old_name: string } = { new_name: '', old_name: '' };
|
||||||
data_obj['new_name'] = new_name;
|
data_obj['new_name'] = new_name;
|
||||||
@@ -149,7 +149,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="mx-auto flex justify-center max-w-7xl h-full">
|
<div class="mx-auto flex justify-center max-w-7xl h-full">
|
||||||
<ul class="divide-y divide-gray-100">
|
<ul class="divide-y divide-gray-100">
|
||||||
{#each crimesList as item, i}
|
{#each crimesList as item, crimeListItemIndex}
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a
|
||||||
href="/view/{$page.params.vorgang}/{item.name}?pin={vorgangPIN}"
|
href="/view/{$page.params.vorgang}/{item.name}?pin={vorgangPIN}"
|
||||||
@@ -168,12 +168,12 @@
|
|||||||
tabindex="0"
|
tabindex="0"
|
||||||
aria-label="Dateiname bearbeiten"
|
aria-label="Dateiname bearbeiten"
|
||||||
on:focusout={() => {
|
on:focusout={() => {
|
||||||
defocus_element(i);
|
defocus_element(crimeListItemIndex);
|
||||||
}}
|
}}
|
||||||
on:keydown|stopPropagation={// event needed to identify ID
|
on:keydown|stopPropagation={// event needed to identify ID
|
||||||
// TO-DO: check if event is needed or if index is sufficient
|
// TO-DO: check if event is needed or if index is sufficient
|
||||||
async (ev) => {
|
async (ev) => {
|
||||||
handle_input(ev, i);
|
handleEditFieldInput(ev, crimeListItemIndex);
|
||||||
}}>{item.name}</span
|
}}>{item.name}</span
|
||||||
>
|
>
|
||||||
|
|
||||||
|
|||||||
@@ -2,21 +2,20 @@ import { client } from '$lib/minio';
|
|||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
|
|
||||||
|
|
||||||
// rename operation
|
// rename operation for crimes
|
||||||
export async function PUT({ request }: {request: Request}) {
|
export async function PUT({ request }: {request: Request}) {
|
||||||
const data = await request.json();
|
const data = await request.json();
|
||||||
|
|
||||||
|
|
||||||
// Vorgang
|
// Vorgang
|
||||||
const vorgang = request.url.split('/').at(-1);
|
const vorgangToken = request.url.split('/').at(-1);
|
||||||
|
|
||||||
// prepare copy, incl. check if new name exists already
|
// prepare copy, incl. check if new name exists already
|
||||||
const old_name = data["old_name"];
|
const crimeOldName = data["old_name"];
|
||||||
const src_full_path = `/tatort/${vorgang}/${old_name}`;
|
const crimeS3FullBucketPathOld = `/tatort/${vorgangToken}/${crimeOldName}`;
|
||||||
const new_name = `${vorgang}/${data["new_name"]}`;
|
const crimeNewName = `${vorgangToken}/${data["new_name"]}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.statObject('tatort', new_name);
|
await client.statObject('tatort', crimeNewName);
|
||||||
return json({ msg: 'Die Datei existiert bereits.' }, { status: 400 });
|
return json({ msg: 'Die Datei existiert bereits.' }, { status: 400 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// continue operation
|
// continue operation
|
||||||
@@ -24,10 +23,10 @@ export async function PUT({ request }: {request: Request}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// actual copy operation
|
// actual copy operation
|
||||||
await client.copyObject('tatort', new_name, src_full_path)
|
await client.copyObject('tatort', crimeNewName, crimeS3FullBucketPathOld)
|
||||||
|
|
||||||
// delete
|
// delete
|
||||||
await client.removeObject('tatort', `${vorgang}/${old_name}`)
|
await client.removeObject('tatort', `${vorgangToken}/${crimeOldName}`)
|
||||||
|
|
||||||
// return success or failure
|
// return success or failure
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user