Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft vil 382/import doc #916

Merged
merged 5 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 179 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
issuer: /\.[jt]sx?$/,
use: ['@svgr/webpack'],
});
config.resolve.alias.canvas = false;
return config;
},
experimental: { esmExternals: false },
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
},
"devDependencies": {
"@next/eslint-plugin-next": "^12.1.6",
"@react-pdf/types": "^2.5.0",
"@svgr/webpack": "6.2.1",
"@swc/cli": "^0.1.57",
"@swc/core": "1.2.205",
Expand Down Expand Up @@ -179,6 +180,7 @@
"query-string": "^7.1.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-pdf": "^8.0.0",
"react-player": "^2.10.1",
"react-query": "^3.39.2",
"resize-observer-polyfill": "^1.5.1",
Expand Down
4 changes: 2 additions & 2 deletions server/controllers/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const CREATE_SCHEMA: JSONSchemaType<CreateActivityData> = {
type: 'object',
properties: {
id: { type: 'number', nullable: false },
type: { type: 'string', nullable: false, enum: ['text', 'video', 'image', 'h5p', 'sound'] },
type: { type: 'string', nullable: false, enum: ['text', 'video', 'image', 'h5p', 'sound', 'document'] },
value: { type: 'string', nullable: false },
},
required: ['type', 'value'],
Expand Down Expand Up @@ -275,7 +275,7 @@ const UPDATE_A_SCHEMA: JSONSchemaType<UpdateActivity> = {
type: 'object',
properties: {
id: { type: 'number', nullable: false },
type: { type: 'string', nullable: false, enum: ['text', 'video', 'image', 'h5p', 'sound'] },
type: { type: 'string', nullable: false, enum: ['text', 'video', 'image', 'h5p', 'sound', 'document'] },
value: { type: 'string', nullable: false },
},
required: ['type', 'value'],
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import path from 'path';
import type { UserType } from '../entities/user';
import { authenticate } from '../middlewares/authenticate';
import { handleErrors } from '../middlewares/handleErrors';
import { diskStorage } from './multer';
import { diskStorage } from '../middlewares/multer';

type RouteOptions = {
path: string;
Expand Down
13 changes: 11 additions & 2 deletions server/controllers/filesController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { Request, Response } from 'express';
import fs from 'fs';
import path from 'path';
import { v4 } from 'uuid';

import { uploadFile } from '../fileUpload';
import { AppError, ErrorCode } from '../middlewares/handleErrors';
Expand All @@ -14,14 +17,20 @@ export async function uploadFiles(req: Request, res: Response) {
throw new AppError('Files are missing', ErrorCode.UNKNOWN);
}
const promises: Promise<string | null>[] = [];

const folderPath = path.join(__dirname, `../fileUpload/images/${user.id}`);
fs.mkdirSync(folderPath, { recursive: true });
for (const file of files as Express.Multer.File[]) {
// making the filename being the path here is a trick to use
// upload function...
const filename = `images/${user.id}/${file.filename}`;
const promise = uploadFile(filename, file.mimetype);
const ext = file.originalname.split('.').pop();
const filename = `${v4()}.${ext}`;
fs.writeFileSync(`${folderPath}/${filename}`, file.buffer);
const promise = uploadFile(`images/${user.id}/${filename}`, file.mimetype);
promises.push(promise);
}
const results = await Promise.all(promises);
fs.rmSync(folderPath, { recursive: true, force: true });
res.status(200).json(results);
} catch (error) {
if (error instanceof AppError) {
Expand Down
Loading
Loading