diff --git a/src/api/Backend.tsx b/src/api/Backend.tsx index 16133b7fd3f4c75ebc1305a06dfb1f31a6331d56..7d4280f47f5d196c8a3cbeca9426d34ac1c91305 100644 --- a/src/api/Backend.tsx +++ b/src/api/Backend.tsx @@ -1,6 +1,5 @@ import { basePath } from "../../basepath"; import { ApiError } from "./ApiError"; -import DummyBackend from "./DummyBackend"; import type { GetStatusResponse, @@ -62,7 +61,7 @@ export const OBJECT_TYPES = [ "permission", ]; -export type Backend = BackendImpl | DummyBackend; +export type Backend = BackendImpl; export class BackendImpl { private csrfToken?: string; diff --git a/src/api/DummyBackend.tsx b/src/api/DummyBackend.tsx deleted file mode 100644 index da09f5c1bf9219fdb1c2b64b5edb93d3cf9ba7ba..0000000000000000000000000000000000000000 --- a/src/api/DummyBackend.tsx +++ /dev/null @@ -1,433 +0,0 @@ -import { basePath } from "../../basepath"; -import type { - AuthenticationFsmpiRequest, - AuthenticationFsmpiResponse, - AuthenticationPasswordRequest, - AuthenticationStartOAuthRequest, - AuthenticationStartOAuthResponse, - AuthenticationStatusRequest, - AuthenticationStatusResponse, - PutFeedbackNewRequest, - GetFeedbackRequest, - GetFeedbackResponse, - ChapterSuggestionRequest, - CreateConfiguredObjectRequest, - CreateConfiguredObjectResponse, - GetStatusResponse, - GetChangelogRequest, - GetChangelogResponse, - GetConfigurationResponse, - GetCourseLectureResponse, - GetCourseResponse, - GetCoursesResponse, - GetHomepageResponse, - GetJobsRequest, - GetJobsResponse, - GetMySettingsResponse, - GetNewConfigurationResponse, - GetSorterLogResponse, - GetUsersResponse, - JobActionRequest, - ModifyManyObjectsRequest, - SearchResponse, - UpdateConfiguredObjectRequest, - UpdateMySettingsRequest, - id_string, - int, -} from "./api_v1_types"; - -export class DummyBackend { - public isPrivileged = false; - - assetUrl(): string { - return "https://video.fsmpi.rwth-aachen.de/files"; - } - - staticUrl(): string { - return window.location.origin + basePath + "/static"; - } - - // Dummy data for each endpoint - private dummyStatusData: GetStatusResponse = { - status: "available", - is_debug: true, - server_name: "dummy", - announcements: [ - { - id: 1, - type: "info", - visibility: "only_main_page", - text: "Dummy announcement 1", - }, - { - id: 2, - type: "warning", - visibility: "all_pages", - text: "Dummy announcement 2", - }, - ], - }; - - private dummyHomepageData: GetHomepageResponse = { - featured: [ - { - type: "plain", - title: "Wir suchen: sample text!", - text: `Wir brauchen mehr sample text! - - Möchtest du etwas tun, damit es frischen sampletext von deiner sampletext gibt? Du hast die freie Wahl: Zwischen sampletext, sampletext, Live-sampletext, sampletext von Sachen im Hintergrund (sampletextWeb, sampletextGUI, …) und mehr finden wir mit Sicherheit etwas interessantes für dich. - - Wenn du mitmachen möchtest, schreib uns eine E-Mail an sampletext@sampletext.de - wir freuen uns auf dich!`, - }, - { - type: "image", - title: "Featured Lecture", - image_url: "http://example.com/featured-lecture.jpg", - }, - { - type: "lecture", - title: "Latest Lecture", - lecture: { - id: 2001, - course_id: 102, - title: "Advanced Topics in Dummy Data", - speaker: "Prof. Example", - location: "Lecture Hall 1", - time: "2024-04-02T14:00:00", - duration: 90, - description: "A deep dive into advanced dummy data techniques.", - thumbnail_url: "http://example.com/lecture-thumbnail.jpg", - no_recording: false, - livestream_planned: true, - authentication_methods: ["public"], - allow_embed: true, - // chapters and media_sources can be added as needed - }, - }, - { - type: "course_list", - title: "Popular Courses", - courses: [ - 103, - // More courses can be added here - ], - }, - ], - upcoming_lectures: [ - { - id: 3001, - course_id: 104, - title: "Upcoming Lecture on Dummy Data", - speaker: "Dr. Future", - location: "Virtual", - time: "2024-04-10T11:00:00", - duration: 45, - description: "An upcoming lecture discussing future trends in dummy data.", - thumbnail_url: "http://example.com/upcoming-lecture.jpg", - no_recording: false, - livestream_planned: false, - authentication_methods: ["public"], - allow_embed: true, - // chapters and media_sources can be added as needed - }, - // More upcoming lectures can be added here - ], - new_lectures: [ - { - id: 4001, - course_id: 105, - title: "New Lecture on Dummy Data Analysis", - speaker: "Prof. Analyzer", - location: "Auditorium", - time: "2024-04-05T09:30:00", - duration: 60, - description: "A new lecture focusing on analyzing dummy data.", - thumbnail_url: "http://example.com/new-lecture.jpg", - no_recording: true, - livestream_planned: false, - authentication_methods: ["public"], - allow_embed: true, - // chapters and media_sources can be added as needed - }, - // More new lectures can be added here - ], - courses_context: { - "102": { - id: 102, - id_string: "course-102", - full_name: "Intermediate Dummy Data", - short_name: "Dummy 102", - semester: "2024ss", - organizer: "Dr. Intermediate", - topic: "Data Science", - description: "Intermediate level concepts in dummy data creation.", - show_chapters_on_course: false, - default_authentication_methods: ["public"], - // lectures can be added as needed - }, - "103": { - id: 103, - id_string: "course-103", - full_name: "Dummy Data for Experts", - short_name: "Dummy Expert", - semester: "2024ss", - organizer: "Prof. Advanced", - topic: "Advanced Data", - description: "An expert-level course in dummy data creation.", - show_chapters_on_course: true, - default_authentication_methods: ["rwth", "moodle"], - // lectures can be added as needed - }, - "104": { - id: 104, - id_string: "course-104", - full_name: "Dummy Data for Beginners", - short_name: "Dummy Beginner", - semester: "2024ss", - organizer: "Prof. Beginner", - topic: "Data Science", - description: "A beginner-level course in dummy data creation.", - show_chapters_on_course: true, - default_authentication_methods: ["public"], - // lectures can be added as needed - }, - "105": { - id: 105, - id_string: "course-105", - full_name: "Dummy Data Analysis", - short_name: "Dummy Analysis", - semester: "2024ss", - organizer: "Prof. Analyzer", - topic: "Data Science", - description: "A course focusing on analyzing dummy data.", - show_chapters_on_course: true, - default_authentication_methods: ["public"], - // lectures can be added as needed - }, - }, - }; - - private dummyCoursesData: GetCoursesResponse = { - courses: { - "course-101": { - id: 101, - id_string: "course-101", - full_name: "Introduction to Dummy Data", - short_name: "Dummy 101", - semester: "2024ss", - organizer: "Dr. Example", - topic: "Data Science", - description: "A course about creating dummy data.", - show_chapters_on_course: true, - default_authentication_methods: ["public"], - }, - // Add more dummy courses if needed - }, - }; - - private dummyCourseData: GetCourseResponse = { - id: 101, - id_string: "course-101", - full_name: "Introduction to Dummy Data", - short_name: "Dummy 101", - semester: "2024ss", - organizer: "Dr. Example", - topic: "Data Science", - description: "A course about creating dummy data.", - show_chapters_on_course: true, - default_authentication_methods: ["public"], - lectures: [ - // Add dummy lectures data here - ], - }; - - private dummyLectureData: GetCourseLectureResponse = { - lecture: { - id: 1001, - course_id: 101, - title: "Lecture on Dummy Data Creation", - speaker: "Dr. Example", - location: "Online", - time: "2024-04-01T10:00:00", - duration: 60, - description: "An introductory lecture on creating dummy data.", - thumbnail_url: "http://example.com/thumbnail.jpg", - no_recording: false, - livestream_planned: false, - authentication_methods: ["public"], - allow_embed: true, - // chapters and media_sources can be added as needed - }, - }; - - private authenticationFsmpiResponse: AuthenticationFsmpiResponse = {}; - - private authenticationStartOAuthResponse: AuthenticationStartOAuthResponse = { - verification_url: "https://example.com/verify", - }; - - private authenticationStatusResponse: AuthenticationStatusResponse = { - authenticated_methods: ["fsmpi", "password"], - in_progress_authentication: "rwth", - is_lecture_authenticated: true, - }; - - setCsrfToken(csrfToken?: string): void { - // Do nothing - } - - getStatus(): Promise<GetStatusResponse> { - return Promise.resolve(this.dummyStatusData); - } - - getHomepage(): Promise<GetHomepageResponse> { - return Promise.resolve(this.dummyHomepageData); - } - - getCourses(): Promise<GetCoursesResponse> { - return Promise.resolve(this.dummyCoursesData); - } - - getCourse(course_id: int | id_string, include_lectures?: boolean): Promise<GetCourseResponse> { - // Return a dummy course based on the course_id and include_lectures flag - return Promise.resolve(this.dummyCourseData); - } - - getCourseLecture(course_id: int, lecture_id: int): Promise<GetCourseLectureResponse> { - // Return a dummy lecture based on the course_id and lecture_id - return Promise.resolve(this.dummyLectureData); - } - - authenticatePassword(request: AuthenticationPasswordRequest): Promise<{}> { - // Return a promise resolving to the mock response - return Promise.resolve({}); - } - - authenticateFsmpi(request: AuthenticationFsmpiRequest): Promise<AuthenticationFsmpiResponse> { - // Return a promise resolving to the mock response - return Promise.resolve(this.authenticationFsmpiResponse); - } - - startAuthentication( - request: AuthenticationStartOAuthRequest, - ): Promise<AuthenticationStartOAuthResponse> { - // Return a promise resolving to the mock response - return Promise.resolve(this.authenticationStartOAuthResponse); - } - - getAuthenticationStatus( - request?: AuthenticationStatusRequest, - ): Promise<AuthenticationStatusResponse> { - // Return a promise resolving to the mock response - return Promise.resolve(this.authenticationStatusResponse); - } - - putNewFeedback(req: PutFeedbackNewRequest): Promise<{}> { - return Promise.reject("Not implemented"); - } - - getFeedback(req: GetFeedbackRequest): Promise<GetFeedbackResponse> { - return Promise.reject("Not implemented"); - } - - logout(): Promise<void> { - // Return a promise resolving to the mock response - return Promise.resolve(); - } - - getOMConfiguration(object_type: string, object_id: int): Promise<GetConfigurationResponse> { - return Promise.reject("Not implemented"); - } - - getNewOMConfiguration(object_type: string): Promise<GetNewConfigurationResponse> { - return Promise.reject("Not implemented"); - } - - createOMObject( - object_type: string, - request: CreateConfiguredObjectRequest, - ): Promise<CreateConfiguredObjectResponse> { - return Promise.reject("Not implemented"); - } - - updateOMObject( - object_type: string, - object_id: int, - request: UpdateConfiguredObjectRequest, - ): Promise<{}> { - return Promise.reject("Not implemented"); - } - - modifyManyOMObjects(request: ModifyManyObjectsRequest): Promise<{}> { - return Promise.reject("Not implemented"); - } - - deleteOMObject(object_type: string, object_id: int): Promise<{}> { - return Promise.reject("Not implemented"); - } - - suggestChapter(lecture_id: int, request: ChapterSuggestionRequest): Promise<{}> { - return Promise.reject("Not implemented"); - } - - importRWTHOnlineCourse(rwth_course_id: int): Promise<string> { - return Promise.reject("Not implemented"); - } - - getChangelog(req: GetChangelogRequest): Promise<GetChangelogResponse> { - return Promise.reject("Not implemented"); - } - - search(query: string): Promise<SearchResponse> { - return Promise.reject("Not implemented"); - } - - getSorterLog(): Promise<GetSorterLogResponse> { - return Promise.reject("Not implemented"); - } - - deleteSorterErrorLog(log_id: int): Promise<{}> { - return Promise.reject("Not implemented"); - } - - getUsers(): Promise<GetUsersResponse> { - return Promise.reject("Not implemented"); - } - - getMySettings(): Promise<GetMySettingsResponse> { - return Promise.reject("Not implemented"); - } - - updateMySettings(request: UpdateMySettingsRequest): Promise<{}> { - return Promise.reject("Not implemented"); - } - - getJobs(req: GetJobsRequest): Promise<GetJobsResponse> { - return Promise.reject("Not implemented"); - } - - deleteJob(id: int): Promise<{}> { - return Promise.reject("Not implemented"); - } - - jobAction(id: int, action: JobActionRequest["action"]): Promise<{}> { - return Promise.reject("Not implemented"); - } - - // Special method for language files - getLanguageFile(lang: string): Promise<Record<string, string>> { - return fetch(`${this.staticUrl()}/lang/${lang}.json`) - .then((res) => { - if (!res.ok) { - throw new Error(`Cannot load language ${lang}. Status: ${res.status}`); - } - return res.json(); - }) - .catch((error) => { - console.error(`Exception while loading language ${lang}:`, error); - return {}; - }); - } -} - -export default DummyBackend; diff --git a/src/components/BackendProvider.tsx b/src/components/BackendProvider.tsx index 22b56fce4fce2a101fc11a67888e1460373c7935..fb1c5699f438c894cab2cf0c2370dfc507d7acf3 100644 --- a/src/components/BackendProvider.tsx +++ b/src/components/BackendProvider.tsx @@ -1,17 +1,12 @@ import { BackendImpl } from "@/api/Backend"; -import DummyBackend from "@/api/DummyBackend"; import { createContext, useContext, useState } from "react"; import type React from "react"; -const BackendContext = createContext<BackendImpl | DummyBackend>(new DummyBackend()); +const BackendContext = createContext<BackendImpl>(new BackendImpl()); export function RealBackendProvider({ children }: { children: React.ReactNode }) { - const USE_DUMMY = - typeof process.env.NEXT_PUBLIC_DUMMY_BACKEND === "string" && - process.env.NEXT_PUBLIC_DUMMY_BACKEND === "true"; - - let [state, _] = useState(() => (USE_DUMMY ? new DummyBackend() : new BackendImpl())); + let [state, _] = useState(() => new BackendImpl()); return <BackendContext.Provider value={state}>{children}</BackendContext.Provider>; }