feat: introducing ability to set custom collection import size limit (#4440)

This commit is contained in:
Joel Jacob Stephen 2024-10-23 08:04:40 -05:00 committed by GitHub
parent f10fac9f44
commit 0e00eeb950
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 36 additions and 18 deletions

View File

@ -513,8 +513,8 @@
"postman_environment": "Postman Environment", "postman_environment": "Postman Environment",
"postman_environment_description": "Import Postman Environment from a JSON file", "postman_environment_description": "Import Postman Environment from a JSON file",
"title": "Import", "title": "Import",
"file_size_limit_exceeded_warning_multiple_files": "Chosen files exceed the recommended limit of 10MB. Only the first {files} selected will be imported", "file_size_limit_exceeded_warning_multiple_files": "Chosen files exceed the recommended limit of {sizeLimit}MB. Only the first {files} selected will be imported",
"file_size_limit_exceeded_warning_single_file": "The currently chosen file exceeds the recommended limit of 10MB. Please select another file.", "file_size_limit_exceeded_warning_single_file": "The currently chosen file exceeds the recommended limit of {sizeLimit}MB. Please select another file.",
"success": "Successfully imported" "success": "Successfully imported"
}, },
"inspections": { "inspections": {

View File

@ -33,6 +33,7 @@
<template v-if="importFilesCount"> <template v-if="importFilesCount">
{{ {{
t("import.file_size_limit_exceeded_warning_multiple_files", { t("import.file_size_limit_exceeded_warning_multiple_files", {
sizeLimit: ALLOWED_FILE_SIZE_LIMIT,
files: files:
importFilesCount === 1 ? "file" : `${importFilesCount} files`, importFilesCount === 1 ? "file" : `${importFilesCount} files`,
}) })
@ -40,7 +41,11 @@
</template> </template>
<template v-else> <template v-else>
{{ t("import.file_size_limit_exceeded_warning_single_file") }} {{
t("import.file_size_limit_exceeded_warning_single_file", {
sizeLimit: ALLOWED_FILE_SIZE_LIMIT,
})
}}
</template> </template>
</p> </p>
<div> <div>
@ -59,6 +64,7 @@
import { useI18n } from "@composables/i18n" import { useI18n } from "@composables/i18n"
import { useToast } from "@composables/toast" import { useToast } from "@composables/toast"
import { computed, ref } from "vue" import { computed, ref } from "vue"
import { platform } from "~/platform"
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
@ -74,7 +80,7 @@ const props = withDefaults(
const t = useI18n() const t = useI18n()
const toast = useToast() const toast = useToast()
const ALLOWED_FILE_SIZE_LIMIT = 10 // 10 MB const ALLOWED_FILE_SIZE_LIMIT = platform.limits?.collectionImportSizeLimit ?? 10 // Default to 10 MB
const importFilesCount = ref(0) const importFilesCount = ref(0)

View File

@ -1,19 +1,20 @@
import { AuthPlatformDef } from "./auth"
import { UIPlatformDef } from "./ui"
import { EnvironmentsPlatformDef } from "./environments"
import { CollectionsPlatformDef } from "./collections"
import { SettingsPlatformDef } from "./settings"
import { HistoryPlatformDef } from "./history"
import { AnalyticsPlatformDef } from "./analytics"
import { InterceptorsPlatformDef } from "./interceptors"
import { HoppModule } from "~/modules"
import { InspectorsPlatformDef } from "./inspectors"
import { ServiceClassInstance } from "dioc" import { ServiceClassInstance } from "dioc"
import { IOPlatformDef } from "./io"
import { SpotlightPlatformDef } from "./spotlight"
import { InfraPlatformDef } from "./infra"
import { ExperimentsPlatformDef } from "./experiments"
import { Ref } from "vue" import { Ref } from "vue"
import { HoppModule } from "~/modules"
import { AnalyticsPlatformDef } from "./analytics"
import { AuthPlatformDef } from "./auth"
import { CollectionsPlatformDef } from "./collections"
import { EnvironmentsPlatformDef } from "./environments"
import { ExperimentsPlatformDef } from "./experiments"
import { HistoryPlatformDef } from "./history"
import { InfraPlatformDef } from "./infra"
import { InspectorsPlatformDef } from "./inspectors"
import { InterceptorsPlatformDef } from "./interceptors"
import { IOPlatformDef } from "./io"
import { LimitsPlatformDef } from "./limits"
import { SettingsPlatformDef } from "./settings"
import { SpotlightPlatformDef } from "./spotlight"
import { UIPlatformDef } from "./ui"
export type PlatformDef = { export type PlatformDef = {
ui?: UIPlatformDef ui?: UIPlatformDef
@ -54,6 +55,7 @@ export type PlatformDef = {
*/ */
workspaceSwitcherLogin?: Ref<boolean> workspaceSwitcherLogin?: Ref<boolean>
} }
limits?: LimitsPlatformDef
infra?: InfraPlatformDef infra?: InfraPlatformDef
experiments?: ExperimentsPlatformDef experiments?: ExperimentsPlatformDef
} }

View File

@ -0,0 +1,7 @@
// Define various limits for the platform
export type LimitsPlatformDef = {
/**
* Assign an import size limit when importing collections
*/
collectionImportSizeLimit?: number
}

View File

@ -43,5 +43,8 @@ createHoppApp("#app", {
exportAsGIST: false, exportAsGIST: false,
hasTelemetry: false, hasTelemetry: false,
}, },
limits: {
collectionImportSizeLimit: 50,
},
infra: InfraPlatform, infra: InfraPlatform,
}) })