Skip to content

Commit b7864b8

Browse files
committed
Fixed all conflicts (I think) and merged assistants into react-setup
1 parent 0c60279 commit b7864b8

File tree

4 files changed

+41
-31
lines changed

4 files changed

+41
-31
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Thumbs.db
4242

4343
# Testing and Coverage
4444
coverage/
45-
test/
45+
4646
*.spec.ts
4747

4848
# Debug files
@@ -54,6 +54,8 @@ test/
5454
# Miscellaneous
5555
.temp/
5656
.cache/
57+
58+
# Ignore test files
5759
*.pdf
5860

5961
# Database Files

server/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import express from "express";
22
import sqlite3 from "sqlite3";
33
import cors from "cors";
44
import bodyParser from "body-parser";
5-
import dotenv from "dotenv";
65
import { open, Database } from "sqlite";
76
import dotenv from "dotenv"
87

server/src/routes/admin-router.ts

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import express, { Request, Response, Router, NextFunction } from "express";
22
import { DatabaseController } from "../database-controller";
3-
import { GetQuery, InsertData, RadData, Testing } from "../types";
3+
import { GetQuery, GPTResponse, InsertData, RadData, Testing } from "../types";
44
import axios from "axios";
55
import jwt from "jsonwebtoken";
66
import authenticateJWT from "../auth/jwt-auth";
7+
import { GPTController } from "../gpt-controller";
8+
import multer from "multer";
79

8-
export default function adminRouter(dbController: DatabaseController): Router {
10+
const router = express.Router();
11+
const upload = multer({ dest: "../../pdfData/papers" });
12+
13+
export default function adminRouter(
14+
dbController: DatabaseController,
15+
gptController: GPTController,
16+
): Router {
917
const router = Router();
1018

1119
// This takes a data response from the GUI after fixes have been made.
@@ -30,10 +38,11 @@ export default function adminRouter(dbController: DatabaseController): Router {
3038
router.post(
3139
"/parseRequest",
3240
authenticateJWT,
41+
upload.array("pdfs"),
3342
(req: Request, res: Response) => {
3443
try {
3544
// TODO
36-
parsePapers(req.body).then((result: InsertData[]) => {
45+
parsePapers(req.files, gptController).then((result: GPTResponse[]) => {
3746
res.send(responseToJSON(result));
3847
});
3948
} catch (error) {
@@ -68,30 +77,25 @@ export default function adminRouter(dbController: DatabaseController): Router {
6877
},
6978
);
7079

71-
72-
7380
const casData = casResponse.data; // assumed user CAS info, need to test to see
74-
if (casData.includes('<cas:authenticationSuccess>')) {
75-
const nsid = casData.match(/<cas:user>(.*?)<\/cas:user>/)[1];
76-
console.log(`User logged in with nsid: ${nsid}`);
77-
if (!nsid) {
78-
res.status(401).json({ error: "Invalid CAS Ticket" });
79-
}
80-
81-
if (!allowedNSIDs.includes(nsid)) {
82-
console.log(`User attempted to login with nsid: ${nsid}`);
83-
res.status(403).json({ error: "Access denied" });
84-
}
85-
const token = jwt.sign(
86-
{ username: nsid},
87-
process.env.JWT_SECRET!,
88-
{ expiresIn: "3h" },
89-
);
90-
res.json({token: token, nsid: nsid});
91-
} else {
92-
res.status(401).json({ error: 'CAS authentication failed' });
93-
94-
}
81+
if (casData.includes("<cas:authenticationSuccess>")) {
82+
const nsid = casData.match(/<cas:user>(.*?)<\/cas:user>/)[1];
83+
console.log(`User logged in with nsid: ${nsid}`);
84+
if (!nsid) {
85+
res.status(401).json({ error: "Invalid CAS Ticket" });
86+
}
87+
88+
if (!allowedNSIDs.includes(nsid)) {
89+
console.log(`User attempted to login with nsid: ${nsid}`);
90+
res.status(403).json({ error: "Access denied" });
91+
}
92+
const token = jwt.sign({ username: nsid }, process.env.JWT_SECRET!, {
93+
expiresIn: "3h",
94+
});
95+
res.json({ token: token, nsid: nsid });
96+
} else {
97+
res.status(401).json({ error: "CAS authentication failed" });
98+
}
9599
} catch (error) {
96100
res.status(500).json({ error: "CAS validation failed" });
97101
}
@@ -109,8 +113,13 @@ async function insertRows(
109113
}
110114
}
111115

112-
async function parsePapers(body: any) {
113-
const temp: InsertData[] = [];
116+
async function parsePapers(
117+
files: any,
118+
gptController: GPTController,
119+
): Promise<GPTResponse[]> {
120+
const fileList: string[] = files.forEach((file: any) => file.path);
121+
gptController.runGPTAnalysis(fileList);
122+
const temp: GPTResponse[] = [];
114123
return temp;
115124
}
116125

@@ -127,6 +136,6 @@ function requestFromJSON(body: any): InsertData[] {
127136
});
128137
}
129138

130-
function responseToJSON(radDataArray: RadData[]): string {
139+
function responseToJSON(radDataArray: GPTResponse[]): string {
131140
return JSON.stringify(radDataArray, null, 2); // null and 2 prettify the JSON
132141
}

0 commit comments

Comments
 (0)