mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Refactor into usage
This commit is contained in:
@@ -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,
|
||||
});
|
||||
},
|
||||
|
||||
|
@@ -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,
|
||||
});
|
||||
},
|
||||
|
||||
|
@@ -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<BlobFileDescriptor>,
|
||||
basePath: string,
|
||||
onProgress: (count: number, total: number) => void,
|
||||
sizeOptions?: {|
|
||||
limit: number,
|
||||
getMessage: (fileSizeInMb: number) => string,
|
||||
|},
|
||||
sizeOptions?: ExportSizeOptions,
|
||||
|}): Promise<Blob> => {
|
||||
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);
|
||||
|
@@ -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<string>,
|
||||
userId: string
|
||||
|
@@ -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<string> => {
|
||||
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);
|
||||
});
|
||||
|
Reference in New Issue
Block a user