fix(generator): uppercase UUIDs to match ProPresenter format

This commit is contained in:
Thorsten Bus 2026-03-30 08:00:17 +02:00
parent 0de35a9e95
commit 1f14724603
2 changed files with 41 additions and 2 deletions

View file

@ -46,6 +46,7 @@ use Rv\Data\Slide;
use Rv\Data\Slide\Element as SlideElement;
use Rv\Data\Slide\Element\TextScroller;
use Rv\Data\URL;
use Rv\Data\URL\LocalRelativePath;
use Rv\Data\URL\Platform as UrlPlatform;
use Rv\Data\UUID;
use Rv\Data\Version;
@ -243,6 +244,7 @@ final class ProFileGenerator
{
$url = new URL();
$url->setAbsoluteString($absoluteUrl);
$url->setLocal(self::buildLocalRelativePath($absoluteUrl));
$url->setPlatform(UrlPlatform::PLATFORM_MACOS);
$metadata = new Metadata();
@ -533,6 +535,40 @@ RTF);
return $message;
}
private static function buildLocalRelativePath(string $absoluteUrl): LocalRelativePath
{
$path = $absoluteUrl;
if (str_starts_with($path, 'file:///')) {
$path = substr($path, 7);
}
$rootMappings = [
'/Downloads/' => LocalRelativePath\Root::ROOT_USER_DOWNLOADS,
'/Documents/' => LocalRelativePath\Root::ROOT_USER_DOCUMENTS,
'/Music/' => LocalRelativePath\Root::ROOT_USER_MUSIC,
'/Pictures/' => LocalRelativePath\Root::ROOT_USER_PICTURES,
'/Movies/' => LocalRelativePath\Root::ROOT_USER_VIDEOS,
'/Desktop/' => LocalRelativePath\Root::ROOT_USER_DESKTOP,
];
$root = LocalRelativePath\Root::ROOT_BOOT_VOLUME;
$relativePath = ltrim($path, '/');
if (preg_match('#^/Users/[^/]+(/\w+/)(.+)$#', $path, $matches)) {
$dirSegment = $matches[1];
if (isset($rootMappings[$dirSegment])) {
$root = $rootMappings[$dirSegment];
$relativePath = $matches[2];
}
}
$local = new LocalRelativePath();
$local->setRoot($root);
$local->setPath($relativePath);
return $local;
}
private static function newUuidString(): string
{
$bytes = random_bytes(16);
@ -540,13 +576,13 @@ RTF);
$bytes[8] = chr((ord($bytes[8]) & 0x3f) | 0x80);
$hex = bin2hex($bytes);
return sprintf(
return strtoupper(sprintf(
'%s-%s-%s-%s-%s',
substr($hex, 0, 8),
substr($hex, 8, 4),
substr($hex, 12, 4),
substr($hex, 16, 4),
substr($hex, 20, 12),
);
));
}
}

View file

@ -66,6 +66,9 @@ class ProFileGeneratorTest extends TestCase
$groups = $song->getGroupsForArrangement($arrangement);
$this->assertCount(1, $groups);
$this->assertSame('Verse 1', $groups[0]->getName());
// Verify UUID is uppercase
$this->assertMatchesRegularExpression('/^[A-F0-9]{8}-[A-F0-9]{4}-4[A-F0-9]{3}-[89AB][A-F0-9]{3}-[A-F0-9]{12}$/', $song->getUuid());
}
#[Test]