Spaces:
Paused
Paused
feat(api): replace all conv deletion form by API endpoint (#1695)
Browse files
src/routes/api/conversations/+server.ts
CHANGED
|
@@ -42,3 +42,13 @@ export async function GET({ locals, url }) {
|
|
| 42 |
return Response.json({ message: "Must have session cookie" }, { status: 401 });
|
| 43 |
}
|
| 44 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
return Response.json({ message: "Must have session cookie" }, { status: 401 });
|
| 43 |
}
|
| 44 |
}
|
| 45 |
+
|
| 46 |
+
export async function DELETE({ locals }) {
|
| 47 |
+
if (locals.user?._id || locals.sessionId) {
|
| 48 |
+
await collections.conversations.deleteMany({
|
| 49 |
+
...authCondition(locals),
|
| 50 |
+
});
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
return new Response();
|
| 54 |
+
}
|
src/routes/conversations/+page.server.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
| 1 |
-
import { base } from "$app/paths";
|
| 2 |
-
import { authCondition } from "$lib/server/auth";
|
| 3 |
-
import { collections } from "$lib/server/database";
|
| 4 |
-
import { redirect } from "@sveltejs/kit";
|
| 5 |
-
|
| 6 |
-
export const actions = {
|
| 7 |
-
async delete({ locals }) {
|
| 8 |
-
// double check we have a user to delete conversations for
|
| 9 |
-
if (locals.user?._id || locals.sessionId) {
|
| 10 |
-
await collections.conversations.deleteMany({
|
| 11 |
-
...authCondition(locals),
|
| 12 |
-
});
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
redirect(303, `${base}/`);
|
| 16 |
-
},
|
| 17 |
-
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/routes/settings/(nav)/+page.svelte
CHANGED
|
@@ -1,17 +1,13 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
import Modal from "$lib/components/Modal.svelte";
|
| 3 |
-
import CarbonClose from "~icons/carbon/close";
|
| 4 |
import CarbonTrashCan from "~icons/carbon/trash-can";
|
| 5 |
import CarbonArrowUpRight from "~icons/carbon/arrow-up-right";
|
| 6 |
|
| 7 |
-
import { enhance } from "$app/forms";
|
| 8 |
-
import { base } from "$app/paths";
|
| 9 |
-
|
| 10 |
import { useSettingsStore } from "$lib/stores/settings";
|
| 11 |
import Switch from "$lib/components/Switch.svelte";
|
| 12 |
import { env as envPublic } from "$env/dynamic/public";
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
let settings = useSettingsStore();
|
| 17 |
</script>
|
|
@@ -85,9 +81,20 @@
|
|
| 85 |
><CarbonArrowUpRight class="mr-1.5 shrink-0 text-sm " /> Share your feedback on HuggingChat</a
|
| 86 |
>
|
| 87 |
<button
|
| 88 |
-
onclick={(e) => {
|
| 89 |
e.preventDefault();
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
}}
|
| 92 |
type="submit"
|
| 93 |
class="flex items-center underline decoration-gray-300 underline-offset-2 hover:decoration-gray-700"
|
|
@@ -95,40 +102,4 @@
|
|
| 95 |
>
|
| 96 |
</div>
|
| 97 |
</div>
|
| 98 |
-
|
| 99 |
-
{#if isConfirmingDeletion}
|
| 100 |
-
<Modal on:close={() => (isConfirmingDeletion = false)}>
|
| 101 |
-
<form
|
| 102 |
-
use:enhance={() => {
|
| 103 |
-
isConfirmingDeletion = false;
|
| 104 |
-
}}
|
| 105 |
-
method="post"
|
| 106 |
-
action="{base}/conversations?/delete"
|
| 107 |
-
class="flex w-full flex-col gap-5 p-6"
|
| 108 |
-
>
|
| 109 |
-
<div class="flex items-start justify-between text-xl font-semibold text-gray-800">
|
| 110 |
-
<h2>Are you sure?</h2>
|
| 111 |
-
<button
|
| 112 |
-
type="button"
|
| 113 |
-
class="group"
|
| 114 |
-
onclick={(e) => {
|
| 115 |
-
e.stopPropagation();
|
| 116 |
-
isConfirmingDeletion = false;
|
| 117 |
-
}}
|
| 118 |
-
>
|
| 119 |
-
<CarbonClose class="text-gray-900 group-hover:text-gray-500" />
|
| 120 |
-
</button>
|
| 121 |
-
</div>
|
| 122 |
-
<p class="text-gray-800">
|
| 123 |
-
This action will delete all your conversations. This cannot be undone.
|
| 124 |
-
</p>
|
| 125 |
-
<button
|
| 126 |
-
type="submit"
|
| 127 |
-
class="mt-2 rounded-full bg-red-700 px-5 py-2 text-lg font-semibold text-gray-100 ring-gray-400 ring-offset-1 transition-all hover:ring focus-visible:outline-none focus-visible:ring"
|
| 128 |
-
>
|
| 129 |
-
Confirm deletion
|
| 130 |
-
</button>
|
| 131 |
-
</form>
|
| 132 |
-
</Modal>
|
| 133 |
-
{/if}
|
| 134 |
</div>
|
|
|
|
| 1 |
<script lang="ts">
|
|
|
|
|
|
|
| 2 |
import CarbonTrashCan from "~icons/carbon/trash-can";
|
| 3 |
import CarbonArrowUpRight from "~icons/carbon/arrow-up-right";
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
import { useSettingsStore } from "$lib/stores/settings";
|
| 6 |
import Switch from "$lib/components/Switch.svelte";
|
| 7 |
import { env as envPublic } from "$env/dynamic/public";
|
| 8 |
+
import { goto } from "$app/navigation";
|
| 9 |
+
import { error } from "$lib/stores/errors";
|
| 10 |
+
import { base } from "$app/paths";
|
| 11 |
|
| 12 |
let settings = useSettingsStore();
|
| 13 |
</script>
|
|
|
|
| 81 |
><CarbonArrowUpRight class="mr-1.5 shrink-0 text-sm " /> Share your feedback on HuggingChat</a
|
| 82 |
>
|
| 83 |
<button
|
| 84 |
+
onclick={async (e) => {
|
| 85 |
e.preventDefault();
|
| 86 |
+
|
| 87 |
+
confirm("Are you sure you want to delete all conversations?") &&
|
| 88 |
+
(await fetch(`${base}/api/conversations`, {
|
| 89 |
+
method: "DELETE",
|
| 90 |
+
})
|
| 91 |
+
.then(async () => {
|
| 92 |
+
await goto(`${base}/`, { invalidateAll: true });
|
| 93 |
+
})
|
| 94 |
+
.catch((err) => {
|
| 95 |
+
console.error(err);
|
| 96 |
+
$error = err.message;
|
| 97 |
+
}));
|
| 98 |
}}
|
| 99 |
type="submit"
|
| 100 |
class="flex items-center underline decoration-gray-300 underline-offset-2 hover:decoration-gray-700"
|
|
|
|
| 102 |
>
|
| 103 |
</div>
|
| 104 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
</div>
|