Skip to content

Commit

Permalink
cleanup(api): removed pdf export utils
Browse files Browse the repository at this point in the history
In its current state, this functionality is too computationally intensive for our production servers. Therefore, one should resort to the `@rimun/pdf` command line tools.
  • Loading branch information
marinoandrea committed Feb 29, 2024
1 parent f9561b5 commit 9530bc1
Show file tree
Hide file tree
Showing 10 changed files with 0 additions and 952 deletions.
74 changes: 0 additions & 74 deletions packages/rimun-api/src/services/exports/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import * as ftp from "basic-ftp";
import { randomUUID } from "crypto";
import { mkdir, readFile, rm } from "fs/promises";
import { ftpConfig } from "../../storage";
import { authenticatedProcedure, trpc } from "../../trpc";
import { checkPersonPermission, getCurrentSession } from "../utils";
import { generateBadges } from "./pdf";

const ATTENDEES_TSV_HEADER = [
"Name",
Expand Down Expand Up @@ -54,75 +49,6 @@ const exportsRouter = trpc.router({

return output;
}),

generateBadge: authenticatedProcedure.query(async ({ ctx }) => {
const currentSession = await getCurrentSession(ctx);

const result = await ctx.prisma.personApplication.findMany({
where: {
session_id: currentSession.id,
status_application: "ACCEPTED",
},
include: {
person: { include: { account: true, country: true } },
school: { include: { country: true } },
confirmed_group: true,
confirmed_role: true,
committee: true,
delegation: { include: { country: true } },
},
});

// TODO: move into storage
const ftpClient = new ftp.Client();
await ftpClient.access(ftpConfig as ftp.AccessOptions);

const pictures = new Map<string, string>();

try {
await mkdir("temp");
} catch (e) {
console.error(e);
}

for (const attendee of result) {
const path = attendee.person.picture_path;
const ext = path.split(".")[1];

const tempFileName = `temp/${randomUUID()}.${ext}`;
try {
await ftpClient.downloadTo(tempFileName, path);
pictures.set(path, tempFileName);
} catch {
continue;
}
}

const badges = await generateBadges(
result,
currentSession,
async (path) => {
const tempFileName = pictures.get(path);

if (!tempFileName) {
return null;
}

const data = await readFile(tempFileName);
return data;
}
);

ftpClient.close();

try {
await rm("temp", { recursive: true, force: true });
} catch (e) {
console.error(e);
}

return badges;
}),
});

export default exportsRouter;

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 9530bc1

Please sign in to comment.