Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Assistants settings] Update reported data backend #871

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/routes/settings/+layout.server.ts

This file was deleted.

17 changes: 17 additions & 0 deletions src/routes/settings/assistants/[assistantId]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { PUBLIC_ORIGIN, PUBLIC_SHARE_PREFIX } from "$env/static/public";
import { WEBHOOK_URL_REPORT_ASSISTANT } from "$env/static/private";
import { z } from "zod";
import type { Assistant } from "$lib/types/Assistant";

async function assistantOnlyIfAuthor(locals: App.Locals, assistantId?: string) {
const assistant = await collections.assistants.findOne({ _id: new ObjectId(assistantId) });

Expand All @@ -21,6 +22,22 @@ async function assistantOnlyIfAuthor(locals: App.Locals, assistantId?: string) {
return assistant;
}

export async function load({ params, locals }) {
const assistantId = params.assistantId;
let isReported = false;

const createdBy = locals.user?._id ?? locals.sessionId;
if (createdBy) {
const report = await collections.reports.findOne({
createdBy,
assistantId: new ObjectId(assistantId),
});
isReported = !!report;
}

return { isReported };
}

export const actions: Actions = {
delete: async ({ params, locals }) => {
let assistant;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/settings/assistants/[assistantId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<CarbonCopy class="mr-1.5 inline text-xs" />Duplicate</button
>
</form>
{#if !assistant?.reported}
{#if !data.isReported}
<button
type="button"
on:click={() => {
Expand Down
Loading