generated from well-known-components/base-ts-project
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: validate scene thumbnail (#201)
- Loading branch information
1 parent
e6d3e4c
commit ba30d03
Showing
8 changed files
with
121 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,43 @@ | ||
import { EntityType } from '@dcl/schemas' | ||
import { DeploymentToValidate, OK, ValidateFn, validationFailed, ValidationResponse } from '../types' | ||
import { validateAfterADR173, validateIfTypeMatches } from './validations' | ||
|
||
function validateIfScene(validateFn: ValidateFn): ValidateFn { | ||
return validateIfTypeMatches(EntityType.SCENE, validateFn) | ||
} | ||
import { ContentMapping, EntityType } from '@dcl/schemas' | ||
import { DeploymentToValidate, OK, validationFailed, ValidationResponse } from '../types' | ||
import { validateAfterADR173, validateAfterADR236, validateAll, validateIfTypeMatches } from './validations' | ||
|
||
/** | ||
* Validate that given scene deployment does not contain worldConfiguration section | ||
* @public | ||
*/ | ||
export const noWorldsConfigurationValidateFn = validateIfScene( | ||
validateAfterADR173(async function validateFn(deployment: DeploymentToValidate): Promise<ValidationResponse> { | ||
const sceneHasWorldConfiguration = deployment.entity.metadata?.worldConfiguration !== undefined | ||
if (sceneHasWorldConfiguration) { | ||
return validationFailed('Scenes cannot have worldConfiguration section after ADR 173.') | ||
export const noWorldsConfigurationValidateFn = validateAfterADR173(async function validateFn( | ||
deployment: DeploymentToValidate | ||
): Promise<ValidationResponse> { | ||
const sceneHasWorldConfiguration = deployment.entity.metadata?.worldConfiguration !== undefined | ||
if (sceneHasWorldConfiguration) { | ||
return validationFailed('Scenes cannot have worldConfiguration section after ADR 173.') | ||
} | ||
return OK | ||
}) | ||
|
||
/** | ||
* Validate that given scene deployment thumbnail is a file embedded in the deployment | ||
* @public | ||
*/ | ||
export const embeddedThumbnail = validateAfterADR236(async function validateFn( | ||
deployment: DeploymentToValidate | ||
): Promise<ValidationResponse> { | ||
const sceneThumbnail = deployment.entity.metadata?.display.navmapThumbnail | ||
if (sceneThumbnail) { | ||
const isFilePresent = deployment.entity.content.some((content: ContentMapping) => content.file === sceneThumbnail) | ||
if (!isFilePresent) { | ||
return validationFailed(`Scene thumbnail '${sceneThumbnail}' must be a file included in the deployment.`) | ||
} | ||
return OK | ||
}) | ||
) | ||
} | ||
return OK | ||
}) | ||
|
||
/** | ||
* Validate that given scene deployment is valid | ||
* @public | ||
*/ | ||
export const sceneValidateFn = noWorldsConfigurationValidateFn | ||
export const sceneValidateFn = validateIfTypeMatches( | ||
EntityType.SCENE, | ||
validateAll(noWorldsConfigurationValidateFn, embeddedThumbnail) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters