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