feat(api): Add new admin emoji API

This commit is contained in:
Jesse Wierzbinski 2024-05-11 15:27:28 -10:00
parent b979daa39a
commit 8fedd1a07d
No known key found for this signature in database
20 changed files with 954 additions and 167 deletions

View file

@ -1,3 +1,4 @@
import { proxyUrl } from "@response";
import { sanitizedHtmlStrip } from "@sanitization";
import {
type InferInsertModel,
@ -442,7 +443,17 @@ export class Note {
(mention) => mention.instanceId === null,
);
let replacedContent = data.content;
// Rewrite all src tags to go through proxy
let replacedContent = new HTMLRewriter()
.on("[src]", {
element(element) {
element.setAttribute(
"src",
proxyUrl(element.getAttribute("src") ?? "") ?? "",
);
},
})
.transform(data.content);
for (const mention of mentionedLocalUsers) {
replacedContent = replacedContent.replace(

View file

@ -407,6 +407,27 @@ export class User {
return isLocal ? username : `${username}@${baseUrl}`;
}
async update(data: Partial<typeof Users.$inferSelect>) {
const updated = (
await db
.update(Users)
.set({
...data,
updatedAt: new Date().toISOString(),
})
.where(eq(Users.id, this.id))
.returning()
)[0];
const newUser = await User.fromId(updated.id);
if (!newUser) throw new Error("User not found after update");
this.user = newUser.getUser();
return this;
}
toAPI(isOwnAccount = false): APIAccount {
const user = this.getUser();
return {