mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
day of linting judgement
This commit is contained in:
@@ -43,7 +43,8 @@ export function getAxiosErrorMessage(error: AxiosError) {
|
||||
console.log("response error", error.response);
|
||||
const responseErrorText =
|
||||
typeof error.response.data === "object"
|
||||
? (error.response.data as any).error
|
||||
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(error.response.data as any).error
|
||||
: error.response.data;
|
||||
|
||||
if (
|
||||
|
||||
@@ -15,6 +15,7 @@ export const canvasPageService = {
|
||||
url,
|
||||
});
|
||||
return pages.flatMap((pageList) => pageList);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} catch (error: any) {
|
||||
if (error?.response?.status === 403) {
|
||||
console.log(
|
||||
|
||||
@@ -72,6 +72,7 @@ const createQuestionOnly = async (
|
||||
const hackFixQuestionOrdering = async (
|
||||
canvasCourseId: number,
|
||||
canvasQuizId: number,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
questionAndPositions: Array<{ question: any; position: number }>
|
||||
) => {
|
||||
console.log("Fixing question order");
|
||||
@@ -149,6 +150,7 @@ export const canvasQuizService = {
|
||||
? new Date(quiz.lock_at).toLocaleString()
|
||||
: undefined,
|
||||
}));
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} catch (error: any) {
|
||||
if (error?.response?.status === 403) {
|
||||
console.log(
|
||||
|
||||
@@ -33,10 +33,10 @@ const getNextUrl = (
|
||||
return nextUrl;
|
||||
};
|
||||
|
||||
export async function paginatedRequest<T extends any[]>(request: {
|
||||
export async function paginatedRequest<T extends unknown[]>(request: {
|
||||
url: string;
|
||||
}): Promise<T> {
|
||||
var requestCount = 1;
|
||||
let requestCount = 1;
|
||||
const url = new URL(request.url);
|
||||
url.searchParams.set("per_page", "100");
|
||||
|
||||
@@ -44,8 +44,8 @@ export async function paginatedRequest<T extends any[]>(request: {
|
||||
url.toString()
|
||||
);
|
||||
|
||||
var returnData = Array.isArray(firstData) ? [...firstData] : [firstData]; // terms come across as nested objects {enrolmentTerms: terms[]}
|
||||
var nextUrl = getNextUrl(firstHeaders);
|
||||
let returnData = Array.isArray(firstData) ? [...firstData] : [firstData]; // terms come across as nested objects {enrolmentTerms: terms[]}
|
||||
let nextUrl = getNextUrl(firstHeaders);
|
||||
|
||||
while (nextUrl) {
|
||||
requestCount += 1;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { AxiosResponse } from "axios";
|
||||
import { axiosClient } from "../axiosUtils";
|
||||
|
||||
type FetchOptions = Omit<RequestInit, "method">;
|
||||
|
||||
const rateLimitRetryCount = 6;
|
||||
const rateLimitSleepInterval = 1000;
|
||||
|
||||
@@ -18,21 +16,21 @@ export const isRateLimited = async (
|
||||
);
|
||||
};
|
||||
|
||||
const rateLimitAwarePost = async (url: string, body: any, retryCount = 0) => {
|
||||
const response = await axiosClient.post(url, body);
|
||||
// const rateLimitAwarePost = async (url: string, body: unknown, retryCount = 0) => {
|
||||
// const response = await axiosClient.post(url, body);
|
||||
|
||||
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 rateLimitAwarePost(url, body, retryCount + 1);
|
||||
}
|
||||
}
|
||||
// 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 rateLimitAwarePost(url, body, retryCount + 1);
|
||||
// }
|
||||
// }
|
||||
|
||||
return response;
|
||||
};
|
||||
// return response;
|
||||
// };
|
||||
|
||||
export const rateLimitAwareDelete = async (
|
||||
url: string,
|
||||
|
||||
@@ -120,7 +120,7 @@ export const courseItemFileStorageService = {
|
||||
);
|
||||
|
||||
const markdownDictionary: {
|
||||
[key in CourseItemType]: () => string;
|
||||
[_key in CourseItemType]: () => string;
|
||||
} = {
|
||||
Assignment: () =>
|
||||
assignmentMarkdownSerializer.toMarkdown(item as LocalAssignment),
|
||||
|
||||
@@ -102,6 +102,7 @@ export async function deleteLecture(
|
||||
await fs.access(lecturePath); // throws error if no file
|
||||
await fs.unlink(lecturePath);
|
||||
console.log(`File deleted: ${lecturePath}`);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} catch (error: any) {
|
||||
if (error?.code === "ENOENT") {
|
||||
console.log(`Cannot delete lecture, file does not exist: ${lecturePath}`);
|
||||
|
||||
@@ -75,7 +75,7 @@ export const settingsFileStorageService = {
|
||||
const courseDirectory = path.join(basePath, courseName);
|
||||
const settingsPath = path.join(courseDirectory, "settings.yml");
|
||||
|
||||
const { name, ...settingsWithoutName } = settings;
|
||||
const { name: _, ...settingsWithoutName } = settings;
|
||||
|
||||
const settingsMarkdown =
|
||||
localCourseYamlUtils.settingsToYaml(settingsWithoutName);
|
||||
|
||||
@@ -3,7 +3,6 @@ import { marked } from "marked";
|
||||
import DOMPurify from "isomorphic-dompurify";
|
||||
import { LocalCourseSettings } from "@/models/local/localCourseSettings";
|
||||
import markedKatex from "marked-katex-extension";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
marked.use(
|
||||
markedKatex({
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { useState } from "react";
|
||||
import superjson from "superjson";
|
||||
import { httpBatchLink } from "@trpc/client";
|
||||
import { trpc } from "./trpcClient";
|
||||
import { trpc, TRPCProvider } from "./trpcClient";
|
||||
import { getQueryClient } from "@/app/providersQueryClientUtils";
|
||||
import { isServer } from "@tanstack/react-query";
|
||||
|
||||
@@ -13,6 +13,7 @@ export default function TrpcProvider({
|
||||
}) {
|
||||
const url = isServer ? "http://localhost:3000/api/trpc/" : "/api/trpc";
|
||||
|
||||
const queryClient = getQueryClient();
|
||||
const [trpcClient] = useState(() =>
|
||||
trpc.createClient({
|
||||
links: [
|
||||
@@ -25,9 +26,14 @@ export default function TrpcProvider({
|
||||
})
|
||||
);
|
||||
|
||||
// return (
|
||||
// <trpc.Provider client={trpcClient} queryClient={getQueryClient()}>
|
||||
// {children}
|
||||
// </trpc.Provider>
|
||||
// );
|
||||
return (
|
||||
<trpc.Provider client={trpcClient} queryClient={getQueryClient()}>
|
||||
<TRPCProvider trpcClient={trpcClient} queryClient={queryClient}>
|
||||
{children}
|
||||
</trpc.Provider>
|
||||
</TRPCProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import publicProcedure from "../procedures/public";
|
||||
import { z } from "zod";
|
||||
import { router } from "../trpcSetup";
|
||||
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
||||
import { zodLocalAssignment } from "@/models/local/assignment/localAssignment";
|
||||
|
||||
export const directoriesRouter = router({
|
||||
getEmptyDirectories: publicProcedure.query(async () => {
|
||||
|
||||
@@ -3,7 +3,6 @@ import { z } from "zod";
|
||||
import { router } from "../trpcSetup";
|
||||
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
||||
import { zodLocalCourseSettings } from "@/models/local/localCourseSettings";
|
||||
import { trpc } from "../trpcClient";
|
||||
import {
|
||||
getLectures,
|
||||
updateLecture,
|
||||
|
||||
@@ -13,7 +13,7 @@ describe("FileStorageTests", () => {
|
||||
try {
|
||||
await fs.access(storageDirectory);
|
||||
await fs.rm(storageDirectory, { recursive: true });
|
||||
} catch (error) {}
|
||||
} catch {}
|
||||
await fs.mkdir(storageDirectory, { recursive: true });
|
||||
});
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ describe("FileStorageTests", () => {
|
||||
try {
|
||||
await fs.access(storageDirectory);
|
||||
await fs.rm(storageDirectory, { recursive: true });
|
||||
} catch (error) {}
|
||||
} catch {}
|
||||
await fs.mkdir(storageDirectory, { recursive: true });
|
||||
});
|
||||
|
||||
@@ -75,7 +75,7 @@ a) truthy
|
||||
// `${basePath}/${courseName}/${moduleName}/quizzes/testQuiz.md`,
|
||||
// invalidQuizMarkdown
|
||||
// );
|
||||
|
||||
|
||||
// const invalidReasons = await fileStorageService.quizzes.getInvalidQuizzes(
|
||||
// courseName,
|
||||
// moduleName
|
||||
|
||||
@@ -1,49 +1,50 @@
|
||||
import toast, { ErrorIcon, CheckmarkIcon } from "react-hot-toast";
|
||||
import toast, { CheckmarkIcon } from "react-hot-toast";
|
||||
import { ReactNode } from "react";
|
||||
import { MutationCache, QueryCache, QueryClient } from "@tanstack/react-query";
|
||||
|
||||
const addErrorAsToast = async (error: any) => {
|
||||
console.error("error from toast", error);
|
||||
const message = getErrorMessage(error);
|
||||
// const addErrorAsToast = async (error: unknown) => {
|
||||
// console.error("error from toast", error);
|
||||
// const message = getErrorMessage(error);
|
||||
|
||||
toast(
|
||||
(t: any) => (
|
||||
<div className="row">
|
||||
<div className="col-auto my-auto">
|
||||
<ErrorIcon />
|
||||
</div>
|
||||
<div className="col my-auto">
|
||||
<div className="white-space">{message}</div>
|
||||
<div>
|
||||
<a
|
||||
href="https://snow.kualibuild.com/app/651eeebc32976c013a4c4739/run"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
Report Bug
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-auto my-auto">
|
||||
<button
|
||||
onClick={() => toast.dismiss(t.id)}
|
||||
className="btn btn-outline-secondary btn-sm"
|
||||
>
|
||||
<i className="bi bi-x"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
{
|
||||
duration: Infinity,
|
||||
}
|
||||
);
|
||||
};
|
||||
// toast(
|
||||
// (t) => (
|
||||
// <div className="row">
|
||||
// <div className="col-auto my-auto">
|
||||
// <ErrorIcon />
|
||||
// </div>
|
||||
// <div className="col my-auto">
|
||||
// <div className="white-space">{message}</div>
|
||||
// <div>
|
||||
// <a
|
||||
// href="https://snow.kualibuild.com/app/651eeebc32976c013a4c4739/run"
|
||||
// target="_blank"
|
||||
// rel="noreferrer"
|
||||
// >
|
||||
// Report Bug
|
||||
// </a>
|
||||
// </div>
|
||||
// </div>
|
||||
// <div className="col-auto my-auto">
|
||||
// <button
|
||||
// onClick={() => toast.dismiss(t.id)}
|
||||
// className="btn btn-outline-secondary btn-sm"
|
||||
// >
|
||||
// <i className="bi bi-x"></i>
|
||||
// </button>
|
||||
// </div>
|
||||
// </div>
|
||||
// ),
|
||||
// {
|
||||
// duration: Infinity,
|
||||
// }
|
||||
// );
|
||||
// };
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function getErrorMessage(error: any) {
|
||||
if (error?.response?.status === 422) {
|
||||
console.log(error.response.data.detail);
|
||||
const serializationMessages = error.response.data.detail.map(
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(d: any) => `${d.type} - ${d.loc[1]}`
|
||||
);
|
||||
return `Deserialization error on request:\n${serializationMessages.join(
|
||||
@@ -66,12 +67,8 @@ export function createInfoToast(
|
||||
children: ReactNode,
|
||||
onClose: () => void = () => {}
|
||||
) {
|
||||
const closeHandler = (t: any) => {
|
||||
toast.dismiss(t.id);
|
||||
onClose();
|
||||
};
|
||||
toast(
|
||||
(t: any) => (
|
||||
(t) => (
|
||||
<div className="row">
|
||||
<div className="col-auto my-auto">
|
||||
<i className="bi bi-info-circle-fill"></i>
|
||||
@@ -79,7 +76,10 @@ export function createInfoToast(
|
||||
<div className="col my-auto">{children}</div>
|
||||
<div className="col-auto my-auto">
|
||||
<button
|
||||
onClick={() => closeHandler(t)}
|
||||
onClick={() => {
|
||||
toast.dismiss(t.id);
|
||||
onClose();
|
||||
}}
|
||||
className="btn btn-outline-secondary py-1"
|
||||
>
|
||||
<i className="bi-x-lg" />
|
||||
@@ -98,7 +98,7 @@ export function createInfoToast(
|
||||
|
||||
export function createSuccessToast(message: string) {
|
||||
toast(
|
||||
(t: any) => (
|
||||
(t) => (
|
||||
<div className="row">
|
||||
<div className="col-auto my-auto">
|
||||
<CheckmarkIcon />
|
||||
|
||||
Reference in New Issue
Block a user