Skip to content
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
3 changes: 3 additions & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ SELF_SERVICE_FLOWS_REGISTRATION_AFTER_DEFAULT_BROWSER_RETURN_URL=http://127.0.0.
# SELFSERVICE_ALLOWED_RETURN_URLS_0=http://127.0.0.1:3000
# SELFSERVICE_ALLOWED_RETURN_URLS_1=http://127.0.0.1:4433
LOG_LEVEL=trace

MAX_QUIZ_FILE_SIZE=1048576
BODY_LIMIT_MB=15 #MB
4 changes: 3 additions & 1 deletion api/cli/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ func GetAPICommandDef(cfg config.AppConfig, logger *zap.Logger) cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {

// Create fiber app
app := fiber.New(fiber.Config{})
app := fiber.New(fiber.Config{
BodyLimit: cfg.BodyLimitMB * 1024 * 1024,
})

app.Use(cors.New(cors.Config{
AllowHeaders: "Origin,Content-Type,Accept,Content-Length,Accept-Language,Accept-Encoding,Connection,Access-Control-Allow-Origin,Authorization,Options",
Expand Down
1 change: 1 addition & 0 deletions api/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type AppConfig struct {
Secret string `envconfig:"JWT_SECRET"`
WebUrl string `envconfig:"WEB_URL"`
JWTIssuer string `envconfig:"ISSUER"`
BodyLimitMB int `envconfig:"BODY_LIMIT_MB"`
RedisClient RedisClientConfig
DB DBConfig
Kratos KratosConfig
Expand Down
1 change: 1 addition & 0 deletions api/config/quiz.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package config
type QuizConfig struct {
QuestionTimeLimit string `envconfig:"QUESTION_TIME_LIMIT"`
ScoreboardMaxDuration string `envconfig:"SCOREBOARD_MAX_DURATION"`
FileSize int64 `envconfig:"QUIZ_FILE_SIZE" default:"1048576"`
}
2 changes: 1 addition & 1 deletion api/constants/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const (
QuizTitle = "quiz_title"
QuizTitleRequired = "quiz-title is required"
ErrGettingAttachment = "error in getting file"
ErrFileSizeExceed = "file size exceeded"
ErrFileSizeExceed = "The file is too large to upload. Please select a smaller file."
ErrFileIsNotInSupportedType = "file has no supported type"
ErrProblemInUploadFile = "there was some error in file upload"
ErrValidatingColumns = "file columns not in proper format"
Expand Down
4 changes: 2 additions & 2 deletions api/middlewares/csv_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func (m *Middleware) ValidateCsv(c *fiber.Ctx) error {
return utils.JSONFail(c, http.StatusBadRequest, constants.ErrGettingAttachment)
}

if file.Size > constants.FileSize {
if file.Size > m.Config.Quiz.FileSize {
m.Logger.Error("error in getting csv file", zap.Error(err))
return utils.JSONFail(c, http.StatusBadRequest, constants.ErrGettingAttachment)
return utils.JSONFail(c, http.StatusBadRequest, constants.ErrFileSizeExceed)
}

isMatched := false
Expand Down
3 changes: 2 additions & 1 deletion app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ HOST=127.0.0.1
NUXT_PUBLIC_BASE_URL=http://127.0.0.1:5000
NUXT_PUBLIC_API_URL="http://127.0.0.1:3000/api/v1"
NUXT_PUBLIC_API_SOCKET_URL="ws://127.0.0.1:3000/api/v1/socket"
NUXT_PUBLIC_KRATOS_URL="http://127.0.0.1:4433"
NUXT_PUBLIC_KRATOS_URL="http://127.0.0.1:4433"
MAX_IMAGE_FILE_SIZE=1048576 #KB
1 change: 1 addition & 0 deletions app/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineNuxtConfig({
public: {
baseUrl: process.env.NUXT_PUBLIC_BASE_URL || "http://127.0.0.1:3001",
apiUrl: process.env.NUXT_PUBLIC_API_URL || "http://127.0.0.1:3000/api/v1",
maxImageFileSize: parseInt(process.env.MAX_IMAGE_FILE_SIZE || "1048576") , //1MB default
apiSocketUrl:
process.env.NUXT_PUBLIC_API_SOCKET_URL ||
"ws://127.0.0.1:3000/api/v1/socket",
Expand Down
15 changes: 8 additions & 7 deletions app/pages/admin/quiz/create-quiz.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ useSystemEnv();
// define props and emits
let file = ref(0);
let title = ref("");
const url = useRuntimeConfig().public;
const publicRuntimeConfig = useRuntimeConfig().public;
const maxFileSize = publicRuntimeConfig.maxImageFileSize;
let quizId = ref();
const requestPending = ref(false);
const imageRequestPending = ref(false);
Expand All @@ -27,7 +28,7 @@ const uploadQuizAndQuestions = async (e) => {
formData.append(description.name, description.value);
formData.append(attachment.name, attachment.files[0]);
try {
await $fetch(encodeURI(`${url.apiUrl}/quizzes/${title.value}/upload`), {
await $fetch(encodeURI(`${publicRuntimeConfig.apiUrl}/quizzes/${title.value}/upload`), {
method: "POST",
headers: {
Accept: "application/json",
Expand All @@ -51,7 +52,7 @@ const uploadQuizAndQuestions = async (e) => {

try {
await $fetch(
encodeURI(`${url.apiUrl}/quizzes/${quizId.value}/questions?media=image`),
encodeURI(`${publicRuntimeConfig.apiUrl}/quizzes/${quizId.value}/questions?media=image`),
{
method: "GET",
headers: {
Expand Down Expand Up @@ -106,9 +107,9 @@ const imageFileUpload = async (e) => {
return;
}

// 2 MB max
if (file.size > 2000000) {
toast.error("Please upload an image less than 2 MB.");
// 1 MB max
if (file.size > maxFileSize) {
toast.error(`Please upload an image less than ${maxFileSize / 1024 / 1024} MB.`);
return;
}

Expand All @@ -117,7 +118,7 @@ const imageFileUpload = async (e) => {

imageRequestPending.value = true;
try {
await $fetch(encodeURI(`${url.apiUrl}/images?quiz_id=${quizId.value}`), {
await $fetch(encodeURI(`${publicRuntimeConfig.apiUrl}/images?quiz_id=${quizId.value}`), {
method: "POST",
headers: {
Accept: "application/json",
Expand Down
Loading