|
|
|
@ -2,10 +2,14 @@ import { readFile, readdir, access } from "fs/promises"; |
|
|
|
|
import path from "path"; |
|
|
|
|
|
|
|
|
|
import matter from "gray-matter"; |
|
|
|
|
import { Client } from "ldapts"; |
|
|
|
|
import { serialize } from "next-mdx-remote/serialize"; |
|
|
|
|
|
|
|
|
|
import { getCurrentTerm } from "@/lib/events"; |
|
|
|
|
|
|
|
|
|
const EXECS_PATH = path.join("content", "team", "execs"); |
|
|
|
|
const fileType = ".md"; |
|
|
|
|
const { year, term } = getCurrentTerm(); |
|
|
|
|
|
|
|
|
|
export interface Metadata { |
|
|
|
|
name: string; |
|
|
|
@ -13,10 +17,39 @@ export interface Metadata { |
|
|
|
|
image: string; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// export async function getExecNames() {
|
|
|
|
|
// return (await readdir(EXECS_PATH))
|
|
|
|
|
// .filter((name) => name.endsWith(fileType))
|
|
|
|
|
// .map((name) => name.slice(0, -1 * fileType.length));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
export async function getExecNames() { |
|
|
|
|
return (await readdir(EXECS_PATH)) |
|
|
|
|
.filter((name) => name.endsWith(fileType)) |
|
|
|
|
.map((name) => name.slice(0, -1 * fileType.length)); |
|
|
|
|
if (process.env.USE_LDAP?.toLowerCase() !== "true") { |
|
|
|
|
return (await readdir(EXECS_PATH)) |
|
|
|
|
.filter((name) => name.endsWith(fileType)) |
|
|
|
|
.map((name) => name.slice(0, -1 * fileType.length)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const url = "ldap://ldap1.csclub.uwaterloo.ca"; |
|
|
|
|
const searchDN = "ou=People,dc=csclub,dc=uwaterloo,dc=ca"; |
|
|
|
|
const client = new Client({ url }); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
await client.bind("", ""); |
|
|
|
|
const { searchEntries } = await client.search(searchDN, { |
|
|
|
|
scope: "sub", |
|
|
|
|
filter: `(&(objectClass=member)(term=${(term as string).slice( |
|
|
|
|
0, |
|
|
|
|
1 |
|
|
|
|
)}${year})(exec=True))`,
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const execMembers = searchEntries.map((item) => item.cn as string); |
|
|
|
|
} finally { |
|
|
|
|
await client.unbind(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return execMembers; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export async function getExec(fileName: string, convert = true) { |
|
|
|
|