Skip to content

Commit

Permalink
build fix
Browse files Browse the repository at this point in the history
  • Loading branch information
NishantGupta2325 committed Jun 16, 2024
1 parent 3726ddd commit 3d0e8f3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const config = {
"rules": {
"@typescript-eslint/array-type": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/consistent-type-imports": [
"warn",
{
Expand Down
10 changes: 4 additions & 6 deletions src/app/api/papers/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ export async function POST(req: Request, res: Response) {
try {
await connectToDatabase();
const body = (await req.json()) as IPaper;
const { tag, slot, subject, exam, year } = body;
const result = cloudinary.v2.uploader.multi(tag, {
format: "pdf",
transformation: { crop: "fill", gravity: "auto" },
});
const { urls, slot, subject, exam, year } = body;
// @ts-expect-error: cloudinary was dumb this time
const result = cloudinary.v2.uploader.multi({urls: urls, format: "pdf"})
console.log(result);
return NextResponse.json(tag);
return NextResponse.json(urls);
} catch (error) {
return NextResponse.json(
{ message: "Failed to fetch papers", error },
Expand Down
12 changes: 7 additions & 5 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"use client";
import React, { useCallback, useState, useEffect, use } from "react";
import { PDFDocument } from "pdf-lib";
import React, { useState, useEffect } from "react";
import axios from "axios";
import { CldUploadWidget } from "next-cloudinary";
import { CloudinaryUploadWidgetProps } from "@/interface";

const Upload: React.FC = () => {
const [subject, setSubject] = useState<string>("dcnjddc");
const [slot, setSlot] = useState<string>("dcscddc");
const [year, setYear] = useState<string>("ccdd");
const [exam, setExam] = useState<string>("cat1");
const [tag, setTag] = useState<string>();
const [urls, setUrls] = useState<string[]>();
useEffect(() => {
async function makeTage() {
const timestamp = Date.now();
Expand All @@ -23,7 +24,7 @@ const Upload: React.FC = () => {
async function completeUpload() {
console.log();
const body = {
tag: tag,
urls: urls,
subject: subject,
slot: slot,
year: year,
Expand Down Expand Up @@ -54,8 +55,9 @@ const Upload: React.FC = () => {
maxFiles: 5,
tags: [tag],
}}
onSuccess={(results) => {
console.log("Upload successful:", results.info);
onSuccess={(results: CloudinaryUploadWidgetProps) => {
//@ts-expect-error: ts being an ass
setUrls((prevUrls) => [...(prevUrls ?? []), results.info?.url]);
}}
onClose={(result) => console.log(result)}
>
Expand Down
2 changes: 1 addition & 1 deletion src/db/papers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import mongoose, { Schema, Document, Model } from "mongoose";
import { IPaper } from "@/interface";

const paperSchema = new Schema<IPaper>({
tag: { type: String, required: true },
urls: { type: [String], required: true },
subject: { type: String, required: true },
slot: { type: String, required: true },
year: { type: String, required: true },
Expand Down
6 changes: 5 additions & 1 deletion src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ export interface CloudinaryUploadResult {
url: string;
}

export interface CloudinaryUploadWidgetProps {
info?: CloudinaryUploadResult | undefined | string;
}

export interface PostRequestBody {
tags: string;
}

export interface IPaper{
tag: string;
urls: Array<string>;
subject: string;
slot: string;
year: string;
Expand Down

0 comments on commit 3d0e8f3

Please sign in to comment.