Spaces:
Build error
Build error
[Assisntats reports] Minor fixes (#827)
Browse files* [Assisntats reports] Minor fixes
* Update src/routes/settings/assistants/[assistantId]/+page.server.ts
Co-authored-by: Nathan Sarrazin <[email protected]>
---------
Co-authored-by: Nathan Sarrazin <[email protected]>
src/routes/settings/assistants/[assistantId]/+page.server.ts
CHANGED
@@ -6,6 +6,7 @@ import { base } from "$app/paths";
|
|
6 |
import { PUBLIC_ORIGIN, PUBLIC_SHARE_PREFIX } from "$env/static/public";
|
7 |
import { WEBHOOK_URL_REPORT_ASSISTANT } from "$env/static/private";
|
8 |
import { z } from "zod";
|
|
|
9 |
async function assistantOnlyIfAuthor(locals: App.Locals, assistantId?: string) {
|
10 |
const assistant = await collections.assistants.findOne({ _id: new ObjectId(assistantId) });
|
11 |
|
@@ -88,18 +89,22 @@ export const actions: Actions = {
|
|
88 |
const prefixUrl = PUBLIC_SHARE_PREFIX || `${PUBLIC_ORIGIN || url.origin}${base}`;
|
89 |
const assistantUrl = `${prefixUrl}/assistant/${params.assistantId}`;
|
90 |
|
91 |
-
const assistant = await collections.assistants.findOne(
|
92 |
{ _id: new ObjectId(params.assistantId) },
|
93 |
{ projection: { name: 1 } }
|
94 |
);
|
95 |
|
|
|
|
|
96 |
const res = await fetch(WEBHOOK_URL_REPORT_ASSISTANT, {
|
97 |
method: "POST",
|
98 |
headers: {
|
99 |
"Content-type": "application/json",
|
100 |
},
|
101 |
body: JSON.stringify({
|
102 |
-
text: `Assistant <${assistantUrl}|${assistant?.name}> reported by
|
|
|
|
|
103 |
}),
|
104 |
});
|
105 |
|
|
|
6 |
import { PUBLIC_ORIGIN, PUBLIC_SHARE_PREFIX } from "$env/static/public";
|
7 |
import { WEBHOOK_URL_REPORT_ASSISTANT } from "$env/static/private";
|
8 |
import { z } from "zod";
|
9 |
+
import type { Assistant } from "$lib/types/Assistant";
|
10 |
async function assistantOnlyIfAuthor(locals: App.Locals, assistantId?: string) {
|
11 |
const assistant = await collections.assistants.findOne({ _id: new ObjectId(assistantId) });
|
12 |
|
|
|
89 |
const prefixUrl = PUBLIC_SHARE_PREFIX || `${PUBLIC_ORIGIN || url.origin}${base}`;
|
90 |
const assistantUrl = `${prefixUrl}/assistant/${params.assistantId}`;
|
91 |
|
92 |
+
const assistant = await collections.assistants.findOne<Pick<Assistant, "name">>(
|
93 |
{ _id: new ObjectId(params.assistantId) },
|
94 |
{ projection: { name: 1 } }
|
95 |
);
|
96 |
|
97 |
+
const username = locals.user?.username;
|
98 |
+
|
99 |
const res = await fetch(WEBHOOK_URL_REPORT_ASSISTANT, {
|
100 |
method: "POST",
|
101 |
headers: {
|
102 |
"Content-type": "application/json",
|
103 |
},
|
104 |
body: JSON.stringify({
|
105 |
+
text: `Assistant <${assistantUrl}|${assistant?.name}> reported by ${
|
106 |
+
username ? `<http://hf.co/${username}|${username}>` : "non-logged in user"
|
107 |
+
}.\n\n> ${result.data}`,
|
108 |
}),
|
109 |
});
|
110 |
|