Skip to content

Commit

Permalink
Merge branch 'main' of github.com:tekdi/shiksha-admin into release-1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
itsvick committed Oct 14, 2024
2 parents 8f81028 + 8e8b1f2 commit 450b20c
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 92 deletions.
56 changes: 53 additions & 3 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ const remotes = (isServer) => {
};
};

const PORTAL_BASE_URL = "https://staging.sunbirded.org";

const routes = {
API: {
GENERAL: {
CONTENT_PREVIEW: "/content/preview/:path*",
CONTENT_PLUGINS: "/content-plugins/:path*",
GENERIC_EDITOR: "/generic-editor/:path*",
CONTENT_EDITOR: "/editor/content/:path*",
ASSET_IMAGE: "/assets/images/:path*",
},
},
};

const nextConfig = {
eslint: {
// Disabling on production builds because we're running checks on PRs via GitHub Actions.
Expand All @@ -33,12 +47,24 @@ const nextConfig = {
return [
{
source: "/action/asset/v1/upload/:identifier*", // Match asset upload routes
destination: `${process.env.WORKSPACE_BASE_URL}/api/fileUpload`, // Forward asset uploads to fileUpload.js
destination: '/api/fileUpload' // Forward asset uploads to fileUpload proxy
},
{
source: "/action/content/v3/upload/url/:identifier*", // Match content upload with 'url' in the path
destination: `${process.env.WORKSPACE_BASE_URL}/api/proxy?path=/action/content/v3/upload/url/:identifier*`, // Forward to proxy route with path as query param
},
{
source: '/action/content/v3/upload/:identifier*', // Match content upload routes
destination: '/api/fileUpload', // Forward asset uploads to fileUpload proxy
},
{
source: "/action/asset/:path*", // Match other /action/asset routes
destination: `${process.env.WORKSPACE_BASE_URL}/api/proxy?path=/action/asset/:path*`, // Forward other /action/asset requests to proxy.js
},
{
source: "/action/content/:path*", // Match other /action/asset routes
destination: `${process.env.WORKSPACE_BASE_URL}/api/proxy?path=/action/content/:path*`, // Forward other /action/asset requests to proxy.js
},
{
source: "/action/:path*", // Match any other routes starting with /action/
destination: `${process.env.WORKSPACE_BASE_URL}/api/proxy?path=/action/:path*`, // Forward them to proxy.js
Expand All @@ -48,8 +74,32 @@ const nextConfig = {
destination: `${process.env.WORKSPACE_BASE_URL}/api/proxy?path=/api/:path*`, // Forward them to proxy.js
},
{
source: "/assets/public/:path*", // Match any URL starting with /assets/public/
destination: `${process.env.CLOUD_STORAGE_URL}/:path*`, // Forward to S3, stripping "/assets/public"
source: '/assets/public/:path*', // Match any URL starting with /assets/public/
destination: `${process.env.WORKSPACE_BASE_URL}/assets/public/:path*`, // Forward to workspace proxy
},
{
source: routes.API.GENERAL.CONTENT_PREVIEW,
destination: `${PORTAL_BASE_URL}${routes.API.GENERAL.CONTENT_PREVIEW}`, // Proxy to portal
},
{
source: routes.API.GENERAL.CONTENT_PLUGINS,
destination: `${PORTAL_BASE_URL}${routes.API.GENERAL.CONTENT_PLUGINS}`, // Proxy to portal
},
{
source: routes.API.GENERAL.GENERIC_EDITOR,
destination: `${PORTAL_BASE_URL}${routes.API.GENERAL.GENERIC_EDITOR}`, // Proxy to portal
},
{
source: routes.API.GENERAL.CONTENT_EDITOR,
destination: `${PORTAL_BASE_URL}${routes.API.GENERAL.CONTENT_EDITOR}`, // Proxy to portal
},
{
source: routes.API.GENERAL.ASSET_IMAGE,
destination: `${PORTAL_BASE_URL}${routes.API.GENERAL.ASSET_IMAGE}`, // Proxy to portal
},
{
source: "/app/telemetry", // Match telemetry route
destination: `${process.env.WORKSPACE_BASE_URL}/api/telemetry`, // Redirect to telemetry proxy
},
];
},
Expand Down
4 changes: 2 additions & 2 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export default function Document() {
<Head>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@project-sunbird/sunbird-questionset-editor-web-component/styles.css"
href="https://cdn.jsdelivr.net/npm/@tekdi/sunbird-questionset-editor-web-component@3.0.1/styles.css"
/>
<script
src="https://cdn.jsdelivr.net/npm/@project-sunbird/sunbird-questionset-editor-web-component/sunbird-questionset-editor.js"
src="https://cdn.jsdelivr.net/npm/@tekdi/sunbird-questionset-editor-web-component@3.0.1/sunbird-questionset-editor.js"
async
></script>
</Head>
Expand Down
56 changes: 56 additions & 0 deletions src/pages/api/fileUpload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { NextApiRequest, NextApiResponse } from 'next';

export const config = {
api: {
bodyParser: false, // Disable body parsing so we can handle it manually
},
};

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
console.log('req.url ====>', req.url)
if (req.method === 'POST') {
try {
// Create a new Headers object to ensure valid header types
const headers = new Headers();

// Forward the incoming request headers, filtering out invalid headers
for (const [key, value] of Object.entries(req.headers)) {
// Exclude 'content-length' as it can cause issues
if (key.toLowerCase() !== 'content-length') {
headers.append(key, value as string);
}
}

// Read the request body as a stream
const body = await new Promise<Buffer>((resolve, reject) => {
const chunks: Buffer[] = [];
req.on('data', (chunk) => {
chunks.push(Buffer.from(chunk));
});
req.on('end', () => {
resolve(Buffer.concat(chunks));
});
req.on('error', (err) => {
reject(err);
});
});

// Forward the request to the middleware API
const response = await fetch(`${process.env.WORKSPACE_BASE_URL}` + `${req.url}`, {
method: 'POST',
headers: headers, // Use the new Headers object
body, // Pass the request body as a Buffer
});

// Forward the middleware response back to the client
const data = await response.json();
res.status(response.status).json(data);
} catch (error) {
console.error('Error proxying request:', error);
res.status(500).json({ error: 'Internal Server Error' });
}
} else {
res.setHeader('Allow', ['POST']);
res.status(405).end(`Method ${req.method} Not Allowed`);
}
}
31 changes: 14 additions & 17 deletions src/pages/editor.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import React from 'react'
import dynamic from 'next/dynamic';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';

import React from "react";
import dynamic from "next/dynamic";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";

// @ts-ignore
const Editors = dynamic(() => import('editor/Editor'), { ssr: false });
const Editors = dynamic(() => import("editor/Editor"), { ssr: false });

const Editor = () => {
return (
<Editors />
)
}

export default Editor
return <Editors />;
};

export default Editor;

export async function getStaticProps({ locale }: any) {
return {
props: {
...(await serverSideTranslations(locale, ["common"])),
},
};
}
return {
props: {
noLayout: true,
...(await serverSideTranslations(locale, ["common"])),
},
};
}
4 changes: 2 additions & 2 deletions src/pages/importCsv.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ const ImportCsv = () => {
>
{t("COURSE_PLANNER.IMPORT_PLANNER")}
</Button>
<Button
{/* <Button
variant="outlined"
sx={{
borderRadius: "8px",
Expand All @@ -364,7 +364,7 @@ const ImportCsv = () => {
onClick={handleRemoveFile}
>
{t("COURSE_PLANNER.REMOVE_FILE")}
</Button>
</Button> */}
<Button
sx={{
borderRadius: "8px",
Expand Down
24 changes: 24 additions & 0 deletions src/pages/upload-editor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'
import dynamic from 'next/dynamic';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';


// @ts-ignore
const UploadEditor = dynamic(() => import('editor/UploadEditor'), { ssr: false });

const Editor = () => {
return (
<UploadEditor />
)
}

export default Editor

export async function getStaticProps({ locale }: any) {
return {
props: {
noLayout: true,
...(await serverSideTranslations(locale, ["common"])),
},
};
}
21 changes: 9 additions & 12 deletions src/pages/workspace/content/allContents/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import React from 'react'
import dynamic from 'next/dynamic';

import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import React from "react";
import dynamic from "next/dynamic";

// @ts-ignore
const Content = dynamic(() => import('editor/Content'), { ssr: false });
const Content = dynamic(() => import("editor/Content"), { ssr: false });

const content = () => {
return (
<Content />
)
}

export default content
return <Content />;
};

export default content;

export async function getStaticProps({ locale }: any) {
return {
props: {
noLayout: true,
...(await serverSideTranslations(locale, ["common"])),
},
};
}
}
21 changes: 9 additions & 12 deletions src/pages/workspace/content/create/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import React from 'react'
import dynamic from 'next/dynamic';

import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import React from "react";
import dynamic from "next/dynamic";

// @ts-ignore
const Create = dynamic(() => import('editor/Create'), { ssr: false });
const Create = dynamic(() => import("editor/Create"), { ssr: false });

const create = () => {
return (
<Create />
)
}

export default create
return <Create />;
};

export default create;

export async function getStaticProps({ locale }: any) {
return {
props: {
noLayout: true,
...(await serverSideTranslations(locale, ["common"])),
},
};
}
}
21 changes: 9 additions & 12 deletions src/pages/workspace/content/draft/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import React from 'react'
import dynamic from 'next/dynamic';

import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import React from "react";
import dynamic from "next/dynamic";

// @ts-ignore
const Draft = dynamic(() => import('editor/Draft'), { ssr: false });
const Draft = dynamic(() => import("editor/Draft"), { ssr: false });

const draft = () => {
return (
<Draft />
)
}

export default draft
return <Draft />;
};

export default draft;

export async function getStaticProps({ locale }: any) {
return {
props: {
noLayout: true,
...(await serverSideTranslations(locale, ["common"])),
},
};
}
}
21 changes: 9 additions & 12 deletions src/pages/workspace/content/publish/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import React from 'react'
import dynamic from 'next/dynamic';

import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import React from "react";
import dynamic from "next/dynamic";

// @ts-ignore
const Publish = dynamic(() => import('editor/Publish'), { ssr: false });
const Publish = dynamic(() => import("editor/Publish"), { ssr: false });

const publish = () => {
return (
<Publish />
)
}

export default publish
return <Publish />;
};

export default publish;

export async function getStaticProps({ locale }: any) {
return {
props: {
noLayout: true,
...(await serverSideTranslations(locale, ["common"])),
},
};
}
}
Loading

0 comments on commit 450b20c

Please sign in to comment.