{"version":3,"file":"settings.mjs","names":[],"sources":["../../../src/libs/formatters/settings.ts"],"sourcesContent":["import type { Config } from \"../../types/config.js\";\nimport type { LucidAuth } from \"../../types/hono.js\";\nimport type { Settings, SettingsInclude } from \"../../types/response.js\";\nimport { createLicenseKeyDisplay } from \"../../utils/helpers/license-key-display.js\";\nimport { Permissions } from \"../permission/definitions.js\";\nimport hasAccess from \"../permission/has-access.js\";\n\ninterface SettingsPropsT {\n\tmediaStorageUsed: number;\n\tprocessedImageCount: number;\n\tlicenseKey: string | null;\n\tmediaAdapterEnabled: boolean;\n\tmediaAdapterKey: string | null;\n\temailAdapterKey: string;\n\temailSimulated: boolean;\n\temailTemplates: string[];\n\timageProcessorKey: string | null;\n\tsystemAlertEmail: string | null;\n\truntimeKey: string;\n\tqueueKey: string;\n\tkvKey: string;\n\tdatabaseKey: string;\n}\n\nconst formatSingle = (props: {\n\tsettings: SettingsPropsT;\n\tconfig: Config;\n\tincludes: SettingsInclude[] | undefined;\n\tauthUser?: LucidAuth;\n}): Settings => {\n\tconst includes = props.includes ?? [];\n\tif (includes.length === 0) return {};\n\n\tconst includeSet = new Set(includes);\n\tconst response: Settings = {};\n\n\tif (includeSet.has(\"ai\")) {\n\t\tresponse.ai = {\n\t\t\tenabled: props.config.ai.enabled,\n\t\t\tfeatures: {\n\t\t\t\timageGeneration: props.config.ai.features.imageGeneration,\n\t\t\t\taltGeneration: props.config.ai.features.altGeneration,\n\t\t\t\tcustomFieldGeneration: props.config.ai.features.customFieldGeneration,\n\t\t\t},\n\t\t};\n\t}\n\n\tif (includeSet.has(\"email\")) {\n\t\tresponse.email = {\n\t\t\tsimulated: props.settings.emailSimulated,\n\t\t\ttemplates: props.settings.emailTemplates,\n\t\t\tfrom: props.config.email?.from ?? null,\n\t\t};\n\t}\n\n\tif (includeSet.has(\"media\")) {\n\t\tconst storageTotal = props.config.media.limits.storageBytes;\n\t\tconst storageRemaining =\n\t\t\tstorageTotal === false\n\t\t\t\t? null\n\t\t\t\t: storageTotal - props.settings.mediaStorageUsed;\n\n\t\tresponse.media = {\n\t\t\tenabled: props.settings.mediaAdapterEnabled,\n\t\t\tstorage: {\n\t\t\t\ttotal: storageTotal === false ? null : storageTotal,\n\t\t\t\tremaining: storageRemaining,\n\t\t\t\tused: props.settings.mediaStorageUsed,\n\t\t\t},\n\t\t\tprocessed: {\n\t\t\t\tstored: props.config.media.images.storeProcessed,\n\t\t\t\timageLimit: props.config.media.limits.processedImagesPerFile,\n\t\t\t\ttotal: props.settings.processedImageCount,\n\t\t\t},\n\t\t};\n\t}\n\n\tif (includeSet.has(\"license\")) {\n\t\tresponse.license = {\n\t\t\tkey: createLicenseKeyDisplay(props.settings.licenseKey),\n\t\t};\n\t}\n\n\tconst canReadSystem = hasAccess({\n\t\tuser: props.authUser,\n\t\trequiredPermissions: [Permissions.SettingsRead],\n\t});\n\n\tif (includeSet.has(\"system\") && canReadSystem) {\n\t\tresponse.system = {\n\t\t\truntime: props.settings.runtimeKey,\n\t\t\tdatabase: props.settings.databaseKey,\n\t\t\tkv: props.settings.kvKey,\n\t\t\tqueue: props.settings.queueKey,\n\t\t\tmedia: props.settings.mediaAdapterKey,\n\t\t\temail: props.settings.emailAdapterKey,\n\t\t\timageProcessor: props.settings.imageProcessorKey,\n\t\t\talertEmail: props.settings.systemAlertEmail,\n\t\t};\n\t}\n\n\treturn response;\n};\n\nexport default {\n\tformatSingle,\n};\n"],"mappings":"8LAwGA,IAAA,EAAe,CACd,aAjFqB,GAKN,CACf,IAAM,EAAW,EAAM,UAAY,CAAC,EACpC,GAAI,EAAS,SAAW,EAAG,MAAO,CAAC,EAEnC,IAAM,EAAa,IAAI,IAAI,CAAQ,EAC7B,EAAqB,CAAC,EAqB5B,GAnBI,EAAW,IAAI,IAAI,IACtB,EAAS,GAAK,CACb,QAAS,EAAM,OAAO,GAAG,QACzB,SAAU,CACT,gBAAiB,EAAM,OAAO,GAAG,SAAS,gBAC1C,cAAe,EAAM,OAAO,GAAG,SAAS,cACx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