diff --git a/newIDE/app/src/Export/BrowserExporters/BrowserOnlineWebExport.js b/newIDE/app/src/Export/BrowserExporters/BrowserOnlineWebExport.js index ca804a19c2..185dbeebe7 100644 --- a/newIDE/app/src/Export/BrowserExporters/BrowserOnlineWebExport.js +++ b/newIDE/app/src/Export/BrowserExporters/BrowserOnlineWebExport.js @@ -26,7 +26,10 @@ import { ExplanationHeader, OnlineGameLink, } from '../GenericExporters/OnlineWebExport'; -import { hasValidSubscriptionPlan } from '../../Utils/GDevelopServices/Usage'; +import { + hasValidSubscriptionPlan, + onlineWebExportSizeOptions, +} from '../../Utils/GDevelopServices/Usage'; const gd: libGDevelop = global.gd; type ExportState = null; @@ -49,9 +52,6 @@ type ResourcesDownloadOutput = {| type CompressionOutput = Blob; -const FREE_SIZE_LIMIT_IN_MB = 50; -const SUBSCRIBED_SIZE_LIMIT_IN_MB = 250; - export const browserOnlineWebExportPipeline: ExportPipeline< ExportState, PreparedExporter, @@ -162,19 +162,10 @@ export const browserOnlineWebExportPipeline: ExportPipeline< textFiles, basePath: '/export/', onProgress: context.updateStepProgress, - sizeOptions: { - // Higher limit for users with a subscription. - limit: - (hasValidSubscription - ? SUBSCRIBED_SIZE_LIMIT_IN_MB - : FREE_SIZE_LIMIT_IN_MB) * - 1000 * - 1000, - getMessage: fileSizeInMb => - hasValidSubscription - ? `Archive is of size ${fileSizeInMb} MB, which is above the limit allowed of ${SUBSCRIBED_SIZE_LIMIT_IN_MB} MB.` - : `Archive is of size ${fileSizeInMb} MB, which is above the limit allowed of ${FREE_SIZE_LIMIT_IN_MB} MB. You can subscribe to GDevelop to increase the limit to ${SUBSCRIBED_SIZE_LIMIT_IN_MB} MB.`, - }, + // Higher limit for users with a subscription. + sizeOptions: hasValidSubscription + ? onlineWebExportSizeOptions.subscribed + : onlineWebExportSizeOptions.guest, }); }, diff --git a/newIDE/app/src/Export/LocalExporters/LocalOnlineWebExport.js b/newIDE/app/src/Export/LocalExporters/LocalOnlineWebExport.js index 17918ff948..1bf9dc96dc 100644 --- a/newIDE/app/src/Export/LocalExporters/LocalOnlineWebExport.js +++ b/newIDE/app/src/Export/LocalExporters/LocalOnlineWebExport.js @@ -22,16 +22,16 @@ import { OnlineGameLink, } from '../GenericExporters/OnlineWebExport'; import { downloadUrlsToLocalFiles } from '../../Utils/LocalFileDownloader'; -import { hasValidSubscriptionPlan } from '../../Utils/GDevelopServices/Usage'; +import { + hasValidSubscriptionPlan, + onlineWebExportSizeOptions, +} from '../../Utils/GDevelopServices/Usage'; const path = optionalRequire('path'); const os = optionalRequire('os'); const gd: libGDevelop = global.gd; type ExportState = null; -const FREE_SIZE_LIMIT_IN_MB = 50; -const SUBSCRIBED_SIZE_LIMIT_IN_MB = 250; - type PreparedExporter = {| exporter: gdjsExporter, localFileSystem: LocalFileSystem, @@ -165,19 +165,10 @@ export const localOnlineWebExportPipeline: ExportPipeline< return archiveLocalFolder({ path: temporaryOutputDir, outputFilename: path.join(archiveOutputDir, 'game-archive.zip'), - sizeOptions: { - // Higher limit for users with a subscription. - limit: - (hasValidSubscription - ? SUBSCRIBED_SIZE_LIMIT_IN_MB - : FREE_SIZE_LIMIT_IN_MB) * - 1000 * - 1000, - getMessage: fileSizeInMb => - hasValidSubscription - ? `Archive is of size ${fileSizeInMb} MB, which is above the limit allowed of ${SUBSCRIBED_SIZE_LIMIT_IN_MB} MB.` - : `Archive is of size ${fileSizeInMb} MB, which is above the limit allowed of ${FREE_SIZE_LIMIT_IN_MB} MB. You can subscribe to GDevelop to increase the limit to ${SUBSCRIBED_SIZE_LIMIT_IN_MB} MB.`, - }, + // Higher limit for users with a subscription. + sizeOptions: hasValidSubscription + ? onlineWebExportSizeOptions.subscribed + : onlineWebExportSizeOptions.guest, }); }, diff --git a/newIDE/app/src/Utils/BrowserArchiver.js b/newIDE/app/src/Utils/BrowserArchiver.js index 4769abfcc0..abaa6c8a3f 100644 --- a/newIDE/app/src/Utils/BrowserArchiver.js +++ b/newIDE/app/src/Utils/BrowserArchiver.js @@ -3,6 +3,7 @@ import { initializeZipJs } from './Zip.js'; import { downloadUrlsToBlobs, type ItemResult } from './BlobDownloader'; import path from 'path'; import { shortenString } from './StringHelpers.js'; +import { type ExportSizeOptions } from './GDevelopServices/Usage'; export type BlobFileDescriptor = {| filePath: string, @@ -101,10 +102,7 @@ export const archiveFiles = async ({ blobFiles: Array, basePath: string, onProgress: (count: number, total: number) => void, - sizeOptions?: {| - limit: number, - getMessage: (fileSizeInMb: number) => string, - |}, + sizeOptions?: ExportSizeOptions, |}): Promise => { const zipJs: ZipJs = await initializeZipJs(); @@ -162,7 +160,7 @@ export const archiveFiles = async ({ fileSize / (1000 * 1000) ); reject( - new Error(sizeOptions.getMessage(roundFileSizeInMb)) + new Error(sizeOptions.getErrorMessage(roundFileSizeInMb)) ); } resolve(blob); diff --git a/newIDE/app/src/Utils/GDevelopServices/Usage.js b/newIDE/app/src/Utils/GDevelopServices/Usage.js index 43dcd865ff..f4aa049baf 100644 --- a/newIDE/app/src/Utils/GDevelopServices/Usage.js +++ b/newIDE/app/src/Utils/GDevelopServices/Usage.js @@ -190,6 +190,29 @@ export const businessPlan: PlanDetails = { descriptionBullets: [], }; +const SUBSCRIBED_SIZE_LIMIT_IN_MB = 250; +const GUEST_SIZE_LIMIT_IN_MB = 50; + +export type ExportSizeOptions = {| + limit: number, + getErrorMessage: (fileSizeInMb: number) => string, +|}; + +export const onlineWebExportSizeOptions: { + [key: 'guest' | 'subscribed']: ExportSizeOptions, +} = { + guest: { + limit: SUBSCRIBED_SIZE_LIMIT_IN_MB * 1000 * 1000, + getErrorMessage: (fileSizeInMb: number) => + `Archive is of size ${fileSizeInMb} MB, which is above the limit allowed of ${SUBSCRIBED_SIZE_LIMIT_IN_MB} MB`, + }, + subscribed: { + limit: GUEST_SIZE_LIMIT_IN_MB * 1000 * 1000, + getErrorMessage: (fileSizeInMb: number) => + `Archive is of size ${fileSizeInMb} MB, which is above the limit allowed of ${GUEST_SIZE_LIMIT_IN_MB} MB. You can subscribe to GDevelop to increase the limit to ${SUBSCRIBED_SIZE_LIMIT_IN_MB} MB.`, + }, +}; + export const getUserUsages = ( getAuthorizationHeader: () => Promise, userId: string diff --git a/newIDE/app/src/Utils/LocalArchiver.js b/newIDE/app/src/Utils/LocalArchiver.js index fbce89215f..72d8e092c2 100644 --- a/newIDE/app/src/Utils/LocalArchiver.js +++ b/newIDE/app/src/Utils/LocalArchiver.js @@ -2,6 +2,7 @@ import optionalRequire from './OptionalRequire'; import optionalLazyRequire from '../Utils/OptionalLazyRequire'; +import { type ExportSizeOptions } from './GDevelopServices/Usage'; const fs = optionalRequire('fs'); const lazyRequireArchiver = optionalLazyRequire('archiver'); @@ -16,10 +17,7 @@ export const archiveLocalFolder = ({ }: {| path: string, outputFilename: string, - sizeOptions?: {| - limit: number, - getMessage: (fileSizeInMb: number) => string, - |}, + sizeOptions?: ExportSizeOptions, |}): Promise => { const archiver = lazyRequireArchiver(); return new Promise((resolve, reject) => { @@ -37,7 +35,7 @@ export const archiveLocalFolder = ({ ); if (sizeOptions && fileSize > sizeOptions.limit) { const roundFileSizeInMb = Math.round(fileSize / (1000 * 1000)); - reject(new Error(sizeOptions.getMessage(roundFileSizeInMb))); + reject(new Error(sizeOptions.getErrorMessage(roundFileSizeInMb))); } resolve(outputFilename); });