mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
added a lot of canvas data types
This commit is contained in:
33
nextjs/src/app/globals.css
Normal file
33
nextjs/src/app/globals.css
Normal file
@@ -0,0 +1,33 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
:root {
|
||||
--foreground-rgb: 0, 0, 0;
|
||||
--background-start-rgb: 214, 219, 220;
|
||||
--background-end-rgb: 255, 255, 255;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--foreground-rgb: 255, 255, 255;
|
||||
--background-start-rgb: 0, 0, 0;
|
||||
--background-end-rgb: 0, 0, 0;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
color: rgb(var(--foreground-rgb));
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
transparent,
|
||||
rgb(var(--background-end-rgb))
|
||||
)
|
||||
rgb(var(--background-start-rgb));
|
||||
}
|
||||
|
||||
@layer utilities {
|
||||
.text-balance {
|
||||
text-wrap: balance;
|
||||
}
|
||||
}
|
||||
22
nextjs/src/app/layout.tsx
Normal file
22
nextjs/src/app/layout.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Inter } from "next/font/google";
|
||||
import "./globals.css";
|
||||
|
||||
const inter = Inter({ subsets: ["latin"] });
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Create Next App",
|
||||
description: "Generated by create next app",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body className={inter.className}>{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
9
nextjs/src/app/page.tsx
Normal file
9
nextjs/src/app/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import Image from "next/image";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<main className="flex min-h-screen flex-col items-center justify-between p-24">
|
||||
|
||||
</main>
|
||||
);
|
||||
}
|
||||
7
nextjs/src/models/canvas/assignments/CanvasLockInfo.ts
Normal file
7
nextjs/src/models/canvas/assignments/CanvasLockInfo.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export interface CanvasLockInfo {
|
||||
asset_string: string;
|
||||
unlock_at?: string; // ISO 8601 date string
|
||||
lock_at?: string; // ISO 8601 date string
|
||||
context_module?: any;
|
||||
manually_locked?: boolean;
|
||||
}
|
||||
82
nextjs/src/models/canvas/assignments/canvasAssignment.ts
Normal file
82
nextjs/src/models/canvas/assignments/canvasAssignment.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { DiscussionTopicModel } from "../discussions/canvasDiscussionModelTopic";
|
||||
import { SubmissionModel } from "../submissions/canvasSubmissionModel";
|
||||
import { CanvasAssignmentDate } from "./canvasAssignmentDate";
|
||||
import { CanvasAssignmentOverride } from "./canvasAssignmentOverride";
|
||||
import { CanvasExternalToolTagAttributes } from "./canvasExternalToolTagAttributes";
|
||||
import { CanvasLockInfo } from "./CanvasLockInfo";
|
||||
import { CanvasRubricCriteria } from "./canvasRubricCriteria";
|
||||
import { CanvasTurnitinSettings } from "./canvasTurnitinSettings";
|
||||
|
||||
export interface CanvasAssignment {
|
||||
id: number;
|
||||
name: string;
|
||||
description: string;
|
||||
created_at: string; // ISO 8601 date string
|
||||
has_overrides: boolean;
|
||||
course_id: number;
|
||||
html_url: string;
|
||||
submissions_download_url: string;
|
||||
assignment_group_id: number;
|
||||
due_date_required: boolean;
|
||||
max_name_length: number;
|
||||
peer_reviews: boolean;
|
||||
automatic_peer_reviews: boolean;
|
||||
position: number;
|
||||
grading_type: string;
|
||||
published: boolean;
|
||||
unpublishable: boolean;
|
||||
only_visible_to_overrides: boolean;
|
||||
locked_for_user: boolean;
|
||||
moderated_grading: boolean;
|
||||
grader_count: number;
|
||||
allowed_attempts: number;
|
||||
is_quiz_assignment: boolean;
|
||||
submission_types: string[];
|
||||
updated_at?: string; // ISO 8601 date string
|
||||
due_at?: string; // ISO 8601 date string
|
||||
lock_at?: string; // ISO 8601 date string
|
||||
unlock_at?: string; // ISO 8601 date string
|
||||
all_dates?: CanvasAssignmentDate[];
|
||||
allowed_extensions?: string[];
|
||||
turnitin_enabled?: boolean;
|
||||
vericite_enabled?: boolean;
|
||||
turnitin_settings?: CanvasTurnitinSettings;
|
||||
grade_group_students_individually?: boolean;
|
||||
external_tool_tag_attributes?: CanvasExternalToolTagAttributes;
|
||||
peer_review_count?: number;
|
||||
peer_reviews_assign_at?: string; // ISO 8601 date string
|
||||
intra_group_peer_reviews?: boolean;
|
||||
group_category_id?: number;
|
||||
needs_grading_count?: number;
|
||||
needs_grading_count_by_section?: {
|
||||
section_id: string;
|
||||
needs_grading_count: number;
|
||||
}[];
|
||||
post_to_sis?: boolean;
|
||||
integration_id?: string;
|
||||
integration_data?: any;
|
||||
muted?: boolean;
|
||||
points_possible?: number;
|
||||
has_submitted_submissions?: boolean;
|
||||
grading_standard_id?: number;
|
||||
lock_info?: CanvasLockInfo;
|
||||
lock_explanation?: string;
|
||||
quiz_id?: number;
|
||||
anonymous_submissions?: boolean;
|
||||
discussion_topic?: DiscussionTopicModel;
|
||||
freeze_on_copy?: boolean;
|
||||
frozen?: boolean;
|
||||
frozen_attributes?: string[];
|
||||
submission?: SubmissionModel;
|
||||
use_rubric_for_grading?: boolean;
|
||||
rubric_settings?: any;
|
||||
rubric?: CanvasRubricCriteria[];
|
||||
assignment_visibility?: number[];
|
||||
overrides?: CanvasAssignmentOverride[];
|
||||
omit_from_final_grade?: boolean;
|
||||
final_grader_id?: number;
|
||||
grader_comments_visible_to_graders?: boolean;
|
||||
graders_anonymous_to_graders?: boolean;
|
||||
grader_names_visible_to_final_grader?: boolean;
|
||||
anonymous_grading?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export interface CanvasAssignmentDate {
|
||||
title: string;
|
||||
id?: number;
|
||||
base?: boolean;
|
||||
due_at?: string; // ISO 8601 date string
|
||||
unlock_at?: string; // ISO 8601 date string
|
||||
lock_at?: string; // ISO 8601 date string
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
export interface CanvasAssignmentOverride {
|
||||
id: number;
|
||||
assignment_id: number;
|
||||
course_section_id: number;
|
||||
title: string;
|
||||
student_ids?: number[];
|
||||
group_id?: number;
|
||||
due_at?: string; // ISO 8601 date string
|
||||
all_day?: boolean;
|
||||
all_day_date?: string; // ISO 8601 date string
|
||||
unlock_at?: string; // ISO 8601 date string
|
||||
lock_at?: string; // ISO 8601 date string
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export interface CanvasExternalToolTagAttributes {
|
||||
url: string;
|
||||
resource_link_id: string;
|
||||
new_tab?: boolean;
|
||||
}
|
||||
13
nextjs/src/models/canvas/assignments/canvasRubric.ts
Normal file
13
nextjs/src/models/canvas/assignments/canvasRubric.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export interface CanvasRubric {
|
||||
id?: number;
|
||||
title: string;
|
||||
context_id: number;
|
||||
context_type: string;
|
||||
points_possible: number;
|
||||
reusable: boolean;
|
||||
read_only: boolean;
|
||||
hide_score_total?: boolean;
|
||||
// Uncomment and define if needed
|
||||
// data: CanvasRubricCriteria[];
|
||||
// free_form_criterion_comments?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
export interface CanvasRubricAssociation {
|
||||
id: number;
|
||||
rubric_id: number;
|
||||
association_id: number;
|
||||
association_type: string;
|
||||
use_for_grading: boolean;
|
||||
summary_data?: string;
|
||||
purpose: string;
|
||||
hide_score_total?: boolean;
|
||||
hide_points: boolean;
|
||||
hide_outcome_results: boolean;
|
||||
}
|
||||
16
nextjs/src/models/canvas/assignments/canvasRubricCriteria.ts
Normal file
16
nextjs/src/models/canvas/assignments/canvasRubricCriteria.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export interface CanvasRubricCriteria {
|
||||
id: string;
|
||||
description: string;
|
||||
long_description: string;
|
||||
points?: number;
|
||||
learning_outcome_id?: string;
|
||||
vendor_guid?: string;
|
||||
criterion_use_range?: boolean;
|
||||
ratings?: {
|
||||
points: number;
|
||||
id: string;
|
||||
description: string;
|
||||
long_description: string;
|
||||
}[];
|
||||
ignore_for_scoring?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
export interface CanvasTurnitinSettings {
|
||||
originality_report_visibility: string;
|
||||
s_paper_check: boolean;
|
||||
internet_check: boolean;
|
||||
journal_check: boolean;
|
||||
exclude_biblio: boolean;
|
||||
exclude_quoted: boolean;
|
||||
exclude_small_matches_type?: boolean;
|
||||
exclude_small_matches_value?: number;
|
||||
}
|
||||
3
nextjs/src/models/canvas/courses/calendarLinkModel.ts
Normal file
3
nextjs/src/models/canvas/courses/calendarLinkModel.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export interface CalendarLinkModel {
|
||||
ics: string;
|
||||
}
|
||||
54
nextjs/src/models/canvas/courses/courseModel.ts
Normal file
54
nextjs/src/models/canvas/courses/courseModel.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { EnrollmentModel } from "../enrollments/enrollmentModel";
|
||||
import { CalendarLinkModel } from "./calendarLinkModel";
|
||||
import { CourseProgressModel } from "./courseProgressModel";
|
||||
import { TermModel } from "./termModel";
|
||||
|
||||
export interface CourseModel {
|
||||
id: number;
|
||||
sis_course_id: string;
|
||||
uuid: string;
|
||||
integration_id: string;
|
||||
name: string;
|
||||
course_code: string;
|
||||
workflow_state: string;
|
||||
account_id: number;
|
||||
root_account_id: number;
|
||||
enrollment_term_id: number;
|
||||
created_at: string; // ISO 8601 date string
|
||||
locale: string;
|
||||
calendar: CalendarLinkModel;
|
||||
default_view: string;
|
||||
syllabus_body: string;
|
||||
permissions: { [key: string]: boolean };
|
||||
storage_quota_mb: number;
|
||||
storage_quota_used_mb: number;
|
||||
license: string;
|
||||
course_format: string;
|
||||
time_zone: string;
|
||||
sis_import_id?: number;
|
||||
grading_standard_id?: number;
|
||||
start_at?: string; // ISO 8601 date string
|
||||
end_at?: string; // ISO 8601 date string
|
||||
enrollments?: EnrollmentModel[];
|
||||
total_students?: number;
|
||||
needs_grading_count?: number;
|
||||
term?: TermModel;
|
||||
course_progress?: CourseProgressModel;
|
||||
apply_assignment_group_weights?: boolean;
|
||||
is_public?: boolean;
|
||||
is_public_to_auth_users?: boolean;
|
||||
public_syllabus?: boolean;
|
||||
public_syllabus_to_auth?: boolean;
|
||||
public_description?: string;
|
||||
hide_final_grades?: boolean;
|
||||
allow_student_assignment_edits?: boolean;
|
||||
allow_wiki_comments?: boolean;
|
||||
allow_student_forum_attachments?: boolean;
|
||||
open_enrollment?: boolean;
|
||||
self_enrollment?: boolean;
|
||||
restrict_enrollments_to_course_dates?: boolean;
|
||||
access_restricted_by_date?: boolean;
|
||||
blueprint?: boolean;
|
||||
blueprint_restrictions?: { [key: string]: boolean };
|
||||
blueprint_restrictions_by_object_type?: { [key: string]: { [key: string]: boolean } };
|
||||
}
|
||||
6
nextjs/src/models/canvas/courses/courseProgressModel.ts
Normal file
6
nextjs/src/models/canvas/courses/courseProgressModel.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export interface CourseProgressModel {
|
||||
requirement_count?: number;
|
||||
requirement_completed_count?: number;
|
||||
next_requirement_url?: string;
|
||||
completed_at?: string; // ISO 8601 date string
|
||||
}
|
||||
16
nextjs/src/models/canvas/courses/courseSettingsModel.ts
Normal file
16
nextjs/src/models/canvas/courses/courseSettingsModel.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export interface CourseSettingsModel {
|
||||
allow_final_grade_override: boolean;
|
||||
allow_student_discussion_topics: boolean;
|
||||
allow_student_forum_attachments: boolean;
|
||||
allow_student_discussion_editing: boolean;
|
||||
grading_standard_enabled: boolean;
|
||||
allow_student_organized_groups: boolean;
|
||||
hide_final_grades: boolean;
|
||||
hide_distribution_graphs: boolean;
|
||||
lock_all_announcements: boolean;
|
||||
restrict_student_past_view: boolean;
|
||||
restrict_student_future_view: boolean;
|
||||
show_announcements_on_home_page: boolean;
|
||||
home_page_announcement_limit: number;
|
||||
grading_standard_id?: number;
|
||||
}
|
||||
6
nextjs/src/models/canvas/courses/termModel.ts
Normal file
6
nextjs/src/models/canvas/courses/termModel.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export interface TermModel {
|
||||
id: number;
|
||||
name: string;
|
||||
start_at?: string; // ISO 8601 date string
|
||||
end_at?: string; // ISO 8601 date string
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { UserDisplayModel } from "../users/userDisplayModel";
|
||||
import { FileAttachmentModel } from "./canvasFileAttachmentModel";
|
||||
|
||||
export interface DiscussionTopicModel {
|
||||
id: number;
|
||||
title: string;
|
||||
message: string;
|
||||
html_url: string;
|
||||
read_state: string;
|
||||
subscription_hold: string;
|
||||
assignment_id: number;
|
||||
lock_explanation: string;
|
||||
user_name: string;
|
||||
topic_children: number[];
|
||||
podcast_url: string;
|
||||
discussion_type: string;
|
||||
attachments: FileAttachmentModel[];
|
||||
permissions: { [key: string]: boolean };
|
||||
author: UserDisplayModel;
|
||||
unread_count?: number;
|
||||
subscribed?: boolean;
|
||||
posted_at?: string; // ISO 8601 date string
|
||||
last_reply_at?: string; // ISO 8601 date string
|
||||
require_initial_post?: boolean;
|
||||
user_can_see_posts?: boolean;
|
||||
discussion_subentry_count?: number;
|
||||
delayed_post_at?: string; // ISO 8601 date string
|
||||
published?: boolean;
|
||||
lock_at?: string; // ISO 8601 date string
|
||||
locked?: boolean;
|
||||
pinned?: boolean;
|
||||
locked_for_user?: boolean;
|
||||
lock_info?: any;
|
||||
group_topic_children?: any;
|
||||
root_topic_id?: number;
|
||||
group_category_id?: number;
|
||||
allow_rating?: boolean;
|
||||
only_graders_can_rate?: boolean;
|
||||
sort_by_rating?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export interface FileAttachmentModel {
|
||||
content_type: string;
|
||||
url: string;
|
||||
filename: string;
|
||||
display_name: string;
|
||||
}
|
||||
48
nextjs/src/models/canvas/enrollments/enrollmentModel.ts
Normal file
48
nextjs/src/models/canvas/enrollments/enrollmentModel.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { UserDisplayModel } from "../users/userDisplayModel";
|
||||
import { GradeModel } from "./gradeModel";
|
||||
|
||||
export interface EnrollmentModel {
|
||||
id: number;
|
||||
course_id: number;
|
||||
enrollment_state: string;
|
||||
type: string;
|
||||
user_id: number;
|
||||
role: string;
|
||||
role_id: number;
|
||||
html_url: string;
|
||||
grades: GradeModel;
|
||||
user: UserDisplayModel;
|
||||
override_grade: string;
|
||||
sis_course_id?: string;
|
||||
course_integration_id?: string;
|
||||
course_section_id?: number;
|
||||
section_integration_id?: string;
|
||||
sis_account_id?: string;
|
||||
sis_section_id?: string;
|
||||
sis_user_id?: string;
|
||||
limit_privileges_to_course_section?: boolean;
|
||||
sis_import_id?: number;
|
||||
root_account_id?: number;
|
||||
associated_user_id?: number;
|
||||
created_at?: string; // ISO 8601 date string
|
||||
updated_at?: string; // ISO 8601 date string
|
||||
start_at?: string; // ISO 8601 date string
|
||||
end_at?: string; // ISO 8601 date string
|
||||
last_activity_at?: string; // ISO 8601 date string
|
||||
last_attended_at?: string; // ISO 8601 date string
|
||||
total_activity_time?: number;
|
||||
override_score?: number;
|
||||
unposted_current_grade?: string;
|
||||
unposted_final_grade?: string;
|
||||
unposted_current_score?: string;
|
||||
unposted_final_score?: string;
|
||||
has_grading_periods?: boolean;
|
||||
totals_for_all_grading_periods_option?: boolean;
|
||||
current_grading_period_title?: string;
|
||||
current_grading_period_id?: number;
|
||||
current_period_override_grade?: string;
|
||||
current_period_override_score?: number;
|
||||
current_period_unposted_final_score?: number;
|
||||
current_period_unposted_current_grade?: string;
|
||||
current_period_unposted_final_grade?: string;
|
||||
}
|
||||
11
nextjs/src/models/canvas/enrollments/gradeModel.ts
Normal file
11
nextjs/src/models/canvas/enrollments/gradeModel.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export interface GradeModel {
|
||||
html_url?: string;
|
||||
current_grade?: number;
|
||||
final_grade?: number;
|
||||
current_score?: number;
|
||||
final_score?: number;
|
||||
unposted_current_grade?: number;
|
||||
unposted_final_grade?: number;
|
||||
unposted_current_score?: number;
|
||||
unposted_final_score?: number;
|
||||
}
|
||||
18
nextjs/src/models/canvas/modules/canvasModule.ts
Normal file
18
nextjs/src/models/canvas/modules/canvasModule.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { CanvasModuleItem } from "./canvasModuleItems";
|
||||
|
||||
export interface CanvasModule {
|
||||
id: number;
|
||||
workflow_state: string;
|
||||
position: number;
|
||||
name: string;
|
||||
unlock_at?: string; // ISO 8601 date string
|
||||
require_sequential_progress?: boolean;
|
||||
prerequisite_module_ids?: number[];
|
||||
items_count: number;
|
||||
items_url: string;
|
||||
items?: CanvasModuleItem[];
|
||||
state?: string;
|
||||
completed_at?: string; // ISO 8601 date string
|
||||
publish_final_grade?: boolean;
|
||||
published?: boolean;
|
||||
}
|
||||
28
nextjs/src/models/canvas/modules/canvasModuleItems.ts
Normal file
28
nextjs/src/models/canvas/modules/canvasModuleItems.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
export interface CanvasModuleItem {
|
||||
id: number;
|
||||
module_id: number;
|
||||
position: number;
|
||||
title: string;
|
||||
indent?: number;
|
||||
type: string;
|
||||
content_id?: number;
|
||||
html_url: string;
|
||||
url?: string;
|
||||
page_url?: string;
|
||||
external_url?: string;
|
||||
new_tab: boolean;
|
||||
completion_requirement?: {
|
||||
type: string;
|
||||
min_score?: number;
|
||||
completed?: boolean;
|
||||
};
|
||||
published?: boolean;
|
||||
content_details?: CanvasModuleItemContentDetails;
|
||||
}
|
||||
|
||||
export interface CanvasModuleItemContentDetails {
|
||||
due_at?: string; // ISO 8601 date string
|
||||
lock_at?: string; // ISO 8601 date string
|
||||
points_possible: number;
|
||||
locked_for_user: boolean;
|
||||
}
|
||||
16
nextjs/src/models/canvas/pages/canvasPageModel.ts
Normal file
16
nextjs/src/models/canvas/pages/canvasPageModel.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export interface CanvasPage {
|
||||
page_id: number;
|
||||
url: string;
|
||||
title: string;
|
||||
published: boolean;
|
||||
front_page: boolean;
|
||||
body?: string;
|
||||
// Uncomment and define if needed
|
||||
// created_at: string; // ISO 8601 date string
|
||||
// updated_at: string; // ISO 8601 date string
|
||||
// editing_roles: string;
|
||||
// last_edited_by: UserDisplayModel;
|
||||
// locked_for_user: boolean;
|
||||
// lock_info?: LockInfoModel;
|
||||
// lock_explanation?: string;
|
||||
}
|
||||
44
nextjs/src/models/canvas/quizzes/canvasQuizModel.ts
Normal file
44
nextjs/src/models/canvas/quizzes/canvasQuizModel.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { CanvasLockInfo } from "../assignments/CanvasLockInfo";
|
||||
import { CanvasQuizPermissions } from "./canvasQuizPermission";
|
||||
|
||||
export interface CanvasQuiz {
|
||||
id: number;
|
||||
title: string;
|
||||
html_url: string;
|
||||
mobile_url: string;
|
||||
preview_url?: string;
|
||||
description: string;
|
||||
quiz_type: string;
|
||||
assignment_group_id?: number;
|
||||
time_limit?: number;
|
||||
shuffle_answers?: boolean;
|
||||
hide_results?: string;
|
||||
show_correct_answers?: boolean;
|
||||
show_correct_answers_last_attempt?: boolean;
|
||||
show_correct_answers_at?: string; // ISO 8601 date string
|
||||
hide_correct_answers_at?: string; // ISO 8601 date string
|
||||
one_time_results?: boolean;
|
||||
scoring_policy?: string;
|
||||
allowed_attempts: number;
|
||||
one_question_at_a_time?: boolean;
|
||||
question_count?: number;
|
||||
points_possible?: number;
|
||||
cant_go_back?: boolean;
|
||||
access_code?: string;
|
||||
ip_filter?: string;
|
||||
due_at?: string; // ISO 8601 date string
|
||||
lock_at?: string; // ISO 8601 date string
|
||||
unlock_at?: string; // ISO 8601 date string
|
||||
published?: boolean;
|
||||
unpublishable?: boolean;
|
||||
locked_for_user?: boolean;
|
||||
lock_info?: CanvasLockInfo;
|
||||
lock_explanation?: string;
|
||||
speedgrader_url?: string;
|
||||
quiz_extensions_url?: string;
|
||||
permissions: CanvasQuizPermissions;
|
||||
all_dates?: any; // Depending on the structure of the dates, this could be further specified
|
||||
version_number?: number;
|
||||
question_types?: string[];
|
||||
anonymous_submissions?: boolean;
|
||||
}
|
||||
9
nextjs/src/models/canvas/quizzes/canvasQuizPermission.ts
Normal file
9
nextjs/src/models/canvas/quizzes/canvasQuizPermission.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface CanvasQuizPermissions {
|
||||
read: boolean;
|
||||
submit: boolean;
|
||||
create: boolean;
|
||||
manage: boolean;
|
||||
read_statistics: boolean;
|
||||
review_grades: boolean;
|
||||
update: boolean;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { CanvasAssignment } from "../assignments/canvasAssignment";
|
||||
import { CourseModel } from "../courses/courseModel";
|
||||
import { UserModel } from "../users/canvasUserModel";
|
||||
import { UserDisplayModel } from "../users/userDisplayModel";
|
||||
|
||||
export interface SubmissionModel {
|
||||
assignment_id: number;
|
||||
grade: string;
|
||||
html_url: string;
|
||||
preview_url: string;
|
||||
submission_type: string;
|
||||
user_id: number;
|
||||
user: UserModel;
|
||||
workflow_state: string;
|
||||
late_policy_status: string;
|
||||
assignment?: CanvasAssignment;
|
||||
course?: CourseModel;
|
||||
attempt?: number;
|
||||
body?: string;
|
||||
grade_matches_current_submission?: boolean;
|
||||
score?: number;
|
||||
submission_comments?: {
|
||||
id: number;
|
||||
author_id: number;
|
||||
author_name: string;
|
||||
author: UserDisplayModel;
|
||||
comment: string;
|
||||
created_at: string; // ISO 8601 date string
|
||||
edited_at?: string; // ISO 8601 date string
|
||||
media_comment?: {
|
||||
content_type: string;
|
||||
display_name: string;
|
||||
media_id: string;
|
||||
media_type: string;
|
||||
url: string;
|
||||
};
|
||||
}[];
|
||||
submitted_at?: string; // ISO 8601 date string
|
||||
url?: string;
|
||||
grader_id?: number;
|
||||
graded_at?: string; // ISO 8601 date string
|
||||
late?: boolean;
|
||||
assignment_visible?: boolean;
|
||||
excused?: boolean;
|
||||
missing?: boolean;
|
||||
points_deducted?: number;
|
||||
seconds_late?: number;
|
||||
extra_attempts?: number;
|
||||
anonymous_id?: string;
|
||||
}
|
||||
21
nextjs/src/models/canvas/users/canvasUserModel.ts
Normal file
21
nextjs/src/models/canvas/users/canvasUserModel.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { EnrollmentModel } from "../enrollments/enrollmentModel";
|
||||
|
||||
export interface UserModel {
|
||||
id: number;
|
||||
name: string;
|
||||
sortable_name: string;
|
||||
short_name: string;
|
||||
sis_user_id: string;
|
||||
integration_id: string;
|
||||
login_id: string;
|
||||
avatar_url: string;
|
||||
enrollments: EnrollmentModel[];
|
||||
email: string;
|
||||
locale: string;
|
||||
effective_locale: string;
|
||||
time_zone: string;
|
||||
bio: string;
|
||||
permissions: { [key: string]: boolean };
|
||||
sis_import_id?: number;
|
||||
last_login?: string; // ISO 8601 date string
|
||||
}
|
||||
9
nextjs/src/models/canvas/users/userDisplayModel.ts
Normal file
9
nextjs/src/models/canvas/users/userDisplayModel.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface UserDisplayModel {
|
||||
avatar_image_url: string;
|
||||
html_url: string;
|
||||
anonymous_id: string;
|
||||
id?: number;
|
||||
short_name?: string;
|
||||
display_name?: string;
|
||||
pronouns?: string;
|
||||
}
|
||||
199
nextjs/src/services/canvas/requestUtils.ts
Normal file
199
nextjs/src/services/canvas/requestUtils.ts
Normal file
@@ -0,0 +1,199 @@
|
||||
|
||||
type FetchOptions = Omit<RequestInit, "method">;
|
||||
|
||||
const token = process.env.CANVAS_TOKEN;
|
||||
if (!token) {
|
||||
throw new Error("CANVAS_TOKEN not in environment");
|
||||
}
|
||||
|
||||
const baseUrl = `${process.env.CANVAS_URL}/api/v1/`;
|
||||
const rateLimitRetryCount = 6;
|
||||
const rateLimitSleepInterval = 1000;
|
||||
|
||||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
const isRateLimited = async (response: Response): Promise<boolean> => {
|
||||
const content = await response.text();
|
||||
return (
|
||||
response.status === 403 &&
|
||||
content.includes("403 Forbidden (Rate Limit Exceeded)")
|
||||
);
|
||||
};
|
||||
|
||||
const deserialize = async <T>(response: Response): Promise<T | null> => {
|
||||
if (!response.ok) {
|
||||
console.error(`Error with response to ${response.url} ${response.status}`);
|
||||
throw new Error(
|
||||
`Error with response to ${response.url} ${response.status}`
|
||||
);
|
||||
}
|
||||
try {
|
||||
return (await response.json()) as T;
|
||||
} catch (e) {
|
||||
console.error(`An error occurred during deserialization: ${e}`);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
const rateLimitAwarePostAsync = async (
|
||||
url: string,
|
||||
options: FetchOptions,
|
||||
retryCount = 0
|
||||
): Promise<Response> => {
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
method: "POST",
|
||||
headers: {
|
||||
...options.headers,
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (await isRateLimited(response)) {
|
||||
if (retryCount < rateLimitRetryCount) {
|
||||
console.info(
|
||||
`Hit rate limit on post, retry count is ${retryCount} / ${rateLimitRetryCount}, retrying`
|
||||
);
|
||||
await sleep(rateLimitSleepInterval);
|
||||
return await rateLimitAwarePostAsync(url, options, retryCount + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
const content = await response.text();
|
||||
console.error(`Error with response, response content: ${content}`);
|
||||
throw new Error(
|
||||
`Error post response, retrycount: ${retryCount}, ratelimited: ${await isRateLimited(
|
||||
response
|
||||
)}, code: ${response.status}, response content: ${content}`
|
||||
);
|
||||
}
|
||||
return response;
|
||||
};
|
||||
|
||||
const recursiveDeleteAsync = async (
|
||||
url: string,
|
||||
options: FetchOptions,
|
||||
retryCount = 0
|
||||
): Promise<Response> => {
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
...options.headers,
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (await isRateLimited(response)) {
|
||||
console.info("After delete response in rate limited");
|
||||
await sleep(rateLimitSleepInterval);
|
||||
return await recursiveDeleteAsync(url, options, retryCount + 1);
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (e) {
|
||||
const error = e as Error & { response?: Response };
|
||||
if (error.response?.status === 403) {
|
||||
if (retryCount < rateLimitRetryCount) {
|
||||
console.info(
|
||||
`Hit rate limit in delete, retry count is ${retryCount} / ${rateLimitRetryCount}, retrying`
|
||||
);
|
||||
await sleep(rateLimitSleepInterval);
|
||||
return await recursiveDeleteAsync(url, options, retryCount + 1);
|
||||
} else {
|
||||
console.info(
|
||||
`Hit rate limit in delete, ${rateLimitRetryCount} retries did not fix it`
|
||||
);
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
export const WebRequestor = {
|
||||
getManyAsync: async <T>(
|
||||
url: string,
|
||||
options: FetchOptions = {}
|
||||
): Promise<[T[] | null, Response]> => {
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
method: "GET",
|
||||
headers: {
|
||||
...options.headers,
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
return [await deserialize<T[]>(response), response];
|
||||
},
|
||||
|
||||
getAsync: async <T>(
|
||||
url: string,
|
||||
options: FetchOptions = {}
|
||||
): Promise<[T | null, Response]> => {
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
method: "GET",
|
||||
headers: {
|
||||
...options.headers,
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
return [await deserialize<T>(response), response];
|
||||
},
|
||||
|
||||
postAsync: async (
|
||||
url: string,
|
||||
options: FetchOptions = {}
|
||||
): Promise<Response> => {
|
||||
return await rateLimitAwarePostAsync(url, options);
|
||||
},
|
||||
|
||||
postAsyncWithDeserialize: async <T>(
|
||||
url: string,
|
||||
options: FetchOptions = {}
|
||||
): Promise<[T | null, Response]> => {
|
||||
const response = await rateLimitAwarePostAsync(url, options);
|
||||
return [await deserialize<T>(response), response];
|
||||
},
|
||||
|
||||
putAsync: async (
|
||||
url: string,
|
||||
options: FetchOptions = {}
|
||||
): Promise<Response> => {
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
method: "PUT",
|
||||
headers: {
|
||||
...options.headers,
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
return response;
|
||||
},
|
||||
|
||||
putAsyncWithDeserialize: async <T>(
|
||||
url: string,
|
||||
options: FetchOptions = {}
|
||||
): Promise<[T | null, Response]> => {
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
method: "PUT",
|
||||
headers: {
|
||||
...options.headers,
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
return [await deserialize<T>(response), response];
|
||||
},
|
||||
|
||||
deleteAsync: async (
|
||||
url: string,
|
||||
options: FetchOptions = {}
|
||||
): Promise<Response> => {
|
||||
return await recursiveDeleteAsync(url, options);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user