Skip to content

Commit

Permalink
Merge pull request #215 from sinamics/bug_fix
Browse files Browse the repository at this point in the history
Added session validation for mkworld download api
  • Loading branch information
sinamics committed Nov 19, 2023
2 parents f329b75 + a294613 commit c10f8c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/pages/api/mkworld/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { PassThrough } from "stream";
import { execSync } from "child_process";
import { updateLocalConf } from "~/utils/planet";
import { ZT_FOLDER } from "~/utils/ztApi";
import { getServerSession } from "next-auth/next";
import { authOptions } from "~/server/auth";

export const config = {
api: {
Expand All @@ -18,6 +20,12 @@ export const config = {
};

export default async (req: NextApiRequest, res: NextApiResponse) => {
const session = await getServerSession(req, res, authOptions);
if (!session) {
res.status(401).json({ message: "Authorization Error" });
return;
}

if (req.method === "GET") {
try {
const folderPath = path.resolve(`${ZT_FOLDER}/zt-mkworld`);
Expand Down
4 changes: 4 additions & 0 deletions src/pages/api/planet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export const config = {
};

export default async (req: NextApiRequest, res: NextApiResponse) => {
// download planet file.
// The planet.custom is signed by the server, so it can be trusted.
// No authentication is required.

if (req.method === "GET") {
try {
const folderPath = path.resolve(`${ZT_FOLDER}/zt-mkworld`);
Expand Down

0 comments on commit c10f8c5

Please sign in to comment.