Enable metadata versioning
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
@@ -2,10 +2,11 @@
|
||||
namespace MediaWiki\Extension\GlModelViewer;
|
||||
|
||||
use ImageHandler;
|
||||
use BitmapMetadataHandler;
|
||||
use Html;
|
||||
|
||||
class GlModelHandler extends ImageHandler {
|
||||
private const glmvVersion = '0.1';
|
||||
private const GLMV_VERSION = '0.2';
|
||||
|
||||
/**
|
||||
* Model cannot be displayed directly in a browser but can be rendered.
|
||||
@@ -169,7 +170,6 @@ class GlModelHandler extends ImageHandler {
|
||||
* bits, and metadata keys. All keys are optional.
|
||||
*/
|
||||
public function getSizeAndMetadata ($state, $path) {
|
||||
|
||||
$gltf = fopen($path, 'r');
|
||||
fseek($gltf,12);
|
||||
$glMetaLength = unpack("Iint", fread($gltf, 4));
|
||||
@@ -177,7 +177,8 @@ class GlModelHandler extends ImageHandler {
|
||||
$glMeta = json_decode(fread($gltf,$glMetaLength['int']),true);
|
||||
fclose($gltf);
|
||||
$newMeta = array(
|
||||
'Type' => $glType
|
||||
'glmv-meshes' => count($glMeta['meshes']),
|
||||
'glmv-textures' => count($glMeta['textures'])
|
||||
);
|
||||
foreach($glMeta['asset'] as $key => $value) {
|
||||
switch ($key) {
|
||||
@@ -195,9 +196,9 @@ class GlModelHandler extends ImageHandler {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$newMeta['glmv-meshes'] = count($glMeta['meshes']);
|
||||
$newMeta['glmv-textures'] = count($glMeta['textures']);
|
||||
$newMeta['glmv-metadata'] = self::glmvVersion;
|
||||
$newMeta['glmv-metadata'] = self::GLMV_VERSION;
|
||||
$metaHandler = new BitmapMetadataHandler;
|
||||
$metaHandler->addMetadata($newMeta,'exif');
|
||||
return array(
|
||||
'width' => 600,
|
||||
'height' => 800,
|
||||
@@ -212,13 +213,13 @@ class GlModelHandler extends ImageHandler {
|
||||
* MediaHandler::METADATA_GOOD for if the metadata is a-ok,
|
||||
* MediaHandler::METADATA_COMPATIBLE if metadata is old but backwards compatible (which may or may not trigger a metadata reload).
|
||||
*
|
||||
* TODO: This version is for testing/dev only. Better checking will be requried in the future
|
||||
* TODO: This version is for testing/dev only. Better checking will be required in the future
|
||||
* @param File $image
|
||||
* @return bool|int
|
||||
*/
|
||||
public function isFileMetadataValid ($image) {
|
||||
$meta = $image->getMetadataItems('glmv-metadata');
|
||||
if (!isset($meta['glmv-metadata']) || $meta['glmv-metadata'] != self::glmvVersion) {
|
||||
$meta = $image->getMetadataItems(['glmv-metadata']);
|
||||
if (!isset($meta['glmv-metadata']) || $meta['glmv-metadata'] != self::GLMV_VERSION) {
|
||||
return self::METADATA_BAD;
|
||||
}
|
||||
return self::METADATA_GOOD;
|
||||
|
||||
Reference in New Issue
Block a user