From a171b35e97c8931e2466a414a65463f349fb7b11 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Mon, 15 Jan 2024 17:36:24 +0100 Subject: [PATCH] ReviewDB fixes --- src/plugins/reviewDB/auth.tsx | 6 ++-- .../reviewDB/components/ReviewComponent.tsx | 2 +- .../reviewDB/components/ReviewsView.tsx | 9 +++--- src/plugins/reviewDB/reviewDbApi.ts | 31 ++++++++++--------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/plugins/reviewDB/auth.tsx b/src/plugins/reviewDB/auth.tsx index 1d95e47dd..e7a369217 100644 --- a/src/plugins/reviewDB/auth.tsx +++ b/src/plugins/reviewDB/auth.tsx @@ -14,7 +14,7 @@ import { ReviewDBAuth } from "./entities"; const DATA_STORE_KEY = "rdb-auth"; -const OAuth = findByPropsLazy("OAuth2AuthorizeModal"); +const { OAuth2AuthorizeModal } = findByPropsLazy("OAuth2AuthorizeModal"); export let Auth: ReviewDBAuth = {}; @@ -46,7 +46,7 @@ export async function updateAuth(newAuth: ReviewDBAuth) { export function authorize(callback?: any) { openModal(props => - { - // this is terrible, blame ven + // this is terrible, blame mantika const p = filters.byProps; const [ { cozyMessage, buttons, message, buttonsInner, groupStart }, diff --git a/src/plugins/reviewDB/components/ReviewsView.tsx b/src/plugins/reviewDB/components/ReviewsView.tsx index abb856b99..cfd5477db 100644 --- a/src/plugins/reviewDB/components/ReviewsView.tsx +++ b/src/plugins/reviewDB/components/ReviewsView.tsx @@ -28,8 +28,8 @@ import { cl } from "../utils"; import ReviewComponent from "./ReviewComponent"; -const Slate = findByPropsLazy("Editor", "Transforms"); -const InputTypes = findByPropsLazy("ChatInputTypes"); +const { Editor, Transforms } = findByPropsLazy("Editor", "Transforms"); +const { ChatInputTypes } = findByPropsLazy("ChatInputTypes"); const InputComponent = LazyComponent(() => find(m => m.default?.type?.render?.toString().includes("default.CHANNEL_TEXT_AREA")).default); @@ -122,7 +122,7 @@ function ReviewList({ refetch, reviews, hideOwnReview, profileId }: { refetch(): export function ReviewsInputComponent({ discordId, isAuthor, refetch, name }: { discordId: string, name: string; isAuthor: boolean; refetch(): void; }) { const { token } = Auth; const editorRef = useRef(null); - const inputType = InputTypes.ChatInputTypes.FORM; + const inputType = ChatInputTypes.FORM; inputType.disableAutoFocus = true; const channel = { @@ -172,10 +172,9 @@ export function ReviewsInputComponent({ discordId, isAuthor, refetch, name }: { refetch(); const slateEditor = editorRef.current.ref.current.getSlateEditor(); - const { Editor, Transform } = Slate; // clear editor - Transform.delete(slateEditor, { + Transforms.delete(slateEditor, { at: { anchor: Editor.start(slateEditor, []), focus: Editor.end(slateEditor, []), diff --git a/src/plugins/reviewDB/reviewDbApi.ts b/src/plugins/reviewDB/reviewDbApi.ts index a87fbcb8f..657e9c475 100644 --- a/src/plugins/reviewDB/reviewDbApi.ts +++ b/src/plugins/reviewDB/reviewDbApi.ts @@ -19,10 +19,10 @@ import { showToast, Toasts } from "@webpack/common"; import { Auth, authorize, getToken, updateAuth } from "./auth"; -import { Review, ReviewDBCurrentUser, ReviewDBUser } from "./entities"; +import { Review, ReviewDBCurrentUser, ReviewDBUser, ReviewType } from "./entities"; import { settings } from "./settings"; -const API_URL = "https://manti.vendicated.dev"; +const API_URL = "https://manti.vendicated.dev/api/reviewdb"; export const REVIEWS_PER_PAGE = 50; @@ -45,13 +45,13 @@ export async function getReviews(id: string, offset = 0): Promise { flags: String(flags), offset: String(offset) }); - const req = await fetch(`${API_URL}/api/reviewdb/users/${id}/reviews?${params}`); + const req = await fetch(`${API_URL}/users/${id}/reviews?${params}`); const res = (req.status === 200) ? await req.json() as Response : { success: false, - message: "An Error occured while fetching reviews. Please try again later.", + message: req.status === 429 ? "You are sending requests too fast. Wait a few seconds and try again." : "An Error occured while fetching reviews. Please try again later.", reviews: [], updated: false, hasNextPage: false, @@ -65,14 +65,15 @@ export async function getReviews(id: string, offset = 0): Promise { reviews: [ { id: 0, - comment: "An Error occured while fetching reviews. Please try again later.", + comment: res.message, star: 0, timestamp: 0, + type: ReviewType.System, sender: { id: 0, - username: "Error", - profilePhoto: "https://cdn.discordapp.com/attachments/1045394533384462377/1084900598035513447/646808599204593683.png?size=128", - discordID: "0", + username: "ReviewDB", + profilePhoto: "https://cdn.discordapp.com/avatars/1134864775000629298/3f87ad315b32ee464d84f1270c8d1b37.png?size=256&format=webp&quality=lossless", + discordID: "1134864775000629298", badges: [] } } @@ -92,7 +93,7 @@ export async function addReview(review: any): Promise { return null; } - return fetch(API_URL + `/api/reviewdb/users/${review.userid}/reviews`, { + return fetch(API_URL + `/users/${review.userid}/reviews`, { method: "PUT", body: JSON.stringify(review), headers: { @@ -107,7 +108,7 @@ export async function addReview(review: any): Promise { } export async function deleteReview(id: number): Promise { - return fetch(API_URL + `/api/reviewdb/users/${id}/reviews`, { + return fetch(API_URL + `/users/${id}/reviews`, { method: "DELETE", headers: new Headers({ "Content-Type": "application/json", @@ -121,7 +122,7 @@ export async function deleteReview(id: number): Promise { } export async function reportReview(id: number) { - const res = await fetch(API_URL + "/api/reviewdb/reports", { + const res = await fetch(API_URL + "/reports", { method: "PUT", headers: new Headers({ "Content-Type": "application/json", @@ -137,7 +138,7 @@ export async function reportReview(id: number) { } async function patchBlock(action: "block" | "unblock", userId: string) { - const res = await fetch(API_URL + "/api/reviewdb/blocks", { + const res = await fetch(API_URL + "/blocks", { method: "PATCH", headers: new Headers({ "Content-Type": "application/json", @@ -168,7 +169,7 @@ export const blockUser = (userId: string) => patchBlock("block", userId); export const unblockUser = (userId: string) => patchBlock("unblock", userId); export async function fetchBlocks(): Promise { - const res = await fetch(API_URL + "/api/reviewdb/blocks", { + const res = await fetch(API_URL + "/blocks", { method: "GET", headers: new Headers({ Accept: "application/json", @@ -181,14 +182,14 @@ export async function fetchBlocks(): Promise { } export function getCurrentUserInfo(token: string): Promise { - return fetch(API_URL + "/api/reviewdb/users", { + return fetch(API_URL + "/users", { body: JSON.stringify({ token }), method: "POST", }).then(r => r.json()); } export async function readNotification(id: number) { - return fetch(API_URL + `/api/reviewdb/notifications?id=${id}`, { + return fetch(API_URL + `/notifications?id=${id}`, { method: "PATCH", headers: { "Authorization": await getToken() || "",